You are here

public static function Term::postDelete in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/taxonomy/src/Entity/Term.php \Drupal\taxonomy\Entity\Term::postDelete()

Acts on deleted entities before the delete hook is invoked.

Used after the entities are deleted but before invoking the delete hook.

Parameters

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.

\Drupal\Core\Entity\EntityInterface[] $entities: An array of entities.

Overrides Entity::postDelete

File

core/modules/taxonomy/src/Entity/Term.php, line 65
Contains \Drupal\taxonomy\Entity\Term.

Class

Term
Defines the taxonomy term entity.

Namespace

Drupal\taxonomy\Entity

Code

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.
  $orphans = array();
  foreach (array_keys($entities) as $tid) {
    if ($children = $storage
      ->loadChildren($tid)) {
      foreach ($children as $child) {

        // If the term has multiple parents, we don't delete it.
        $parents = $storage
          ->loadParents($child
          ->id());
        if (empty($parents)) {
          $orphans[] = $child
            ->id();
        }
      }
    }
  }

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