diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 6c614097cf0847d9619e64e7f09978bb95e42460..924760f97b8c07fc5590eb047738d0ee5c5db16a 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -3,7 +3,6 @@ namespace Drupal\Core\Config\Entity; use Drupal\Component\Utility\NestedArray; -use Drupal\Core\Cache\Cache; use Drupal\Core\Config\Schema\SchemaIncompleteException; use Drupal\Core\Entity\EntityBase; use Drupal\Core\Config\ConfigDuplicateUUIDException; @@ -480,8 +479,8 @@ public function onDependencyRemoval(array $dependencies) { * Override to never invalidate the entity's cache tag; the config system * already invalidates it. */ - protected function invalidateTagsOnSave($update) { - Cache::invalidateTags($this->getListCacheTagsToInvalidate()); + protected function getTagsToInvalidateOnSave($update) { + return $this->getEntityType()->getListCacheTags(); } /** @@ -490,12 +489,8 @@ protected function invalidateTagsOnSave($update) { * Override to never invalidate the individual entities' cache tags; the * config system already invalidates them. */ - protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_type, array $entities) { - $tags = $entity_type->getListCacheTags(); - foreach ($entities as $entity) { - $tags = Cache::mergeTags($tags, $entity->getListCacheTagsToInvalidate()); - } - Cache::invalidateTags($tags); + protected static function getTagsToInvalidateOnDelete(EntityTypeInterface $entity_type, array $entities) { + return $entity_type->getListCacheTags(); } /** diff --git a/core/lib/Drupal/Core/Entity/EntityBase.php b/core/lib/Drupal/Core/Entity/EntityBase.php index a42ef483366fe86768bafa54d50ed3b32158d6a2..21f3ac30c68474958a602f6133cb4c14cd546bfd 100644 --- a/core/lib/Drupal/Core/Entity/EntityBase.php +++ b/core/lib/Drupal/Core/Entity/EntityBase.php @@ -509,12 +509,15 @@ public static function create(array $values = []) { } /** - * Invalidates an entity's cache tags upon save. + * Get an entity's cache tags upon save. * * @param bool $update * TRUE if the entity has been updated, or FALSE if it has been inserted. + * + * @return string[] + * A set of cache tags. */ - protected function invalidateTagsOnSave($update) { + protected function getTagsToInvalidateOnSave($update) { // An entity was created or updated: invalidate its list cache tags. (An // updated entity may start to appear in a listing because it now meets that // listing's filtering requirements. A newly created entity may start to @@ -528,18 +531,31 @@ protected function invalidateTagsOnSave($update) { // An existing entity was updated, also invalidate its unique cache tag. $tags = Cache::mergeTags($tags, $this->getCacheTagsToInvalidate()); } - Cache::invalidateTags($tags); + return $tags; } /** - * Invalidates an entity's cache tags upon delete. + * Invalidates an entity's cache tags upon save. + * + * @param bool $update + * TRUE if the entity has been updated, or FALSE if it has been inserted. + */ + protected function invalidateTagsOnSave($update) { + Cache::invalidateTags($this->getTagsToInvalidateOnSave($update)); + } + + /** + * Get entity's cache tags upon delete. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type definition. * @param \Drupal\Core\Entity\EntityInterface[] $entities * An array of entities. + * + * @return string[] + * A set of cache tags. */ - protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_type, array $entities) { + protected static function getTagsToInvalidateOnDelete(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 @@ -550,7 +566,19 @@ protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_typ $tags = Cache::mergeTags($tags, $entity->getCacheTagsToInvalidate()); $tags = Cache::mergeTags($tags, $entity->getListCacheTagsToInvalidate()); } - Cache::invalidateTags($tags); + return $tags; + } + + /** + * Invalidates an entity's cache tags upon delete. + * + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * The entity type definition. + * @param \Drupal\Core\Entity\EntityInterface[] $entities + * An array of entities. + */ + protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_type, array $entities) { + Cache::invalidateTags(static::getTagsToInvalidateOnDelete($entity_type, $entities)); } /**