W3cubDocs

/Drupal 8

protected static function Entity::invalidateTagsOnDelete

protected static Entity::invalidateTagsOnDelete(EntityTypeInterface $entity_type, array $entities)

Invalidates an entity's cache tags upon delete.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type definition.

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

File

core/lib/Drupal/Core/Entity/Entity.php, line 549

Class

Entity
Defines a base entity class.

Namespace

Drupal\Core\Entity

Code

protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_type, array $entities) {
  $tags = $entity_type->getListCacheTags();
  foreach ($entities as $entity) {
    // An entity was deleted: invalidate its own cache tag, but also its list
    // cache tags. (A deleted entity may cause changes in a paged list on
    // other pages than the one it's on. The one it's on is handled by its own
    // cache tag, but subsequent list pages would not be invalidated, hence we
    // must invalidate its list cache tags as well.)
    $tags = Cache::mergeTags($tags, $entity->getCacheTagsToInvalidate());
  }
  Cache::invalidateTags($tags);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!Entity.php/function/Entity::invalidateTagsOnDelete/8.1.x