diff --git a/core/modules/taxonomy/src/Entity/Term.php b/core/modules/taxonomy/src/Entity/Term.php index 043c90d..2661283 100644 --- a/core/modules/taxonomy/src/Entity/Term.php +++ b/core/modules/taxonomy/src/Entity/Term.php @@ -59,6 +59,7 @@ class Term extends ContentEntityBase implements TermInterface { * {@inheritdoc} */ public static function postDelete(EntityStorageInterface $storage, array $entities) { + parent::postDelete($storage, $entities); // See if any of the term's children are about to be become orphans. @@ -77,7 +78,7 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti // Delete term hierarchy information after looking up orphans but before // deleting them so that their children/parent information is consistent. - $storage->deleteTermHierarchy(array_keys($entities)); + $storage->deleteTermsFromTermHierarchy(array_keys($entities)); if (!empty($orphans)) { entity_delete_multiple('taxonomy_term', $orphans); diff --git a/core/modules/taxonomy/src/TermStorage.php b/core/modules/taxonomy/src/TermStorage.php index 60b2330..4af8830 100644 --- a/core/modules/taxonomy/src/TermStorage.php +++ b/core/modules/taxonomy/src/TermStorage.php @@ -106,6 +106,23 @@ public function deleteTermHierarchy($tids) { } /** + *{@inheritdoc} + */ + public function deleteTermHierarchyByParent($pids) { + $this->database->delete('taxonomy_term_hierarchy') + ->condition('parent', $pids) + ->execute(); + } + + /** + * Removes the terms and reference to parents from term_hierarchy. + */ + public function deleteTermsFromTermHierarchy($tids) { + $this->deleteTermHierarchy($tids); + $this->deleteTermHierarchyByParent($tids); + } + + /** * {@inheritdoc} */ public function updateTermHierarchy(EntityInterface $term) { diff --git a/core/modules/taxonomy/src/TermStorageInterface.php b/core/modules/taxonomy/src/TermStorageInterface.php index f60d7a2..5d38a69 100644 --- a/core/modules/taxonomy/src/TermStorageInterface.php +++ b/core/modules/taxonomy/src/TermStorageInterface.php @@ -16,7 +16,7 @@ interface TermStorageInterface extends EntityStorageInterface { /** - * Removed reference to terms from term_hierarchy. + * Removes reference to terms from term_hierarchy. * * @param array $tids * Array of terms that need to be removed from hierarchy. @@ -24,6 +24,13 @@ public function deleteTermHierarchy($tids); /** + * Removes reference to terms from term_hierarchy parent + * @param array $pids + * Array of parent terms that needs to be removed from hierarchy + */ + public function deleteTermHierarchyByParent($pids); + + /** * Updates terms hierarchy information with the hierarchy trail of it. * * @param \Drupal\Core\Entity\EntityInterface $term diff --git a/core/modules/taxonomy/src/Tests/TermTest.php b/core/modules/taxonomy/src/Tests/TermTest.php index 0cd7618..5673bb2 100644 --- a/core/modules/taxonomy/src/Tests/TermTest.php +++ b/core/modules/taxonomy/src/Tests/TermTest.php @@ -111,6 +111,15 @@ function testTaxonomyTermHierarchy() { $term2->save(); $parents = taxonomy_term_load_parents($term2->id()); $this->assertTrue(isset($parents[$term1->id()]) && isset($parents[$term3->id()]), 'Both parents found successfully.'); + + // Delete term 3 from the term edit page. + $this->drupalGet('taxonomy/term/' . $term3->id() . '/edit'); + $this->clickLink(t('Delete')); + $this->drupalPostForm(NULL, NULL, t('Delete')); + + // Check the hierarchy after deleting one parent of multiple parents. + $parents = taxonomy_term_load_parents($term2->id()); + $this->assertTrue(count($parents) == 1, 'Term has one parent.'); } /**