core/lib/Drupal/Core/Cache/CacheableResponseInterface.php | 4 +++- core/lib/Drupal/Core/Cache/CacheableResponseTrait.php | 4 +++- .../Drupal/Core/EventSubscriber/AnonymousUserResponseSubscriber.php | 2 +- core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/lib/Drupal/Core/Cache/CacheableResponseInterface.php b/core/lib/Drupal/Core/Cache/CacheableResponseInterface.php index 3b28794..99db5fa 100644 --- a/core/lib/Drupal/Core/Cache/CacheableResponseInterface.php +++ b/core/lib/Drupal/Core/Cache/CacheableResponseInterface.php @@ -23,6 +23,8 @@ * * @param \Drupal\Core\Cache\CacheableDependencyInterface|mixed $dependency * The dependency. + * + * @return $this */ public function addCacheableDependency($dependency); @@ -31,6 +33,6 @@ public function addCacheableDependency($dependency); * * @return \Drupal\Core\Cache\CacheableMetadata */ - public function getCacheability(); + public function getCacheableMetadata(); } diff --git a/core/lib/Drupal/Core/Cache/CacheableResponseTrait.php b/core/lib/Drupal/Core/Cache/CacheableResponseTrait.php index 3e0f964..2940c13 100644 --- a/core/lib/Drupal/Core/Cache/CacheableResponseTrait.php +++ b/core/lib/Drupal/Core/Cache/CacheableResponseTrait.php @@ -27,12 +27,14 @@ public function addCacheableDependency($dependency) { } $this->cacheabilityMetadata = $this->cacheabilityMetadata->merge(CacheableMetadata::createFromObject($dependency)); + + return $this; } /** * {@inheritdoc} */ - public function getCacheability() { + public function getCacheableMetadata() { // A trait doesn't have a constructor, so initialize the cacheability // metadata if that hasn't happened yet. if (!isset($this->cacheabilityMetadata)) { diff --git a/core/lib/Drupal/Core/EventSubscriber/AnonymousUserResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/AnonymousUserResponseSubscriber.php index 569a473..0e64698 100644 --- a/core/lib/Drupal/Core/EventSubscriber/AnonymousUserResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/AnonymousUserResponseSubscriber.php @@ -65,7 +65,7 @@ public function onRespond(FilterResponseEvent $event) { // be invalidated. Therefore, when varying by permissions and the current // user is the anonymous user, also add the cache tag for the 'anonymous' // role. - if (in_array('user.permissions', $response->getCacheability()->getCacheContexts())) { + if (in_array('user.permissions', $response->getCacheableMetadata()->getCacheContexts())) { $per_permissions_response_for_anon = new CacheableMetadata(); $per_permissions_response_for_anon->setCacheTags(['config:user.role.anonymous']); $response->addCacheableDependency($per_permissions_response_for_anon); diff --git a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php index 4996a92..66283d8 100644 --- a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php @@ -138,7 +138,7 @@ public function onRespond(FilterResponseEvent $event) { // Expose the cache contexts and cache tags associated with this page in a // X-Drupal-Cache-Contexts and X-Drupal-Cache-Tags header respectively. if ($response instanceof CacheableResponseInterface) { - $response_cacheability = $response->getCacheability(); + $response_cacheability = $response->getCacheableMetadata(); $response->headers->set('X-Drupal-Cache-Tags', implode(' ', $response_cacheability->getCacheTags())); $response->headers->set('X-Drupal-Cache-Contexts', implode(' ', $this->cacheContextsManager->optimizeTokens($response_cacheability->getCacheContexts()))); }