protected function TermStorageController::postDelete

Overrides Drupal\Core\Entity\DatabaseStorageController::postDelete().

Overrides DatabaseStorageController::postDelete

File

drupal/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php, line 49
Definition of Drupal\taxonomy\TermStorageController.

Class

TermStorageController
Defines a Controller class for taxonomy terms.

Namespace

Drupal\taxonomy

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
          ->id());

        // Because the parent has already been deleted, the parent count might
        // be 0.
        if (count($parents) <= 1) {
          $orphans[] = $child
            ->id();
        }
      }
    }
  }

  // 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)) {
    entity_delete_multiple('taxonomy_term', $orphans);
  }
}