diff --git a/core/lib/Drupal/Core/Cache/MutableCacheableDependencyTrait.php b/core/lib/Drupal/Core/Cache/MutableCacheableDependencyTrait.php index 6c1a681..042c7c9 100644 --- a/core/lib/Drupal/Core/Cache/MutableCacheableDependencyTrait.php +++ b/core/lib/Drupal/Core/Cache/MutableCacheableDependencyTrait.php @@ -38,6 +38,7 @@ */ public function addCacheContexts(array $cache_contexts) { $this->cacheContexts = Cache::mergeContexts($this->cacheContexts, $cache_contexts); + return $this; } /** @@ -45,6 +46,7 @@ public function addCacheContexts(array $cache_contexts) { */ public function addCacheTags(array $cache_tags) { $this->cacheTags = Cache::mergeTags($this->cacheTags, $cache_tags); + return $this; } /** @@ -52,6 +54,7 @@ public function addCacheTags(array $cache_tags) { */ public function addCacheMaxAge($max_age) { $this->cacheMaxAge = Cache::mergeMaxAges($this->cacheMaxAge, $max_age); + return $this; } } diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 46c1147..c9f6502 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -193,7 +193,7 @@ public function enable() { */ public function disable() { // An entity was disabled, invalidate its own cache tag. - Cache::invalidateTags($this->getOriginalCacheTags()); + Cache::invalidateTags($this->getCacheTagsForInvalidation()); return $this->setStatus(FALSE); } diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 7f1034c..4c77b5a 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -449,7 +449,7 @@ public function getCacheContexts() { /** * {@inheritdoc} */ - public function getOriginalCacheTags() { + public function getCacheTagsForInvalidation() { // @todo Add bundle-specific listing cache tag? // https://www.drupal.org/node/2145751 if ($this->isNew()) { @@ -463,9 +463,9 @@ public function getOriginalCacheTags() { */ public function getCacheTags() { if ($this->cacheTags) { - return Cache::mergeTags($this->getOriginalCacheTags(), $this->cacheTags); + return Cache::mergeTags($this->getCacheTagsForInvalidation(), $this->cacheTags); } - return $this->getOriginalCacheTags(); + return $this->getCacheTagsForInvalidation(); } /** @@ -527,7 +527,7 @@ protected function invalidateTagsOnSave($update) { } if ($update) { // An existing entity was updated, also invalidate its unique cache tag. - $tags = Cache::mergeTags($tags, $this->getOriginalCacheTags()); + $tags = Cache::mergeTags($tags, $this->getCacheTagsForInvalidation()); } Cache::invalidateTags($tags); } @@ -548,7 +548,7 @@ protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_typ // 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->getOriginalCacheTags()); + $tags = Cache::mergeTags($tags, $entity->getCacheTagsForInvalidation()); } Cache::invalidateTags($tags); } diff --git a/core/lib/Drupal/Core/Entity/EntityInterface.php b/core/lib/Drupal/Core/Entity/EntityInterface.php index b4cf66f..308e16c 100644 --- a/core/lib/Drupal/Core/Entity/EntityInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityInterface.php @@ -355,7 +355,7 @@ public function getOriginalId(); * @return string[] * List of cache tags. */ - public function getOriginalCacheTags(); + public function getCacheTagsForInvalidation(); /** * Sets the original ID. diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index dd76354..933a257 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -969,7 +969,7 @@ public function getTranslationFromContext(EntityInterface $entity, $langcode = N if ($entity instanceof TranslatableInterface && count($entity->getTranslationLanguages()) > 1) { if (empty($langcode)) { $langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId(); - $entity->addRuntimeCacheContexts(['languages:' . LanguageInterface::TYPE_CONTENT]); + $entity->addRuntimeContexts(['languages:' . LanguageInterface::TYPE_CONTENT]); } // Retrieve language fallback candidates to perform the entity language diff --git a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php index 3a71f44..8281eb9 100644 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php @@ -370,7 +370,7 @@ public function resetCache(array $entities = NULL) { Cache::invalidateTags($tags); } else { - Cache::invalidateTags($this->getOriginalCacheTags()); + Cache::invalidateTags($this->getCacheTags()); } } diff --git a/core/modules/aggregator/src/Entity/Item.php b/core/modules/aggregator/src/Entity/Item.php index 0badf9a..b3d4af1 100644 --- a/core/modules/aggregator/src/Entity/Item.php +++ b/core/modules/aggregator/src/Entity/Item.php @@ -225,7 +225,7 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) { // handles the regular cases. The Item entity has one special case: a newly // created Item is *also* associated with a Feed, so we must invalidate the // associated Feed's cache tag. - Cache::invalidateTags($this->getOriginalCacheTags()); + Cache::invalidateTags($this->getCacheTagsForInvalidation()); } /** diff --git a/core/modules/block/src/Entity/Block.php b/core/modules/block/src/Entity/Block.php index 5637785..869b544 100644 --- a/core/modules/block/src/Entity/Block.php +++ b/core/modules/block/src/Entity/Block.php @@ -246,7 +246,7 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) { // so we must invalidate the associated block's cache tag (which includes // the theme cache tag). if (!$update) { - Cache::invalidateTags($this->getOriginalCacheTags()); + Cache::invalidateTags($this->getCacheTagsForInvalidation()); } } diff --git a/core/modules/block/src/Tests/BlockViewBuilderTest.php b/core/modules/block/src/Tests/BlockViewBuilderTest.php index dc8ce5a..7d21775 100644 --- a/core/modules/block/src/Tests/BlockViewBuilderTest.php +++ b/core/modules/block/src/Tests/BlockViewBuilderTest.php @@ -194,7 +194,7 @@ public function testBlockViewBuilderAlter() { // Enable the block view alter hook that adds a suffix, for basic testing. \Drupal::state()->set('block_test_view_alter_suffix', TRUE); - Cache::invalidateTags($this->block->getOriginalCacheTags()); + Cache::invalidateTags($this->block->getCacheTagsForInvalidation()); $build = $this->getBlockRenderArray(); $this->assertTrue(isset($build['#suffix']) && $build['#suffix'] === '
Goodbye!', 'A block with content is altered.'); $this->assertIdentical($this->renderer->renderRoot($build), 'Llamas > unicorns!
Goodbye!'); @@ -206,7 +206,7 @@ public function testBlockViewBuilderAlter() { $request->setMethod('GET'); \Drupal::state()->set('block_test.content', NULL); - Cache::invalidateTags($this->block->getOriginalCacheTags()); + Cache::invalidateTags($this->block->getCacheTagsForInvalidation()); $default_keys = array('entity_view', 'block', 'test_block'); $default_tags = array('block_view', 'config:block.block.test_block'); diff --git a/core/modules/contact/src/Tests/Views/ContactLinkTest.php b/core/modules/contact/src/Tests/Views/ContactLinkTest.php index 35a725f..a4db76e 100644 --- a/core/modules/contact/src/Tests/Views/ContactLinkTest.php +++ b/core/modules/contact/src/Tests/Views/ContactLinkTest.php @@ -86,7 +86,7 @@ public function testContactLink() { // Disable contact link for no_contact. $this->userData->set('contact', $no_contact_account->id(), 'enabled', FALSE); // @todo Remove cache invalidation in https://www.drupal.org/node/2477903. - Cache::invalidateTags($no_contact_account->getOriginalCacheTags()); + Cache::invalidateTags($no_contact_account->getCacheTagsForInvalidation()); $this->drupalGet('test-contact-link'); $this->assertContactLinks($accounts, array('root', 'admin')); } diff --git a/core/modules/image/src/Entity/ImageStyle.php b/core/modules/image/src/Entity/ImageStyle.php index 927ede1..1ed79b6 100644 --- a/core/modules/image/src/Entity/ImageStyle.php +++ b/core/modules/image/src/Entity/ImageStyle.php @@ -267,7 +267,7 @@ public function flush($path = NULL) { // Clear caches so that formatters may be added for this style. drupal_theme_rebuild(); - Cache::invalidateTags($this->getOriginalCacheTags()); + Cache::invalidateTags($this->getCacheTagsForInvalidation()); return $this; } diff --git a/core/modules/shortcut/src/Entity/Shortcut.php b/core/modules/shortcut/src/Entity/Shortcut.php index dd553e8..abdc9c5 100644 --- a/core/modules/shortcut/src/Entity/Shortcut.php +++ b/core/modules/shortcut/src/Entity/Shortcut.php @@ -102,7 +102,7 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) { // newly created shortcut is *also* added to a shortcut set, so we must // invalidate the associated shortcut set's cache tag. if (!$update) { - Cache::invalidateTags($this->getOriginalCacheTags()); + Cache::invalidateTags($this->getCacheTagsForInvalidation()); } } diff --git a/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php index 48a19e2..6472cb0 100644 --- a/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php +++ b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php @@ -571,7 +571,7 @@ public function testReferencedEntity() { // a cache miss for every route except the ones for the non-referencing // entity and the empty entity listing. $this->pass("Test invalidation of referenced entity's cache tag.", 'Debug'); - Cache::invalidateTags($this->entity->getOriginalCacheTags()); + Cache::invalidateTags($this->entity->getCacheTagsForInvalidation()); $this->verifyPageCache($referencing_entity_url, 'MISS'); $this->verifyPageCache($listing_url, 'MISS'); $this->verifyPageCache($nonempty_entity_listing_url, 'MISS'); diff --git a/core/modules/system/src/Tests/Entity/EntityWithUriCacheTagsTestBase.php b/core/modules/system/src/Tests/Entity/EntityWithUriCacheTagsTestBase.php index bafdef3..5ef3660 100644 --- a/core/modules/system/src/Tests/Entity/EntityWithUriCacheTagsTestBase.php +++ b/core/modules/system/src/Tests/Entity/EntityWithUriCacheTagsTestBase.php @@ -121,7 +121,7 @@ public function testEntityUri() { // Verify that after invalidating the entity's cache tag directly, there is // a cache miss. $this->pass("Test invalidation of entity's cache tag.", 'Debug'); - Cache::invalidateTags($this->entity->getOriginalCacheTags()); + Cache::invalidateTags($this->entity->getCacheTagsForInvalidation()); $this->verifyPageCache($entity_url, 'MISS'); // Verify a cache hit. diff --git a/core/modules/views/src/Plugin/views/cache/CachePluginBase.php b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php index 9e22e61..5ba6bcd 100644 --- a/core/modules/views/src/Plugin/views/cache/CachePluginBase.php +++ b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php @@ -153,7 +153,7 @@ public function cacheGet($type) { * Clear out cached data for a view. */ public function cacheFlush() { - Cache::invalidateTags($this->view->storage->getOriginalCacheTags()); + Cache::invalidateTags($this->view->storage->getCacheTagsForInvalidation()); } /** diff --git a/core/modules/views/src/Tests/Plugin/CacheTagTest.php b/core/modules/views/src/Tests/Plugin/CacheTagTest.php index e4c1684..309a856 100644 --- a/core/modules/views/src/Tests/Plugin/CacheTagTest.php +++ b/core/modules/views/src/Tests/Plugin/CacheTagTest.php @@ -197,7 +197,7 @@ public function testTagCaching() { $view->destroy(); // Invalidate the views cache tags in order to invalidate the render // caching. - \Drupal::service('cache_tags.invalidator')->invalidateTags($view->storage->getOriginalCacheTags()); + \Drupal::service('cache_tags.invalidator')->invalidateTags($view->storage->getCacheTagsForInvalidation()); $build = $view->buildRenderable(); $renderer->renderPlain($build); diff --git a/core/modules/views_ui/src/ViewUI.php b/core/modules/views_ui/src/ViewUI.php index ef7ea73..32b86a6 100644 --- a/core/modules/views_ui/src/ViewUI.php +++ b/core/modules/views_ui/src/ViewUI.php @@ -1340,28 +1340,28 @@ public function hasTrustedData() { * {@inheritdoc} */ public function addCacheContexts(array $cache_contexts) { - $this->storage->addCacheContexts($cache_contexts); + return $this->storage->addCacheContexts($cache_contexts); } /** * {@inheritdoc} */ public function addCacheMaxAge($max_age) { - $this->storage->addCacheMaxAge($max_age); + return $this->storage->addCacheMaxAge($max_age); } /** * {@inheritdoc} */ - public function getOriginalCacheTags() { - return $this->storage->getOriginalCacheTags(); + public function getCacheTagsForInvalidation() { + return $this->storage->getCacheTagsForInvalidation(); } /** * {@inheritdoc} */ public function addCacheTags(array $cache_tags) { - $this->storage->addCacheTags($cache_tags); + return $this->storage->addCacheTags($cache_tags); } }