diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 924760f97b8..6c614097cf0 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -3,6 +3,7 @@ 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; @@ -479,8 +480,8 @@ abstract class ConfigEntityBase extends EntityBase implements ConfigEntityInterf * Override to never invalidate the entity's cache tag; the config system * already invalidates it. */ - protected function getTagsToInvalidateOnSave($update) { - return $this->getEntityType()->getListCacheTags(); + protected function invalidateTagsOnSave($update) { + Cache::invalidateTags($this->getListCacheTagsToInvalidate()); } /** @@ -489,8 +490,12 @@ abstract class ConfigEntityBase extends EntityBase implements ConfigEntityInterf * Override to never invalidate the individual entities' cache tags; the * config system already invalidates them. */ - protected static function getTagsToInvalidateOnDelete(EntityTypeInterface $entity_type, array $entities) { - return $entity_type->getListCacheTags(); + 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); } /** diff --git a/core/lib/Drupal/Core/Entity/EntityBase.php b/core/lib/Drupal/Core/Entity/EntityBase.php index 21f3ac30c68..a42ef483366 100644 --- a/core/lib/Drupal/Core/Entity/EntityBase.php +++ b/core/lib/Drupal/Core/Entity/EntityBase.php @@ -509,15 +509,12 @@ abstract class EntityBase implements EntityInterface { } /** - * Get an entity's cache tags upon save. + * 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. - * - * @return string[] - * A set of cache tags. */ - protected function getTagsToInvalidateOnSave($update) { + protected function invalidateTagsOnSave($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 @@ -531,42 +528,7 @@ abstract class EntityBase implements EntityInterface { // An existing entity was updated, also invalidate its unique cache tag. $tags = Cache::mergeTags($tags, $this->getCacheTagsToInvalidate()); } - return $tags; - } - - /** - * 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 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 - // 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()); - $tags = Cache::mergeTags($tags, $entity->getListCacheTagsToInvalidate()); - } - return $tags; + Cache::invalidateTags($tags); } /** @@ -578,7 +540,17 @@ abstract class EntityBase implements EntityInterface { * An array of entities. */ protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_type, array $entities) { - Cache::invalidateTags(static::getTagsToInvalidateOnDelete($entity_type, $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()); + $tags = Cache::mergeTags($tags, $entity->getListCacheTagsToInvalidate()); + } + Cache::invalidateTags($tags); } /**