diff --git a/core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php b/core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php index 9d985b2142..0a53d9894a 100644 --- a/core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php +++ b/core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php @@ -128,21 +128,4 @@ public function defaultValuesFormSubmit(array $element, array &$form, FormStateI return $default_value; } - /** - * Removes the items with a specific target ID. - * - * @param int|string $target_id - * The target id of the item to be removed. - * - * @return $this - * - * @todo Add this to EntityReferenceFieldItemListInterface in Drupal 9.0.x. - * https://www.drupal.org/node/2785673 - */ - public function removeItemsByTargetId($target_id) { - return $this->filter(function ($item) use ($target_id) { - return $item->target_id != $target_id; - }); - } - } diff --git a/core/modules/taxonomy/src/Entity/Term.php b/core/modules/taxonomy/src/Entity/Term.php index acde65a295..26fb973482 100644 --- a/core/modules/taxonomy/src/Entity/Term.php +++ b/core/modules/taxonomy/src/Entity/Term.php @@ -71,7 +71,9 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti foreach ($children as $child) { $parent = $child->get('parent'); // Update child parents item list. - $parent->removeItemsByTargetId($tid); + $parent->filter(function ($item) use ($tid) { + return $item->target_id != $tid; + }); // If the term has multiple parents, we don't delete it. if ($parent->count()) { diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install index 702ca7ce83..767743543d 100644 --- a/core/modules/taxonomy/taxonomy.install +++ b/core/modules/taxonomy/taxonomy.install @@ -14,8 +14,6 @@ function taxonomy_update_8501() { $definition = $manager->getFieldStorageDefinition('parent', 'taxonomy_term'); $definition->setCustomStorage(FALSE); $manager->updateFieldStorageDefinition($definition); - // Update the entity type because a new interface was added to Term entity. - $manager->updateEntityType($manager->getEntityType('taxonomy_term')); } /** diff --git a/core/modules/taxonomy/tests/src/Functional/Update/TaxonomyParentUpdateTest.php b/core/modules/taxonomy/tests/src/Functional/Update/TaxonomyParentUpdateTest.php index 6733e7e447..c8c9e0cffc 100644 --- a/core/modules/taxonomy/tests/src/Functional/Update/TaxonomyParentUpdateTest.php +++ b/core/modules/taxonomy/tests/src/Functional/Update/TaxonomyParentUpdateTest.php @@ -11,6 +11,7 @@ * Ensure that the taxonomy updates are running as expected. * * @group taxonomy + * @group Update */ class TaxonomyParentUpdateTest extends UpdatePathTestBase { @@ -45,7 +46,6 @@ public function setDatabaseDumpFiles() { * @see taxonomy_update_8501() * @see taxonomy_update_8502() * @see taxonomy_update_8503() - * @see taxonomy_update_8504() */ public function testTaxonomyUpdateParents() { // Run updates. @@ -54,23 +54,23 @@ public function testTaxonomyUpdateParents() { /** @var \Drupal\taxonomy\TermInterface $term */ $term = Term::load(1); $parents = [2, 3]; - $this->assertSame(count($term->parent), 2); + $this->assertCount(2, $term->parent); $this->assertTrue(in_array($term->parent[0]->entity->id(), $parents)); $this->assertTrue(in_array($term->parent[1]->entity->id(), $parents)); $term = Term::load(2); $parents = [0, 3]; - $this->assertSame(count($term->parent), 2); + $this->assertCount(2, $term->parent); $this->assertTrue(in_array($term->parent[0]->target_id, $parents)); $this->assertTrue(in_array($term->parent[1]->target_id, $parents)); $term = Term::load(3); - $this->assertSame(count($term->parent), 1); + $this->assertCount(1, $term->parent); // Target ID is returned as string. $this->assertSame((int) $term->get('parent')[0]->target_id, 0); - // Test if the view has been converted to use {taxonomy_term__parent} table - // instead of {taxonomy_term_hierarchy}. + // Test if the view has been converted to use the {taxonomy_term__parent} + // table instead of the {taxonomy_term_hierarchy} table. $view = $this->config("views.view.test_taxonomy_parent"); $path = 'display.default.display_options.relationships.parent.table'; $this->assertSame($view->get($path), 'taxonomy_term__parent'); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityReferenceFieldTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityReferenceFieldTest.php index 6b95303760..cedf6851a8 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityReferenceFieldTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityReferenceFieldTest.php @@ -451,49 +451,4 @@ public function testEntityReferenceFieldDependencies() { $this->assertEqual(['config' => ['field.storage.entity_test.user_reference_field'], 'module' => ['entity_test']], $field->getDependencies()); } - /** - * Tests removing entity references by ID. - */ - public function testRemoveItemsByTargetId() { - // Create the parent entity. - $entity = $this->container->get('entity_type.manager') - ->getStorage($this->entityType) - ->create(['type' => $this->bundle]); - - // Create three target entities and attach them to parent field. - $target_entities = []; - $reference_field = []; - for ($i = 0; $i < 3; $i++) { - $target_entity = $this->container->get('entity_type.manager') - ->getStorage($this->referencedEntityType) - ->create(['type' => $this->bundle]); - $target_entity->save(); - $target_entities[] = $target_entity; - $reference_field[]['target_id'] = $target_entity->id(); - } - - // Set the field value. - $entity->{$this->fieldName}->setValue($reference_field); - - // Remove an item by ID (middle). - $entity->{$this->fieldName}->removeItemsByTargetId($target_entities[1]->id()); - - $values = $entity->{$this->fieldName}->getValue(); - - $this->assertCount(2, $values); - - // Make sure the ID that was removed is not longer in the values. - // - The array will be re-keyed. - // - $target_entities[1] should be missing. - $expected = [ - 0 => [ - 'target_id' => $target_entities[0]->id(), - ], - 1 => [ - 'target_id' => $target_entities[2]->id(), - ] - ]; - $this->assertSame($expected, $values); - } - }