Term::postDelete

public static Term::postDelete(EntityStorageInterface $storage, array $entities)

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 60

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);
  }
}
doc_Drupal
2016-10-29 09:47:03
Comments
Leave a Comment

Please login to continue.