1 taxonomy.entity.inc protected TaxonomyTermController::postDelete($entities)

Overrides EntityDatabaseStorageController::postDelete().

Parameters

TaxonomyTerm[] $entities: An array of term entities that were just deleted.

Overrides EntityDatabaseStorageController::postDelete

File

core/modules/taxonomy/taxonomy.entity.inc, line 238
Entity classes and controllers for Taxonomy module.

Class

TaxonomyTermController
Controller class for taxonomy terms.

Code

protected function postDelete($entities) {
  // See if any of the term's children are about to be become orphans.
  $orphans = array();
  foreach (array_keys($entities) as $tid) {
    if ($children = taxonomy_term_load_children($tid)) {
      foreach ($children as $child) {
        // If the term has multiple parents, we don't delete it.
        $parents = taxonomy_term_load_parents($child->tid);
        // Because the parent has already been deleted, the parent count might
        // be 0.
        if (count($parents) <= 1) {
          $orphans[] = $child->tid;
        }
      }
    }
  }

  // Delete term hierarchy information after looking up orphans but before
  // deleting them so that their children/parent information is consistent.
  db_delete('taxonomy_term_hierarchy')
    ->condition('tid', array_keys($entities))
    ->execute();

  if (!empty($orphans)) {
    taxonomy_term_delete_multiple($orphans);
  }
}