diff --git a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php index c25fd48..6bfb4c3 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php @@ -465,7 +465,9 @@ protected function invokeFieldMethod($method, ContentEntityInterface $entity) { $translation = $entity->original->getTranslation($removed_langcode); $fields = $translation->getTranslatableFields(); foreach ($fields as $name => $items) { - $items->delete(); + // Call the delete method with the parameter $parent_delete set to + // FALSE to indicate that only an entity translation is being removed. + $items->delete(FALSE); } } } diff --git a/core/lib/Drupal/Core/Field/FieldItemBase.php b/core/lib/Drupal/Core/Field/FieldItemBase.php index d489c8e..61fffa7 100644 --- a/core/lib/Drupal/Core/Field/FieldItemBase.php +++ b/core/lib/Drupal/Core/Field/FieldItemBase.php @@ -201,7 +201,7 @@ public function postSave($update) { } /** * {@inheritdoc} */ - public function delete() { } + public function delete($parent_delete = TRUE) { } /** * {@inheritdoc} diff --git a/core/lib/Drupal/Core/Field/FieldItemList.php b/core/lib/Drupal/Core/Field/FieldItemList.php index 97dd493..8ade48b 100644 --- a/core/lib/Drupal/Core/Field/FieldItemList.php +++ b/core/lib/Drupal/Core/Field/FieldItemList.php @@ -213,8 +213,8 @@ public function postSave($update) { /** * {@inheritdoc} */ - public function delete() { - $this->delegateMethod('delete'); + public function delete($parent_delete = TRUE) { + $this->delegateMethod('delete', $parent_delete); } /** diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php index 1b8822f..2a7ccc4 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php @@ -103,7 +103,7 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function delete() { + public function delete($parent_delete = TRUE) { // Reports that delete() method is executed for testing purposes. field_test_memorize('field_test_field_delete', array($this->getEntity())); } diff --git a/core/modules/file/src/Plugin/Field/FieldType/FileFieldItemList.php b/core/modules/file/src/Plugin/Field/FieldType/FileFieldItemList.php index 20f4797..b0e8922 100644 --- a/core/modules/file/src/Plugin/Field/FieldType/FileFieldItemList.php +++ b/core/modules/file/src/Plugin/Field/FieldType/FileFieldItemList.php @@ -77,8 +77,8 @@ public function postSave($update) { /** * {@inheritdoc} */ - public function delete() { - parent::delete(); + public function delete($parent_delete = TRUE) { + parent::delete($parent_delete); $entity = $this->getEntity(); // If a translation is deleted only decrement the file usage by one. If the diff --git a/core/modules/path/src/Plugin/Field/FieldType/PathFieldItemList.php b/core/modules/path/src/Plugin/Field/FieldType/PathFieldItemList.php index ee03361..6acbaa3 100644 --- a/core/modules/path/src/Plugin/Field/FieldType/PathFieldItemList.php +++ b/core/modules/path/src/Plugin/Field/FieldType/PathFieldItemList.php @@ -24,7 +24,7 @@ public function defaultAccess($operation = 'view', AccountInterface $account = N /** * {@inheritdoc} */ - public function delete() { + public function delete($parent_delete = TRUE) { // Delete all aliases associated with this entity in the current language. $entity = $this->getEntity(); $conditions = [ diff --git a/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/FieldTestItem.php b/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/FieldTestItem.php index 2310ffd..8b09809 100644 --- a/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/FieldTestItem.php +++ b/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/FieldTestItem.php @@ -113,10 +113,10 @@ protected function mustResave() { /** * {@inheritdoc} */ - public function delete() { - parent::delete(); + public function delete($parent_delete = TRUE) { + parent::delete($parent_delete); $deleted_languages = \Drupal::state()->get('entity_test.delete.' . $this->getFieldDefinition()->getName()) ?: []; - $deleted_languages[] = $this->getLangcode(); + $deleted_languages[$this->getLangcode()] = $parent_delete; \Drupal::state()->set('entity_test.delete.' . $this->getFieldDefinition()->getName(), $deleted_languages); } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php index ed6140d..42cbb56 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php @@ -904,11 +904,17 @@ public function testDeleteEntityTranslation() { // Ensure that for the translatable test field the second and third // langcodes are in the deleted languages list. - $actual = \Drupal::state()->get('entity_test.delete.translatable_test_field'); - $expected_translatable = ['l1', 'l2']; + $deleted_information = \Drupal::state()->get('entity_test.delete.translatable_test_field'); + $actual = array_keys($deleted_information); + $expected_translatable = $removed_languages = ['l1', 'l2']; sort($actual); sort($expected_translatable); $this->assertEqual($actual, $expected_translatable); + // Ensure that the delete method was provided with the correct information + // that only an entity translation is being removed. + foreach ($removed_languages as $langcode) { + $this->assertFalse($deleted_information[$langcode]); + } // Ensure that the untranslatable test field is untouched. $this->assertNull(\Drupal::state()->get('entity_test.delete.untranslatable_test_field')); @@ -916,20 +922,32 @@ public function testDeleteEntityTranslation() { $entity->delete(); // All languages have been deleted now. - $actual = \Drupal::state()->get('entity_test.delete.translatable_test_field'); - $expected_translatable[] = 'en'; - $expected_translatable[] = 'l0'; + $deleted_information = \Drupal::state()->get('entity_test.delete.translatable_test_field'); + $actual = array_keys($deleted_information); + $entity_left_translations_before_deletion = ['en', 'l0']; + $expected_translatable = array_merge($expected_translatable, $entity_left_translations_before_deletion); sort($actual); sort($expected_translatable); $this->assertEqual($actual, $expected_translatable); + // Ensure that the delete method was provided with the correct information + // that the entity is being deleted. + foreach ($entity_left_translations_before_deletion as $langcode) { + $this->assertTrue($deleted_information[$langcode]); + } // The untranslatable field is shared and only deleted once, for the // default langcode. - $actual = \Drupal::state()->get('entity_test.delete.untranslatable_test_field'); + $deleted_information = \Drupal::state()->get('entity_test.delete.untranslatable_test_field'); + $actual = array_keys($deleted_information); $expected_untranslatable = ['en']; sort($actual); sort($expected_untranslatable); $this->assertEqual($actual, $expected_untranslatable); + // Ensure that the delete method was provided with the correct information + // that the entity is being deleted. + foreach ($expected_untranslatable as $langcode) { + $this->assertTrue($deleted_information[$langcode]); + } } /**