diff --git a/core/lib/Drupal/Core/Cache/CacheableMetadata.php b/core/lib/Drupal/Core/Cache/CacheabilityMetadata.php similarity index 87% rename from core/lib/Drupal/Core/Cache/CacheableMetadata.php rename to core/lib/Drupal/Core/Cache/CacheabilityMetadata.php index b0b10a5a63..08157932ce 100644 --- a/core/lib/Drupal/Core/Cache/CacheableMetadata.php +++ b/core/lib/Drupal/Core/Cache/CacheabilityMetadata.php @@ -7,7 +7,7 @@ * * @ingroup cache */ -class CacheableMetadata implements RefinableCacheableDependencyInterface { +class CacheabilityMetadata implements RefinableCacheableDependencyInterface { use RefinableCacheableDependencyTrait; @@ -81,15 +81,15 @@ public function setCacheMaxAge($max_age) { } /** - * Merges the values of another CacheableMetadata object with this one. + * Merges the values of another CacheabilityMetadata object with this one. * - * @param \Drupal\Core\Cache\CacheableMetadata $other - * The other CacheableMetadata object. + * @param \Drupal\Core\Cache\CacheabilityMetadata $other + * The other CacheabilityMetadata object. * * @return static - * A new CacheableMetadata object, with the merged data. + * A new CacheabilityMetadata object, with the merged data. */ - public function merge(CacheableMetadata $other) { + public function merge(CacheabilityMetadata $other) { $result = clone $this; // This is called many times per request, so avoid merging unless absolutely @@ -127,7 +127,7 @@ public function merge(CacheableMetadata $other) { } /** - * Applies the values of this CacheableMetadata object to a render array. + * Applies the values of this CacheabilityMetadata object to a render array. * * @param array &$build * A render array. @@ -139,7 +139,7 @@ public function applyTo(array &$build) { } /** - * Creates a CacheableMetadata object with values taken from a render array. + * Creates a CacheabilityMetadata object with values taken from a render array. * * @param array $build * A render array. @@ -155,7 +155,7 @@ public static function createFromRenderArray(array $build) { } /** - * Creates a CacheableMetadata object from a depended object. + * Creates a CacheabilityMetadata object from a depended object. * * @param \Drupal\Core\Cache\CacheableDependencyInterface|mixed $object * The object whose cacheability metadata to retrieve. If it implements diff --git a/core/lib/Drupal/Core/Cache/CacheableJsonResponse.php b/core/lib/Drupal/Core/Cache/CacheableJsonResponse.php index da2344eca9..f6402c4772 100644 --- a/core/lib/Drupal/Core/Cache/CacheableJsonResponse.php +++ b/core/lib/Drupal/Core/Cache/CacheableJsonResponse.php @@ -11,7 +11,7 @@ * contexts for variations. * * @see \Drupal\Core\Cache\Cache - * @see \Drupal\Core\Cache\CacheableMetadata + * @see \Drupal\Core\Cache\CacheabilityMetadata * @see \Drupal\Core\Cache\CacheableResponseTrait */ class CacheableJsonResponse extends JsonResponse implements CacheableResponseInterface { diff --git a/core/lib/Drupal/Core/Cache/CacheableRedirectResponse.php b/core/lib/Drupal/Core/Cache/CacheableRedirectResponse.php index a94755972e..16054593dc 100644 --- a/core/lib/Drupal/Core/Cache/CacheableRedirectResponse.php +++ b/core/lib/Drupal/Core/Cache/CacheableRedirectResponse.php @@ -11,7 +11,7 @@ * contexts for variations. * * @see \Drupal\Core\Cache\Cache - * @see \Drupal\Core\Cache\CacheableMetadata + * @see \Drupal\Core\Cache\CacheabilityMetadata * @see \Drupal\Core\Cache\CacheableResponseTrait */ class CacheableRedirectResponse extends RedirectResponse implements CacheableResponseInterface { diff --git a/core/lib/Drupal/Core/Cache/CacheableResponse.php b/core/lib/Drupal/Core/Cache/CacheableResponse.php index efd839b9d2..c896006951 100644 --- a/core/lib/Drupal/Core/Cache/CacheableResponse.php +++ b/core/lib/Drupal/Core/Cache/CacheableResponse.php @@ -11,7 +11,7 @@ * contexts for variations. * * @see \Drupal\Core\Cache\Cache - * @see \Drupal\Core\Cache\CacheableMetadata + * @see \Drupal\Core\Cache\CacheabilityMetadata * @see \Drupal\Core\Cache\CacheableResponseTrait */ class CacheableResponse extends Response implements CacheableResponseInterface { diff --git a/core/lib/Drupal/Core/Cache/CacheableResponseInterface.php b/core/lib/Drupal/Core/Cache/CacheableResponseInterface.php index cbac2d1be0..48545fbad4 100644 --- a/core/lib/Drupal/Core/Cache/CacheableResponseInterface.php +++ b/core/lib/Drupal/Core/Cache/CacheableResponseInterface.php @@ -23,15 +23,15 @@ * * @return $this * - * @see \Drupal\Core\Cache\CacheableMetadata::createFromObject() + * @see \Drupal\Core\Cache\CacheabilityMetadata::createFromObject() */ public function addCacheableDependency($dependency); /** * Returns the cacheability metadata for this response. * - * @return \Drupal\Core\Cache\CacheableMetadata + * @return \Drupal\Core\Cache\CacheabilityMetadata */ - public function getCacheableMetadata(); + public function getCacheabilityMetadata(); } diff --git a/core/lib/Drupal/Core/Cache/CacheableResponseTrait.php b/core/lib/Drupal/Core/Cache/CacheableResponseTrait.php index 2940c13097..b657dd4f0a 100644 --- a/core/lib/Drupal/Core/Cache/CacheableResponseTrait.php +++ b/core/lib/Drupal/Core/Cache/CacheableResponseTrait.php @@ -12,7 +12,7 @@ /** * The cacheability metadata. * - * @var \Drupal\Core\Cache\CacheableMetadata + * @var \Drupal\Core\Cache\CacheabilityMetadata */ protected $cacheabilityMetadata; @@ -23,10 +23,10 @@ public function addCacheableDependency($dependency) { // A trait doesn't have a constructor, so initialize the cacheability // metadata if that hasn't happened yet. if (!isset($this->cacheabilityMetadata)) { - $this->cacheabilityMetadata = new CacheableMetadata(); + $this->cacheabilityMetadata = new CacheabilityMetadata(); } - $this->cacheabilityMetadata = $this->cacheabilityMetadata->merge(CacheableMetadata::createFromObject($dependency)); + $this->cacheabilityMetadata = $this->cacheabilityMetadata->merge(CacheabilityMetadata::createFromObject($dependency)); return $this; } @@ -34,11 +34,11 @@ public function addCacheableDependency($dependency) { /** * {@inheritdoc} */ - public function getCacheableMetadata() { + public function getCacheabilityMetadata() { // A trait doesn't have a constructor, so initialize the cacheability // metadata if that hasn't happened yet. if (!isset($this->cacheabilityMetadata)) { - $this->cacheabilityMetadata = new CacheableMetadata(); + $this->cacheabilityMetadata = new CacheabilityMetadata(); } return $this->cacheabilityMetadata; diff --git a/core/lib/Drupal/Core/Cache/Context/AccountPermissionsCacheContext.php b/core/lib/Drupal/Core/Cache/Context/AccountPermissionsCacheContext.php index c101968663..c3d5ba6fd0 100644 --- a/core/lib/Drupal/Core/Cache/Context/AccountPermissionsCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/AccountPermissionsCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\PermissionsHashGeneratorInterface; @@ -50,8 +50,8 @@ public function getContext() { /** * {@inheritdoc} */ - public function getCacheableMetadata() { - $cacheable_metadata = new CacheableMetadata(); + public function getCacheabilityMetadata() { + $cacheability_metadata = new CacheabilityMetadata(); // The permissions hash changes when: // - a user is updated to have different roles; @@ -61,7 +61,7 @@ public function getCacheableMetadata() { $tags[] = "config:user.role.$rid"; } - return $cacheable_metadata->setCacheTags($tags); + return $cacheability_metadata->setCacheTags($tags); } } diff --git a/core/lib/Drupal/Core/Cache/Context/CacheContextInterface.php b/core/lib/Drupal/Core/Cache/Context/CacheContextInterface.php index b7538fa67d..c6dce2228d 100644 --- a/core/lib/Drupal/Core/Cache/Context/CacheContextInterface.php +++ b/core/lib/Drupal/Core/Cache/Context/CacheContextInterface.php @@ -29,7 +29,7 @@ public function getContext(); /** * Gets the cacheability metadata for the context. * - * There are three valid cases for the returned CacheableMetadata object: + * There are three valid cases for the returned CacheabilityMetadata object: * - An empty object means this can be optimized away safely. * - A max-age of 0 means that this context can never be optimized away. It * will never bubble up and cache tags will not be used. @@ -38,9 +38,9 @@ public function getContext(); * value changes. * * - * @return \Drupal\Core\Cache\CacheableMetadata + * @return \Drupal\Core\Cache\CacheabilityMetadata * A cacheable metadata object. */ - public function getCacheableMetadata(); + public function getCacheabilityMetadata(); } diff --git a/core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php b/core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php index 056f838c04..0194a5e5e8 100644 --- a/core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php +++ b/core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -101,14 +101,14 @@ public function getLabels($include_calculated_cache_contexts = FALSE) { */ public function convertTokensToKeys(array $context_tokens) { assert($this->assertValidTokens($context_tokens)); - $cacheable_metadata = new CacheableMetadata(); + $cacheability_metadata = new CacheabilityMetadata(); $optimized_tokens = $this->optimizeTokens($context_tokens); // Iterate over cache contexts that have been optimized away and get their // cacheability metadata. foreach (static::parseTokens(array_diff($context_tokens, $optimized_tokens)) as $context_token) { list($context_id, $parameter) = $context_token; $context = $this->getService($context_id); - $cacheable_metadata = $cacheable_metadata->merge($context->getCacheableMetadata($parameter)); + $cacheability_metadata = $cacheability_metadata->merge($context->getCacheabilityMetadata($parameter)); } sort($optimized_tokens); @@ -120,7 +120,7 @@ public function convertTokensToKeys(array $context_tokens) { // Create the returned object and merge in the cacheability metadata. $context_cache_keys = new ContextCacheKeys($keys); - return $context_cache_keys->merge($cacheable_metadata); + return $context_cache_keys->merge($cacheability_metadata); } /** @@ -176,7 +176,7 @@ public function optimizeTokens(array $context_tokens) { } // Check cacheability. If the context defines a max-age of 0, then it // can not be optimized away. Pass the parameter along if we have one. - elseif ($this->getService($context_id)->getCacheableMetadata($parameter)->getCacheMaxAge() === 0) { + elseif ($this->getService($context_id)->getCacheabilityMetadata($parameter)->getCacheMaxAge() === 0) { $optimized_content_tokens[] = $context_token; } // The context token has a period or a colon. Iterate over all ancestor diff --git a/core/lib/Drupal/Core/Cache/Context/CalculatedCacheContextInterface.php b/core/lib/Drupal/Core/Cache/Context/CalculatedCacheContextInterface.php index 74be67027c..0cd47df7a9 100644 --- a/core/lib/Drupal/Core/Cache/Context/CalculatedCacheContextInterface.php +++ b/core/lib/Drupal/Core/Cache/Context/CalculatedCacheContextInterface.php @@ -38,7 +38,7 @@ public function getContext($parameter = NULL); /** * Gets the cacheability metadata for the context based on the parameter value. * - * There are three valid cases for the returned CacheableMetadata object: + * There are three valid cases for the returned CacheabilityMetadata object: * - An empty object means this can be optimized away safely. * - A max-age of 0 means that this context can never be optimized away. It * will never bubble up and cache tags will not be used. @@ -49,12 +49,12 @@ public function getContext($parameter = NULL); * @param string|null $parameter * The parameter, or NULL to indicate all possible parameter values. * - * @return \Drupal\Core\Cache\CacheableMetadata + * @return \Drupal\Core\Cache\CacheabilityMetadata * A cacheable metadata object. * * @throws \LogicException * Thrown if the passed in parameter is invalid. */ - public function getCacheableMetadata($parameter = NULL); + public function getCacheabilityMetadata($parameter = NULL); } diff --git a/core/lib/Drupal/Core/Cache/Context/ContextCacheKeys.php b/core/lib/Drupal/Core/Cache/Context/ContextCacheKeys.php index 27b227cb60..ee065e048e 100644 --- a/core/lib/Drupal/Core/Cache/Context/ContextCacheKeys.php +++ b/core/lib/Drupal/Core/Cache/Context/ContextCacheKeys.php @@ -2,12 +2,12 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; /** * A value object to store generated cache keys with its cacheability metadata. */ -class ContextCacheKeys extends CacheableMetadata { +class ContextCacheKeys extends CacheabilityMetadata { /** * The generated cache keys. diff --git a/core/lib/Drupal/Core/Cache/Context/CookiesCacheContext.php b/core/lib/Drupal/Core/Cache/Context/CookiesCacheContext.php index fe7f4f5017..b498071f93 100644 --- a/core/lib/Drupal/Core/Cache/Context/CookiesCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/CookiesCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; /** * Defines the CookiesCacheContext service, for "per cookie" caching. @@ -35,8 +35,8 @@ public function getContext($cookie = NULL) { /** * {@inheritdoc} */ - public function getCacheableMetadata($cookie = NULL) { - return new CacheableMetadata(); + public function getCacheabilityMetadata($cookie = NULL) { + return new CacheabilityMetadata(); } } diff --git a/core/lib/Drupal/Core/Cache/Context/HeadersCacheContext.php b/core/lib/Drupal/Core/Cache/Context/HeadersCacheContext.php index 71db8e64c7..e3cea0d61c 100644 --- a/core/lib/Drupal/Core/Cache/Context/HeadersCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/HeadersCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; /** * Defines the HeadersCacheContext service, for "per header" caching. @@ -52,8 +52,8 @@ public function getContext($header = NULL) { /** * {@inheritdoc} */ - public function getCacheableMetadata($header = NULL) { - return new CacheableMetadata(); + public function getCacheabilityMetadata($header = NULL) { + return new CacheabilityMetadata(); } } diff --git a/core/lib/Drupal/Core/Cache/Context/IpCacheContext.php b/core/lib/Drupal/Core/Cache/Context/IpCacheContext.php index 9285cb560d..782db03c63 100644 --- a/core/lib/Drupal/Core/Cache/Context/IpCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/IpCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; /** * Defines the IpCacheContext service, for "per IP address" caching. @@ -28,8 +28,8 @@ public function getContext() { /** * {@inheritdoc} */ - public function getCacheableMetadata() { - return new CacheableMetadata(); + public function getCacheabilityMetadata() { + return new CacheabilityMetadata(); } } diff --git a/core/lib/Drupal/Core/Cache/Context/IsFrontPathCacheContext.php b/core/lib/Drupal/Core/Cache/Context/IsFrontPathCacheContext.php index 141b13a63f..6f45c4c1bb 100644 --- a/core/lib/Drupal/Core/Cache/Context/IsFrontPathCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/IsFrontPathCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Path\PathMatcherInterface; /** @@ -43,8 +43,8 @@ public function getContext() { /** * {@inheritdoc} */ - public function getCacheableMetadata() { - $metadata = new CacheableMetadata(); + public function getCacheabilityMetadata() { + $metadata = new CacheabilityMetadata(); $metadata->addCacheTags(['config:system.site']); return $metadata; } diff --git a/core/lib/Drupal/Core/Cache/Context/IsSuperUserCacheContext.php b/core/lib/Drupal/Core/Cache/Context/IsSuperUserCacheContext.php index c6c489427c..cd2733748c 100644 --- a/core/lib/Drupal/Core/Cache/Context/IsSuperUserCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/IsSuperUserCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; /** * Defines the IsSuperUserCacheContext service, for "super user or not" caching. @@ -28,8 +28,8 @@ public function getContext() { /** * {@inheritdoc} */ - public function getCacheableMetadata() { - return new CacheableMetadata(); + public function getCacheabilityMetadata() { + return new CacheabilityMetadata(); } } diff --git a/core/lib/Drupal/Core/Cache/Context/LanguagesCacheContext.php b/core/lib/Drupal/Core/Cache/Context/LanguagesCacheContext.php index 620787b6bb..07c569623f 100644 --- a/core/lib/Drupal/Core/Cache/Context/LanguagesCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/LanguagesCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Language\LanguageManagerInterface; /** @@ -73,8 +73,8 @@ public function getContext($type = NULL) { /** * {@inheritdoc} */ - public function getCacheableMetadata($type = NULL) { - return new CacheableMetadata(); + public function getCacheabilityMetadata($type = NULL) { + return new CacheabilityMetadata(); } } diff --git a/core/lib/Drupal/Core/Cache/Context/MenuActiveTrailsCacheContext.php b/core/lib/Drupal/Core/Cache/Context/MenuActiveTrailsCacheContext.php index db31384122..64324a7ccb 100644 --- a/core/lib/Drupal/Core/Cache/Context/MenuActiveTrailsCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/MenuActiveTrailsCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerAwareTrait; @@ -39,12 +39,12 @@ public function getContext($menu_name = NULL) { /** * {@inheritdoc} */ - public function getCacheableMetadata($menu_name = NULL) { + public function getCacheabilityMetadata($menu_name = NULL) { if (!$menu_name) { throw new \LogicException('No menu name provided for menu.active_trails cache context.'); } - $cacheable_metadata = new CacheableMetadata(); - return $cacheable_metadata->setCacheTags(["config:system.menu.$menu_name"]); + $cacheability_metadata = new CacheabilityMetadata(); + return $cacheability_metadata->setCacheTags(["config:system.menu.$menu_name"]); } } diff --git a/core/lib/Drupal/Core/Cache/Context/PagersCacheContext.php b/core/lib/Drupal/Core/Cache/Context/PagersCacheContext.php index cb34256dc7..500d3055f0 100644 --- a/core/lib/Drupal/Core/Cache/Context/PagersCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/PagersCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; /** * Defines a cache context for "per page in a pager" caching. @@ -38,8 +38,8 @@ public function getContext($pager_id = NULL) { /** * {@inheritdoc} */ - public function getCacheableMetadata($pager_id = NULL) { - return new CacheableMetadata(); + public function getCacheabilityMetadata($pager_id = NULL) { + return new CacheabilityMetadata(); } } diff --git a/core/lib/Drupal/Core/Cache/Context/PathCacheContext.php b/core/lib/Drupal/Core/Cache/Context/PathCacheContext.php index 36ac45d5ab..ded9e61a99 100644 --- a/core/lib/Drupal/Core/Cache/Context/PathCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/PathCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; /** * Defines the PathCacheContext service, for "per URL path" caching. @@ -34,8 +34,8 @@ public function getContext() { /** * {@inheritdoc} */ - public function getCacheableMetadata() { - return new CacheableMetadata(); + public function getCacheabilityMetadata() { + return new CacheabilityMetadata(); } } diff --git a/core/lib/Drupal/Core/Cache/Context/PathParentCacheContext.php b/core/lib/Drupal/Core/Cache/Context/PathParentCacheContext.php index 76c22fb32c..f166121cc9 100644 --- a/core/lib/Drupal/Core/Cache/Context/PathParentCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/PathParentCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; /** * Defines a cache context service for path parents. @@ -34,8 +34,8 @@ public function getContext() { /** * {@inheritdoc} */ - public function getCacheableMetadata() { - return new CacheableMetadata(); + public function getCacheabilityMetadata() { + return new CacheabilityMetadata(); } } diff --git a/core/lib/Drupal/Core/Cache/Context/QueryArgsCacheContext.php b/core/lib/Drupal/Core/Cache/Context/QueryArgsCacheContext.php index a48664468d..bcc243d93b 100644 --- a/core/lib/Drupal/Core/Cache/Context/QueryArgsCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/QueryArgsCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; /** * Defines the QueryArgsCacheContext service, for "per query args" caching. @@ -46,8 +46,8 @@ public function getContext($query_arg = NULL) { /** * {@inheritdoc} */ - public function getCacheableMetadata($query_arg = NULL) { - return new CacheableMetadata(); + public function getCacheabilityMetadata($query_arg = NULL) { + return new CacheabilityMetadata(); } } diff --git a/core/lib/Drupal/Core/Cache/Context/RequestFormatCacheContext.php b/core/lib/Drupal/Core/Cache/Context/RequestFormatCacheContext.php index 7df737d852..8437a18cbd 100644 --- a/core/lib/Drupal/Core/Cache/Context/RequestFormatCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/RequestFormatCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; /** * Defines the RequestFormatCacheContext service, for "per format" caching. @@ -28,8 +28,8 @@ public function getContext() { /** * {@inheritdoc} */ - public function getCacheableMetadata() { - return new CacheableMetadata(); + public function getCacheabilityMetadata() { + return new CacheabilityMetadata(); } } diff --git a/core/lib/Drupal/Core/Cache/Context/RouteCacheContext.php b/core/lib/Drupal/Core/Cache/Context/RouteCacheContext.php index 0438925ee4..6d50c1fca4 100644 --- a/core/lib/Drupal/Core/Cache/Context/RouteCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/RouteCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Routing\RouteMatchInterface; /** @@ -46,8 +46,8 @@ public function getContext() { /** * {@inheritdoc} */ - public function getCacheableMetadata() { - return new CacheableMetadata(); + public function getCacheabilityMetadata() { + return new CacheabilityMetadata(); } } diff --git a/core/lib/Drupal/Core/Cache/Context/SessionExistsCacheContext.php b/core/lib/Drupal/Core/Cache/Context/SessionExistsCacheContext.php index 7ffc5e9866..a235838aee 100644 --- a/core/lib/Drupal/Core/Cache/Context/SessionExistsCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/SessionExistsCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Session\SessionConfigurationInterface; use Symfony\Component\HttpFoundation\RequestStack; @@ -57,8 +57,8 @@ public function getContext() { /** * {@inheritdoc} */ - public function getCacheableMetadata() { - return new CacheableMetadata(); + public function getCacheabilityMetadata() { + return new CacheabilityMetadata(); } } diff --git a/core/lib/Drupal/Core/Cache/Context/SiteCacheContext.php b/core/lib/Drupal/Core/Cache/Context/SiteCacheContext.php index 16516c5e2f..7d94853b03 100644 --- a/core/lib/Drupal/Core/Cache/Context/SiteCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/SiteCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; /** * Defines the SiteCacheContext service, for "per site" caching. @@ -37,8 +37,8 @@ public function getContext() { /** * {@inheritdoc} */ - public function getCacheableMetadata() { - return new CacheableMetadata(); + public function getCacheabilityMetadata() { + return new CacheabilityMetadata(); } } diff --git a/core/lib/Drupal/Core/Cache/Context/ThemeCacheContext.php b/core/lib/Drupal/Core/Cache/Context/ThemeCacheContext.php index e7aeb894b0..e812ca7a26 100644 --- a/core/lib/Drupal/Core/Cache/Context/ThemeCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/ThemeCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Theme\ThemeManagerInterface; /** @@ -46,8 +46,8 @@ public function getContext() { /** * {@inheritdoc} */ - public function getCacheableMetadata() { - return new CacheableMetadata(); + public function getCacheabilityMetadata() { + return new CacheabilityMetadata(); } } diff --git a/core/lib/Drupal/Core/Cache/Context/TimeZoneCacheContext.php b/core/lib/Drupal/Core/Cache/Context/TimeZoneCacheContext.php index 318817264c..4d22b03f44 100644 --- a/core/lib/Drupal/Core/Cache/Context/TimeZoneCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/TimeZoneCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; /** * Defines the TimeZoneCacheContext service, for "per time zone" caching. @@ -32,8 +32,8 @@ public function getContext() { /** * {@inheritdoc} */ - public function getCacheableMetadata() { - return new CacheableMetadata(); + public function getCacheabilityMetadata() { + return new CacheabilityMetadata(); } } diff --git a/core/lib/Drupal/Core/Cache/Context/UrlCacheContext.php b/core/lib/Drupal/Core/Cache/Context/UrlCacheContext.php index 28303303e2..884dfebc13 100644 --- a/core/lib/Drupal/Core/Cache/Context/UrlCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/UrlCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; /** * Defines the UrlCacheContext service, for "per page" caching. @@ -28,8 +28,8 @@ public function getContext() { /** * {@inheritdoc} */ - public function getCacheableMetadata() { - return new CacheableMetadata(); + public function getCacheabilityMetadata() { + return new CacheabilityMetadata(); } } diff --git a/core/lib/Drupal/Core/Cache/Context/UserCacheContext.php b/core/lib/Drupal/Core/Cache/Context/UserCacheContext.php index 868e5fedf8..b0f421e817 100644 --- a/core/lib/Drupal/Core/Cache/Context/UserCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/UserCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; /** * Defines the UserCacheContext service, for "per user" caching. @@ -28,8 +28,8 @@ public function getContext() { /** * {@inheritdoc} */ - public function getCacheableMetadata() { - return new CacheableMetadata(); + public function getCacheabilityMetadata() { + return new CacheabilityMetadata(); } } diff --git a/core/lib/Drupal/Core/Cache/Context/UserRolesCacheContext.php b/core/lib/Drupal/Core/Cache/Context/UserRolesCacheContext.php index 0cd0fbe1a5..04f9488880 100644 --- a/core/lib/Drupal/Core/Cache/Context/UserRolesCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/UserRolesCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; /** * Defines the UserRolesCacheContext service, for "per role" caching. @@ -45,8 +45,8 @@ public function getContext($role = NULL) { /** * {@inheritdoc} */ - public function getCacheableMetadata($role = NULL) { - return (new CacheableMetadata())->setCacheTags(['user:' . $this->user->id()]); + public function getCacheabilityMetadata($role = NULL) { + return (new CacheabilityMetadata())->setCacheTags(['user:' . $this->user->id()]); } } diff --git a/core/lib/Drupal/Core/Cache/RefinableCacheableDependencyInterface.php b/core/lib/Drupal/Core/Cache/RefinableCacheableDependencyInterface.php index 341553fa2a..2c918e5c68 100644 --- a/core/lib/Drupal/Core/Cache/RefinableCacheableDependencyInterface.php +++ b/core/lib/Drupal/Core/Cache/RefinableCacheableDependencyInterface.php @@ -58,7 +58,7 @@ public function mergeCacheMaxAge($max_age); * * @return $this * - * @see \Drupal\Core\Cache\CacheableMetadata::createFromObject() + * @see \Drupal\Core\Cache\CacheabilityMetadata::createFromObject() */ public function addCacheableDependency($other_object); diff --git a/core/lib/Drupal/Core/Config/ConfigFactory.php b/core/lib/Drupal/Core/Config/ConfigFactory.php index e4496f88b7..0d86417cf4 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactory.php +++ b/core/lib/Drupal/Core/Config/ConfigFactory.php @@ -122,7 +122,7 @@ protected function doGet($name, $immutable = TRUE) { } foreach ($this->configFactoryOverrides as $override) { - $config->addCacheableDependency($override->getCacheableMetadata($name)); + $config->addCacheableDependency($override->getCacheabilityMetadata($name)); } return $config; @@ -221,7 +221,7 @@ protected function loadOverrides(array $names) { */ protected function propagateConfigOverrideCacheability($cache_key, $name) { foreach ($this->configFactoryOverrides as $override) { - $this->cache[$cache_key]->addCacheableDependency($override->getCacheableMetadata($name)); + $this->cache[$cache_key]->addCacheableDependency($override->getCacheabilityMetadata($name)); } } diff --git a/core/lib/Drupal/Core/Config/ConfigFactoryOverrideInterface.php b/core/lib/Drupal/Core/Config/ConfigFactoryOverrideInterface.php index 13a78f8369..9fd9aebdad 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactoryOverrideInterface.php +++ b/core/lib/Drupal/Core/Config/ConfigFactoryOverrideInterface.php @@ -59,9 +59,9 @@ public function createConfigObject($name, $collection = StorageInterface::DEFAUL * @param string $name * The name of the configuration override to get metadata for. * - * @return \Drupal\Core\Cache\CacheableMetadata + * @return \Drupal\Core\Cache\CacheabilityMetadata * A cacheable metadata object. */ - public function getCacheableMetadata($name); + public function getCacheabilityMetadata($name); } diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php index 257fdf0fdb..4383409eb3 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Config\Entity; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\ConfigImporterException; @@ -211,7 +211,7 @@ protected function doLoadMultiple(array $ids = NULL) { // fine, B) it means fewer cache tags per page.). // 3. Fewer cache tags is better for performance. $self_referring_cache_tag = ['config:' . $configs[$id]->getName()]; - $config_cacheability = CacheableMetadata::createFromObject($configs[$id]); + $config_cacheability = CacheabilityMetadata::createFromObject($configs[$id]); $config_cacheability->setCacheTags(array_diff($config_cacheability->getCacheTags(), $self_referring_cache_tag)); $entity->addCacheableDependency($config_cacheability); } diff --git a/core/lib/Drupal/Core/EventSubscriber/AnonymousUserResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/AnonymousUserResponseSubscriber.php index 6d143b2fbd..47664b77d2 100644 --- a/core/lib/Drupal/Core/EventSubscriber/AnonymousUserResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/AnonymousUserResponseSubscriber.php @@ -2,7 +2,7 @@ namespace Drupal\Core\EventSubscriber; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\CacheableResponseInterface; use Drupal\Core\Session\AccountInterface; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; @@ -58,8 +58,8 @@ 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->getCacheableMetadata()->getCacheContexts())) { - $per_permissions_response_for_anon = new CacheableMetadata(); + if (in_array('user.permissions', $response->getCacheabilityMetadata()->getCacheContexts())) { + $per_permissions_response_for_anon = new CacheabilityMetadata(); $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/ClientErrorResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ClientErrorResponseSubscriber.php index f93fc63a26..e8d59f6944 100644 --- a/core/lib/Drupal/Core/EventSubscriber/ClientErrorResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/ClientErrorResponseSubscriber.php @@ -2,7 +2,7 @@ namespace Drupal\Core\EventSubscriber; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\CacheableResponseInterface; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; @@ -30,7 +30,7 @@ public function onRespond(FilterResponseEvent $event) { } if ($response->isClientError()) { - $http_4xx_response_cacheability = new CacheableMetadata(); + $http_4xx_response_cacheability = new CacheabilityMetadata(); $http_4xx_response_cacheability->setCacheTags(['4xx-response']); $response->addCacheableDependency($http_4xx_response_cacheability); } diff --git a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php index 747262c849..07ca3db4fb 100644 --- a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php @@ -99,7 +99,7 @@ public function onAllResponds(FilterResponseEvent $event) { // Always add the 'http_response' cache tag to be able to invalidate every // response, for example after rebuilding routes. if ($response instanceof CacheableResponseInterface) { - $response->getCacheableMetadata()->addCacheTags(['http_response']); + $response->getCacheabilityMetadata()->addCacheTags(['http_response']); } } @@ -153,7 +153,7 @@ public function onRespond(FilterResponseEvent $event) { if ($this->debugCacheabilityHeaders) { // Expose the cache contexts and cache tags associated with this page in a // X-Drupal-Cache-Contexts and X-Drupal-Cache-Tags header respectively. - $response_cacheability = $response->getCacheableMetadata(); + $response_cacheability = $response->getCacheabilityMetadata(); $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()))); } diff --git a/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php index f63ade66ac..3a6ff78cc8 100644 --- a/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php @@ -2,7 +2,7 @@ namespace Drupal\Core\EventSubscriber; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\CacheableResponseInterface; use Drupal\Core\DependencyInjection\ClassResolverInterface; use Drupal\Core\Routing\RouteMatchInterface; @@ -91,7 +91,7 @@ public function onViewRenderArray(GetResponseForControllerResultEvent $event) { // The main content render array is rendered into a different Response // object, depending on the specified wrapper format. if ($response instanceof CacheableResponseInterface) { - $main_content_view_subscriber_cacheability = (new CacheableMetadata())->setCacheContexts(['url.query_args:' . static::WRAPPER_FORMAT]); + $main_content_view_subscriber_cacheability = (new CacheabilityMetadata())->setCacheContexts(['url.query_args:' . static::WRAPPER_FORMAT]); $response->addCacheableDependency($main_content_view_subscriber_cacheability); } $event->setResponse($response); diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php index d2a691f077..96dab40629 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Field\Plugin\Field\FieldFormatter; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Field\EntityReferenceFieldItemListInterface; use Drupal\Core\Field\FieldItemListInterface; @@ -54,7 +54,7 @@ protected function getEntitiesToView(EntityReferenceFieldItemListInterface $item $access = $this->checkAccess($entity); // Add the access result's cacheability, ::view() needs it. - $item->_accessCacheability = CacheableMetadata::createFromObject($access); + $item->_accessCacheability = CacheabilityMetadata::createFromObject($access); if ($access->isAllowed()) { // Add the referring item, in case the formatter needs it. $entity->_referringItem = $items[$delta]; @@ -75,7 +75,7 @@ protected function getEntitiesToView(EntityReferenceFieldItemListInterface $item public function view(FieldItemListInterface $items, $langcode = NULL) { $elements = parent::view($items, $langcode); - $field_level_access_cacheability = new CacheableMetadata(); + $field_level_access_cacheability = new CacheabilityMetadata(); // Try to map the cacheability of the access result that was set at // _accessCacheability in getEntitiesToView() to the corresponding render @@ -86,7 +86,7 @@ public function view(FieldItemListInterface $items, $langcode = NULL) { // prepareView(). if (!empty($item->_accessCacheability)) { if (isset($elements[$delta])) { - CacheableMetadata::createFromRenderArray($elements[$delta]) + CacheabilityMetadata::createFromRenderArray($elements[$delta]) ->merge($item->_accessCacheability) ->applyTo($elements[$delta]); } @@ -104,7 +104,7 @@ public function view(FieldItemListInterface $items, $langcode = NULL) { // tags on which the access results depend, to ensure users that cannot view // this field at the moment will gain access once any of those cache tags // are invalidated. - $field_level_access_cacheability->merge(CacheableMetadata::createFromRenderArray($elements)) + $field_level_access_cacheability->merge(CacheabilityMetadata::createFromRenderArray($elements)) ->applyTo($elements); return $elements; diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php index e4c3d9171e..e5dfaa2460 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php @@ -3,7 +3,7 @@ namespace Drupal\Core\Field\Plugin\Field\FieldFormatter; use Drupal\Component\Render\FormattableMarkup; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Datetime\DateFormatterInterface; use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Field\FieldDefinitionInterface; @@ -206,7 +206,7 @@ protected function formatTimestamp($timestamp) { '#markup' => new FormattableMarkup($this->getSetting('future_format'), ['@interval' => $result->getString()]), ]; } - CacheableMetadata::createFromObject($result)->applyTo($build); + CacheabilityMetadata::createFromObject($result)->applyTo($build); return $build; } diff --git a/core/lib/Drupal/Core/Installer/ConfigOverride.php b/core/lib/Drupal/Core/Installer/ConfigOverride.php index ff8d068b2f..8878df8057 100644 --- a/core/lib/Drupal/Core/Installer/ConfigOverride.php +++ b/core/lib/Drupal/Core/Installer/ConfigOverride.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Installer; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Config\ConfigFactoryOverrideInterface; use Drupal\Core\Config\StorageInterface; use Drupal\Core\DependencyInjection\ContainerBuilder; @@ -55,8 +55,8 @@ public function createConfigObject($name, $collection = StorageInterface::DEFAUL /** * {@inheritdoc} */ - public function getCacheableMetadata($name) { - return new CacheableMetadata(); + public function getCacheabilityMetadata($name) { + return new CacheabilityMetadata(); } } diff --git a/core/lib/Drupal/Core/Language/ContextProvider/CurrentLanguageContext.php b/core/lib/Drupal/Core/Language/ContextProvider/CurrentLanguageContext.php index 38250339ce..02748c48cf 100644 --- a/core/lib/Drupal/Core/Language/ContextProvider/CurrentLanguageContext.php +++ b/core/lib/Drupal/Core/Language/ContextProvider/CurrentLanguageContext.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Language\ContextProvider; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Plugin\Context\Context; use Drupal\Core\Plugin\Context\ContextDefinition; @@ -54,7 +54,7 @@ public function getRuntimeContexts(array $unqualified_context_ids) { if (isset($info[$type_key]['name'])) { $context = new Context(new ContextDefinition('language', $info[$type_key]['name']), $this->languageManager->getCurrentLanguage($type_key)); - $cacheability = new CacheableMetadata(); + $cacheability = new CacheabilityMetadata(); $cacheability->setCacheContexts(['languages:' . $type_key]); $context->addCacheableDependency($cacheability); diff --git a/core/lib/Drupal/Core/Menu/LocalActionManager.php b/core/lib/Drupal/Core/Menu/LocalActionManager.php index a95f445dad..27c828b9d6 100644 --- a/core/lib/Drupal/Core/Menu/LocalActionManager.php +++ b/core/lib/Drupal/Core/Menu/LocalActionManager.php @@ -3,7 +3,7 @@ namespace Drupal\Core\Menu; use Drupal\Core\Access\AccessManagerInterface; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Controller\ControllerResolverInterface; use Drupal\Core\Extension\ModuleHandlerInterface; @@ -196,7 +196,7 @@ public function getActionsForRoute($route_appears) { } } $links = []; - $cacheability = new CacheableMetadata(); + $cacheability = new CacheabilityMetadata(); $cacheability->addCacheContexts(['route']); /** @var $plugin \Drupal\Core\Menu\LocalActionInterface */ foreach ($this->instances[$route_appears] as $plugin_id => $plugin) { diff --git a/core/lib/Drupal/Core/Menu/LocalTaskManager.php b/core/lib/Drupal/Core/Menu/LocalTaskManager.php index d20bef0054..402fd722c0 100644 --- a/core/lib/Drupal/Core/Menu/LocalTaskManager.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskManager.php @@ -5,7 +5,7 @@ use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Cache\RefinableCacheableDependencyInterface; use Drupal\Core\Controller\ControllerResolverInterface; @@ -364,7 +364,7 @@ public function getTasksBuild($current_route_name, RefinableCacheableDependencyI */ public function getLocalTasks($route_name, $level = 0) { if (!isset($this->taskData[$route_name])) { - $cacheability = new CacheableMetadata(); + $cacheability = new CacheabilityMetadata(); $cacheability->addCacheContexts(['route']); // Look for route-based tabs. $this->taskData[$route_name] = [ diff --git a/core/lib/Drupal/Core/Menu/MenuLinkTree.php b/core/lib/Drupal/Core/Menu/MenuLinkTree.php index 8a6dce8ffc..5aee608434 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkTree.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkTree.php @@ -4,7 +4,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Access\AccessResultInterface; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Controller\ControllerResolverInterface; use Drupal\Core\Routing\RouteProviderInterface; use Drupal\Core\Template\Attribute; @@ -155,8 +155,8 @@ public function transform(array $tree, array $manipulators) { * {@inheritdoc} */ public function build(array $tree) { - $tree_access_cacheability = new CacheableMetadata(); - $tree_link_cacheability = new CacheableMetadata(); + $tree_access_cacheability = new CacheabilityMetadata(); + $tree_link_cacheability = new CacheabilityMetadata(); $items = $this->buildItems($tree, $tree_access_cacheability, $tree_link_cacheability); $build = []; @@ -196,10 +196,10 @@ public function build(array $tree) { * @param \Drupal\Core\Menu\MenuLinkTreeElement[] $tree * A data structure representing the tree, as returned from * MenuLinkTreeInterface::load(). - * @param \Drupal\Core\Cache\CacheableMetadata &$tree_access_cacheability + * @param \Drupal\Core\Cache\CacheabilityMetadata &$tree_access_cacheability * Internal use only. The aggregated cacheability metadata for the access * results across the entire tree. Used when rendering the root level. - * @param \Drupal\Core\Cache\CacheableMetadata &$tree_link_cacheability + * @param \Drupal\Core\Cache\CacheabilityMetadata &$tree_link_cacheability * Internal use only. The aggregated cacheability metadata for the menu * links across the entire tree. Used when rendering the root level. * @@ -208,7 +208,7 @@ public function build(array $tree) { * * @throws \DomainException */ - protected function buildItems(array $tree, CacheableMetadata &$tree_access_cacheability, CacheableMetadata &$tree_link_cacheability) { + protected function buildItems(array $tree, CacheabilityMetadata &$tree_access_cacheability, CacheabilityMetadata &$tree_link_cacheability) { $items = []; foreach ($tree as $data) { @@ -231,14 +231,14 @@ protected function buildItems(array $tree, CacheableMetadata &$tree_access_cache // will still render the menu link, because this method does not want to // require access checking to be able to render a menu tree. if ($data->access instanceof AccessResultInterface) { - $tree_access_cacheability = $tree_access_cacheability->merge(CacheableMetadata::createFromObject($data->access)); + $tree_access_cacheability = $tree_access_cacheability->merge(CacheabilityMetadata::createFromObject($data->access)); } // Gather the cacheability of every item in the menu link tree. Some links // may be dynamic: they may have a dynamic text (e.g. a "Hi, " link // text, which would vary by 'user' cache context), or a dynamic route // name or route parameters. - $tree_link_cacheability = $tree_link_cacheability->merge(CacheableMetadata::createFromObject($data->link)); + $tree_link_cacheability = $tree_link_cacheability->merge(CacheabilityMetadata::createFromObject($data->link)); // Only render accessible links. if ($data->access instanceof AccessResultInterface && !$data->access->isAllowed()) { diff --git a/core/lib/Drupal/Core/Menu/MenuParentFormSelector.php b/core/lib/Drupal/Core/Menu/MenuParentFormSelector.php index 694897a779..96ee84b147 100644 --- a/core/lib/Drupal/Core/Menu/MenuParentFormSelector.php +++ b/core/lib/Drupal/Core/Menu/MenuParentFormSelector.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Menu; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Component\Utility\Unicode; use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait; use Drupal\Core\Entity\EntityManagerInterface; @@ -63,7 +63,7 @@ public function __construct(MenuLinkTreeInterface $menu_link_tree, EntityTypeMan /** * {@inheritdoc} */ - public function getParentSelectOptions($id = '', array $menus = NULL, CacheableMetadata &$cacheability = NULL) { + public function getParentSelectOptions($id = '', array $menus = NULL, CacheabilityMetadata &$cacheability = NULL) { if (!isset($menus)) { $menus = $this->getMenuOptions(); } @@ -91,7 +91,7 @@ public function getParentSelectOptions($id = '', array $menus = NULL, CacheableM * {@inheritdoc} */ public function parentSelectElement($menu_parent, $id = '', array $menus = NULL) { - $options_cacheability = new CacheableMetadata(); + $options_cacheability = new CacheabilityMetadata(); $options = $this->getParentSelectOptions($id, $menus, $options_cacheability); // If no options were found, there is nothing to select. if ($options) { @@ -149,10 +149,10 @@ protected function getParentDepthLimit($id) { * An excluded menu link. * @param int $depth_limit * The maximum depth of menu links considered for the select options. - * @param \Drupal\Core\Cache\CacheableMetadata|null &$cacheability + * @param \Drupal\Core\Cache\CacheabilityMetadata|null &$cacheability * The object to add cacheability metadata to, if not NULL. */ - protected function parentSelectOptionsTreeWalk(array $tree, $menu_name, $indent, array &$options, $exclude, $depth_limit, CacheableMetadata &$cacheability = NULL) { + protected function parentSelectOptionsTreeWalk(array $tree, $menu_name, $indent, array &$options, $exclude, $depth_limit, CacheabilityMetadata &$cacheability = NULL) { foreach ($tree as $element) { if ($element->depth > $depth_limit) { // Don't iterate through any links on this level. @@ -163,8 +163,8 @@ protected function parentSelectOptionsTreeWalk(array $tree, $menu_name, $indent, // link. if ($cacheability) { $cacheability = $cacheability - ->merge(CacheableMetadata::createFromObject($element->access)) - ->merge(CacheableMetadata::createFromObject($element->link)); + ->merge(CacheabilityMetadata::createFromObject($element->access)) + ->merge(CacheabilityMetadata::createFromObject($element->link)); } // Only show accessible links. diff --git a/core/lib/Drupal/Core/Menu/MenuParentFormSelectorInterface.php b/core/lib/Drupal/Core/Menu/MenuParentFormSelectorInterface.php index 1e1ec5bb52..31c95584fd 100644 --- a/core/lib/Drupal/Core/Menu/MenuParentFormSelectorInterface.php +++ b/core/lib/Drupal/Core/Menu/MenuParentFormSelectorInterface.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Menu; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; /** * Defines an interface for menu selector form elements and menu link options. @@ -18,7 +18,7 @@ * @param array $menus * Optional array of menu names as keys and titles as values to limit * the select options. If NULL, all menus will be included. - * @param \Drupal\Core\Cache\CacheableMetadata|null &$cacheability + * @param \Drupal\Core\Cache\CacheabilityMetadata|null &$cacheability * Optional cacheability metadata object, which will be populated based on * the accessibility of the links and the cacheability of the links. * @@ -26,7 +26,7 @@ * Keyed array where the keys are contain a menu name and parent ID and * the values are a menu name or link title indented by depth. */ - public function getParentSelectOptions($id = '', array $menus = NULL, CacheableMetadata &$cacheability = NULL); + public function getParentSelectOptions($id = '', array $menus = NULL, CacheabilityMetadata &$cacheability = NULL); /** * Gets a form element to choose a menu and parent. diff --git a/core/lib/Drupal/Core/Menu/Plugin/Block/LocalTasksBlock.php b/core/lib/Drupal/Core/Menu/Plugin/Block/LocalTasksBlock.php index 6a518ef3ef..077f99b2f1 100644 --- a/core/lib/Drupal/Core/Menu/Plugin/Block/LocalTasksBlock.php +++ b/core/lib/Drupal/Core/Menu/Plugin/Block/LocalTasksBlock.php @@ -3,7 +3,7 @@ namespace Drupal\Core\Menu\Plugin\Block; use Drupal\Core\Block\BlockBase; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Menu\LocalTaskManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -84,7 +84,7 @@ public function defaultConfiguration() { */ public function build() { $config = $this->configuration; - $cacheability = new CacheableMetadata(); + $cacheability = new CacheabilityMetadata(); $cacheability->addCacheableDependency($this->localTaskManager); $tabs = [ '#theme' => 'menu_local_tasks', diff --git a/core/lib/Drupal/Core/Plugin/Context/Context.php b/core/lib/Drupal/Core/Plugin/Context/Context.php index ac541c430f..c0ac828fdc 100644 --- a/core/lib/Drupal/Core/Plugin/Context/Context.php +++ b/core/lib/Drupal/Core/Plugin/Context/Context.php @@ -5,7 +5,7 @@ use Drupal\Component\Plugin\Context\Context as ComponentContext; use Drupal\Component\Plugin\Exception\ContextException; use Drupal\Core\Cache\CacheableDependencyInterface; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\DependencyInjection\DependencySerializationTrait; use Drupal\Core\TypedData\TypedDataInterface; use Drupal\Core\TypedData\TypedDataTrait; @@ -35,7 +35,7 @@ class Context extends ComponentContext implements ContextInterface { /** * The cacheability metadata. * - * @var \Drupal\Core\Cache\CacheableMetadata + * @var \Drupal\Core\Cache\CacheabilityMetadata */ protected $cacheabilityMetadata; @@ -49,7 +49,7 @@ class Context extends ComponentContext implements ContextInterface { */ public function __construct(ContextDefinitionInterface $context_definition, $context_value = NULL) { parent::__construct($context_definition, NULL); - $this->cacheabilityMetadata = new CacheableMetadata(); + $this->cacheabilityMetadata = new CacheabilityMetadata(); if (!is_null($context_value)) { $this->setContextValue($context_value); } @@ -143,7 +143,7 @@ public function validate() { * {@inheritdoc} */ public function addCacheableDependency($dependency) { - $this->cacheabilityMetadata = $this->cacheabilityMetadata->merge(CacheableMetadata::createFromObject($dependency)); + $this->cacheabilityMetadata = $this->cacheabilityMetadata->merge(CacheabilityMetadata::createFromObject($dependency)); return $this; } diff --git a/core/lib/Drupal/Core/Plugin/Context/ContextInterface.php b/core/lib/Drupal/Core/Plugin/Context/ContextInterface.php index 260cb2c33d..48248a11c2 100644 --- a/core/lib/Drupal/Core/Plugin/Context/ContextInterface.php +++ b/core/lib/Drupal/Core/Plugin/Context/ContextInterface.php @@ -41,7 +41,7 @@ public function getContextData(); * * @return $this * - * @see \Drupal\Core\Cache\CacheableMetadata::createFromObject() + * @see \Drupal\Core\Cache\CacheabilityMetadata::createFromObject() */ public function addCacheableDependency($dependency); diff --git a/core/lib/Drupal/Core/Render/BubbleableMetadata.php b/core/lib/Drupal/Core/Render/BubbleableMetadata.php index 33aa755ea8..d8fb8b31bc 100644 --- a/core/lib/Drupal/Core/Render/BubbleableMetadata.php +++ b/core/lib/Drupal/Core/Render/BubbleableMetadata.php @@ -3,27 +3,27 @@ namespace Drupal\Core\Render; use Drupal\Component\Utility\NestedArray; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; /** * Value object used for bubbleable rendering metadata. * * @see \Drupal\Core\Render\RendererInterface::render() */ -class BubbleableMetadata extends CacheableMetadata implements AttachmentsInterface { +class BubbleableMetadata extends CacheabilityMetadata implements AttachmentsInterface { use AttachmentsTrait; /** * Merges the values of another bubbleable metadata object with this one. * - * @param \Drupal\Core\Cache\CacheableMetadata $other + * @param \Drupal\Core\Cache\CacheabilityMetadata $other * The other bubbleable metadata object. * * @return static * A new bubbleable metadata object, with the merged data. */ - public function merge(CacheableMetadata $other) { + public function merge(CacheabilityMetadata $other) { $result = parent::merge($other); // This is called many times per request, so avoid merging unless absolutely diff --git a/core/lib/Drupal/Core/Render/HtmlResponse.php b/core/lib/Drupal/Core/Render/HtmlResponse.php index 763696d109..c55240bef2 100644 --- a/core/lib/Drupal/Core/Render/HtmlResponse.php +++ b/core/lib/Drupal/Core/Render/HtmlResponse.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Render; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\CacheableResponseInterface; use Drupal\Core\Cache\CacheableResponseTrait; use Symfony\Component\HttpFoundation\Response; @@ -37,7 +37,7 @@ public function setContent($content) { 'placeholders' => [], ], ]; - $this->addCacheableDependency(CacheableMetadata::createFromRenderArray($content)); + $this->addCacheableDependency(CacheabilityMetadata::createFromRenderArray($content)); $this->setAttachments($content['#attached']); $content = $content['#markup']; } diff --git a/core/lib/Drupal/Core/Render/RenderCache.php b/core/lib/Drupal/Core/Render/RenderCache.php index 20e4b0c142..63eab37120 100644 --- a/core/lib/Drupal/Core/Render/RenderCache.php +++ b/core/lib/Drupal/Core/Render/RenderCache.php @@ -3,7 +3,7 @@ namespace Drupal\Core\Render; use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\Context\CacheContextsManager; use Drupal\Core\Cache\CacheFactoryInterface; use Symfony\Component\HttpFoundation\RequestStack; @@ -209,9 +209,9 @@ public function set(array &$elements, array $pre_bubbling_elements) { // Get the cacheability of this element according to the current (stored) // redirecting cache item, if any. - $redirect_cacheability = new CacheableMetadata(); + $redirect_cacheability = new CacheabilityMetadata(); if ($stored_cache_redirect = $cache->get($pre_bubbling_cid)) { - $redirect_cacheability = CacheableMetadata::createFromRenderArray($stored_cache_redirect->data); + $redirect_cacheability = CacheabilityMetadata::createFromRenderArray($stored_cache_redirect->data); } // Calculate the union of the cacheability for this request and the @@ -224,7 +224,7 @@ public function set(array &$elements, array $pre_bubbling_elements) { // redirect cache item itself becomes stale. (Without this, we might end // up toggling between a permanently and a briefly cacheable cache // redirect, because the last update's max-age would always "win".) - $redirect_cacheability_updated = CacheableMetadata::createFromRenderArray($data)->merge($redirect_cacheability); + $redirect_cacheability_updated = CacheabilityMetadata::createFromRenderArray($data)->merge($redirect_cacheability); // Stored cache contexts incomplete: this request causes cache contexts to // be added to the redirecting cache item. @@ -306,7 +306,7 @@ protected function createCacheID(array &$elements) { if (!empty($elements['#cache']['contexts'])) { $context_cache_keys = $this->cacheContextsManager->convertTokensToKeys($elements['#cache']['contexts']); $cid_parts = array_merge($cid_parts, $context_cache_keys->getKeys()); - CacheableMetadata::createFromRenderArray($elements) + CacheabilityMetadata::createFromRenderArray($elements) ->merge($context_cache_keys) ->applyTo($elements); } diff --git a/core/lib/Drupal/Core/Render/Renderer.php b/core/lib/Drupal/Core/Render/Renderer.php index 1c36184430..f330c13fcc 100644 --- a/core/lib/Drupal/Core/Render/Renderer.php +++ b/core/lib/Drupal/Core/Render/Renderer.php @@ -7,7 +7,7 @@ use Drupal\Component\Utility\Xss; use Drupal\Core\Access\AccessResultInterface; use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Controller\ControllerResolverInterface; use Drupal\Core\Theme\ThemeManagerInterface; use Symfony\Component\HttpFoundation\RequestStack; @@ -357,8 +357,8 @@ protected function doRender(&$elements, $is_root_call = FALSE) { } $new_elements = call_user_func_array($callable, $args); // Retain the original cacheability metadata, plus cache keys. - CacheableMetadata::createFromRenderArray($elements) - ->merge(CacheableMetadata::createFromRenderArray($new_elements)) + CacheabilityMetadata::createFromRenderArray($elements) + ->merge(CacheabilityMetadata::createFromRenderArray($new_elements)) ->applyTo($new_elements); if (isset($elements['#cache']['keys'])) { $new_elements['#cache']['keys'] = $elements['#cache']['keys']; @@ -690,8 +690,8 @@ public function mergeBubbleableMetadata(array $a, array $b) { * {@inheritdoc} */ public function addCacheableDependency(array &$elements, $dependency) { - $meta_a = CacheableMetadata::createFromRenderArray($elements); - $meta_b = CacheableMetadata::createFromObject($dependency); + $meta_a = CacheabilityMetadata::createFromRenderArray($elements); + $meta_b = CacheabilityMetadata::createFromObject($dependency); $meta_a->merge($meta_b)->applyTo($elements); } diff --git a/core/lib/Drupal/Core/Render/RendererInterface.php b/core/lib/Drupal/Core/Render/RendererInterface.php index 5f8802d4c6..6ccc1cad40 100644 --- a/core/lib/Drupal/Core/Render/RendererInterface.php +++ b/core/lib/Drupal/Core/Render/RendererInterface.php @@ -407,7 +407,7 @@ public function mergeBubbleableMetadata(array $a, array $b); * then its cacheability metadata will be used. Otherwise, the passed in * object must be assumed to be uncacheable, so max-age 0 is set. * - * @see \Drupal\Core\Cache\CacheableMetadata::createFromObject() + * @see \Drupal\Core\Cache\CacheabilityMetadata::createFromObject() */ public function addCacheableDependency(array &$elements, $dependency); diff --git a/core/lib/Drupal/Core/Routing/CacheableSecuredRedirectResponse.php b/core/lib/Drupal/Core/Routing/CacheableSecuredRedirectResponse.php index b5078330b4..d60ed17879 100644 --- a/core/lib/Drupal/Core/Routing/CacheableSecuredRedirectResponse.php +++ b/core/lib/Drupal/Core/Routing/CacheableSecuredRedirectResponse.php @@ -20,9 +20,9 @@ protected function fromResponse(RedirectResponse $response) { parent::fromResponse($response); - $metadata = $this->getCacheableMetadata(); + $metadata = $this->getCacheabilityMetadata(); if ($response instanceof CacheableResponseInterface) { - $metadata->addCacheableDependency($response->getCacheableMetadata()); + $metadata->addCacheableDependency($response->getCacheabilityMetadata()); } else { $metadata->setCacheMaxAge(0); diff --git a/core/modules/basic_auth/src/Authentication/Provider/BasicAuth.php b/core/modules/basic_auth/src/Authentication/Provider/BasicAuth.php index 8e50c13de9..0ef1c11451 100644 --- a/core/modules/basic_auth/src/Authentication/Provider/BasicAuth.php +++ b/core/modules/basic_auth/src/Authentication/Provider/BasicAuth.php @@ -5,7 +5,7 @@ use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Authentication\AuthenticationProviderInterface; use Drupal\Core\Authentication\AuthenticationProviderChallengeInterface; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait; use Drupal\Core\Entity\EntityTypeManagerInterface; @@ -160,7 +160,7 @@ public function challengeException(Request $request, \Exception $previous) { // @see \Drupal\Core\EventSubscriber\AuthenticationSubscriber::onExceptionSendChallenge() // @see \Drupal\Core\EventSubscriber\ClientErrorResponseSubscriber() // @see \Drupal\Core\EventSubscriber\FinishResponseSubscriber::onAllResponds() - $cacheability = CacheableMetadata::createFromObject($site_config) + $cacheability = CacheabilityMetadata::createFromObject($site_config) ->addCacheTags(['config:user.role.anonymous']) ->addCacheContexts(['user.roles:anonymous']); return $request->isMethodCacheable() diff --git a/core/modules/big_pipe/src/Controller/BigPipeController.php b/core/modules/big_pipe/src/Controller/BigPipeController.php index da95f6d9dc..993ac9184d 100644 --- a/core/modules/big_pipe/src/Controller/BigPipeController.php +++ b/core/modules/big_pipe/src/Controller/BigPipeController.php @@ -3,7 +3,7 @@ namespace Drupal\big_pipe\Controller; use Drupal\big_pipe\Render\Placeholder\BigPipeStrategy; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Routing\LocalRedirectResponse; use Symfony\Component\HttpFoundation\Cookie; use Symfony\Component\HttpFoundation\Request; @@ -53,7 +53,7 @@ public function setNoJsCookie(Request $request) { $response = new LocalRedirectResponse($request->query->get('destination')); // Set cookie without httpOnly, so that JavaScript can delete it. $response->headers->setCookie(new Cookie(BigPipeStrategy::NOJS_COOKIE, TRUE, 0, '/', NULL, FALSE, FALSE, FALSE, NULL)); - $response->addCacheableDependency((new CacheableMetadata())->addCacheContexts(['cookies:' . BigPipeStrategy::NOJS_COOKIE, 'session.exists'])); + $response->addCacheableDependency((new CacheabilityMetadata())->addCacheContexts(['cookies:' . BigPipeStrategy::NOJS_COOKIE, 'session.exists'])); return $response; } diff --git a/core/modules/big_pipe/src/Render/BigPipe.php b/core/modules/big_pipe/src/Render/BigPipe.php index 7397cd53c2..f80b7a7f4a 100644 --- a/core/modules/big_pipe/src/Render/BigPipe.php +++ b/core/modules/big_pipe/src/Render/BigPipe.php @@ -355,7 +355,7 @@ protected function sendPreBody($pre_body, array $no_js_placeholders, AttachedAss ], ], ]); - $html_response->getCacheableMetadata()->setCacheMaxAge(0); + $html_response->getCacheabilityMetadata()->setCacheMaxAge(0); // Push a fake request with the asset libraries loaded so far and dispatch // KernelEvents::RESPONSE event. This results in the attachments for the @@ -456,7 +456,7 @@ protected function sendNoJsPlaceholders($html, $no_js_placeholders, AttachedAsse $html_response = new HtmlResponse(); $html_response->setContent($elements); - $html_response->getCacheableMetadata()->setCacheMaxAge(0); + $html_response->getCacheabilityMetadata()->setCacheMaxAge(0); // Push a fake request with the asset libraries loaded so far and dispatch // KernelEvents::RESPONSE event. This results in the attachments for the diff --git a/core/modules/big_pipe/src/Render/BigPipeResponse.php b/core/modules/big_pipe/src/Render/BigPipeResponse.php index 70b637d34d..28d54363cc 100644 --- a/core/modules/big_pipe/src/Render/BigPipeResponse.php +++ b/core/modules/big_pipe/src/Render/BigPipeResponse.php @@ -74,7 +74,7 @@ protected function populateBasedOnOriginalHtmlResponse() { ->setStatusCode($this->originalHtmlResponse->getStatusCode()) ->setContent($this->originalHtmlResponse->getContent()) ->setAttachments($this->originalHtmlResponse->getAttachments()) - ->addCacheableDependency($this->originalHtmlResponse->getCacheableMetadata()); + ->addCacheableDependency($this->originalHtmlResponse->getCacheabilityMetadata()); // A BigPipe response can never be cached, because it is intended for a // single user. diff --git a/core/modules/block/src/BlockRepository.php b/core/modules/block/src/BlockRepository.php index 2f27df3d19..1c8c04bcf7 100644 --- a/core/modules/block/src/BlockRepository.php +++ b/core/modules/block/src/BlockRepository.php @@ -2,7 +2,7 @@ namespace Drupal\block; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Plugin\Context\ContextHandlerInterface; use Drupal\Core\Theme\ThemeManagerInterface; @@ -45,7 +45,7 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, The /** * {@inheritdoc} */ - public function getVisibleBlocksPerRegion(array &$cacheable_metadata = []) { + public function getVisibleBlocksPerRegion(array &$cacheability_metadata = []) { $active_theme = $this->themeManager->getActiveTheme(); // Build an array of the region names in the right order. $empty = array_fill_keys($active_theme->getRegions(), []); @@ -55,11 +55,11 @@ public function getVisibleBlocksPerRegion(array &$cacheable_metadata = []) { /** @var \Drupal\block\BlockInterface $block */ $access = $block->access('view', NULL, TRUE); $region = $block->getRegion(); - if (!isset($cacheable_metadata[$region])) { - $cacheable_metadata[$region] = CacheableMetadata::createFromObject($access); + if (!isset($cacheability_metadata[$region])) { + $cacheability_metadata[$region] = CacheabilityMetadata::createFromObject($access); } else { - $cacheable_metadata[$region] = $cacheable_metadata[$region]->merge(CacheableMetadata::createFromObject($access)); + $cacheability_metadata[$region] = $cacheability_metadata[$region]->merge(CacheabilityMetadata::createFromObject($access)); } // Set the contexts on the block before checking access. diff --git a/core/modules/block/src/BlockRepositoryInterface.php b/core/modules/block/src/BlockRepositoryInterface.php index 9c4f871a7e..1fd600ee5f 100644 --- a/core/modules/block/src/BlockRepositoryInterface.php +++ b/core/modules/block/src/BlockRepositoryInterface.php @@ -21,14 +21,14 @@ /** * Returns an array of regions and their block entities. * - * @param \Drupal\Core\Cache\CacheableMetadata[] $cacheable_metadata - * (optional) List of CacheableMetadata objects, keyed by region. This is + * @param \Drupal\Core\Cache\CacheabilityMetadata[] $cacheability_metadata + * (optional) List of CacheabilityMetadata objects, keyed by region. This is * by reference and is used to pass this information back to the caller. * * @return array * The array is first keyed by region machine name, with the values * containing an array keyed by block ID, with block entities as the values. */ - public function getVisibleBlocksPerRegion(array &$cacheable_metadata = []); + public function getVisibleBlocksPerRegion(array &$cacheability_metadata = []); } diff --git a/core/modules/block/src/BlockViewBuilder.php b/core/modules/block/src/BlockViewBuilder.php index 72f3b1e516..79a76b8eee 100644 --- a/core/modules/block/src/BlockViewBuilder.php +++ b/core/modules/block/src/BlockViewBuilder.php @@ -5,7 +5,7 @@ use Drupal\Core\Block\MainContentBlockPluginInterface; use Drupal\Core\Block\TitleBlockPluginInterface; use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Entity\EntityViewBuilder; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Extension\ModuleHandlerInterface; @@ -200,8 +200,8 @@ public static function preRender($build) { // blocks to be empty, yet still bubble cacheability metadata, to indicate // why they are empty. if (!empty($content)) { - CacheableMetadata::createFromRenderArray($build) - ->merge(CacheableMetadata::createFromRenderArray($content)) + CacheabilityMetadata::createFromRenderArray($build) + ->merge(CacheabilityMetadata::createFromRenderArray($content)) ->applyTo($build); } } diff --git a/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php b/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php index e95ccd2c7b..d813b909e6 100644 --- a/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php +++ b/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php @@ -6,7 +6,7 @@ use Drupal\Core\Block\MainContentBlockPluginInterface; use Drupal\Core\Block\TitleBlockPluginInterface; use Drupal\Core\Block\MessagesBlockPluginInterface; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Display\PageVariantInterface; use Drupal\Core\Entity\EntityViewBuilderInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -133,8 +133,8 @@ public function build() { ], ]; // Load all region content assigned via blocks. - $cacheable_metadata_list = []; - foreach ($this->blockRepository->getVisibleBlocksPerRegion($cacheable_metadata_list) as $region => $blocks) { + $cacheability_metadata_list = []; + foreach ($this->blockRepository->getVisibleBlocksPerRegion($cacheability_metadata_list) as $region => $blocks) { /** @var $blocks \Drupal\block\BlockInterface[] */ foreach ($blocks as $key => $block) { $block_plugin = $block->getPlugin(); @@ -192,11 +192,11 @@ public function build() { // displayed. // This would need to be changed to allow caching of block regions, as each // region must then have the relevant cacheable metadata. - $merged_cacheable_metadata = CacheableMetadata::createFromRenderArray($build); - foreach ($cacheable_metadata_list as $cacheable_metadata) { - $merged_cacheable_metadata = $merged_cacheable_metadata->merge($cacheable_metadata); + $merged_cacheability_metadata = CacheabilityMetadata::createFromRenderArray($build); + foreach ($cacheability_metadata_list as $cacheability_metadata) { + $merged_cacheability_metadata = $merged_cacheability_metadata->merge($cacheability_metadata); } - $merged_cacheable_metadata->applyTo($build); + $merged_cacheability_metadata->applyTo($build); return $build; } diff --git a/core/modules/block/tests/modules/block_test/src/ContextProvider/MultipleStaticContext.php b/core/modules/block/tests/modules/block_test/src/ContextProvider/MultipleStaticContext.php index 3eda464205..0f0162470a 100644 --- a/core/modules/block/tests/modules/block_test/src/ContextProvider/MultipleStaticContext.php +++ b/core/modules/block/tests/modules/block_test/src/ContextProvider/MultipleStaticContext.php @@ -2,7 +2,7 @@ namespace Drupal\block_test\ContextProvider; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Plugin\Context\ContextProviderInterface; use Drupal\Core\Plugin\Context\EntityContext; @@ -49,7 +49,7 @@ public function getRuntimeContexts(array $unqualified_context_ids) { $context1 = EntityContext::fromEntity($current_user, 'User A'); $context2 = EntityContext::fromEntity($current_user, 'User B'); - $cacheability = new CacheableMetadata(); + $cacheability = new CacheabilityMetadata(); $cacheability->setCacheContexts(['user']); $context1->addCacheableDependency($cacheability); diff --git a/core/modules/block/tests/src/Functional/Rest/BlockResourceTestBase.php b/core/modules/block/tests/src/Functional/Rest/BlockResourceTestBase.php index a6af25805e..cd4c0def85 100644 --- a/core/modules/block/tests/src/Functional/Rest/BlockResourceTestBase.php +++ b/core/modules/block/tests/src/Functional/Rest/BlockResourceTestBase.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\block\Functional\Rest; use Drupal\block\Entity\Block; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase; abstract class BlockResourceTestBase extends EntityResourceTestBase { @@ -148,7 +148,7 @@ protected function getExpectedUnauthorizedAccessMessage($method) { * @todo Fix this in https://www.drupal.org/node/2820315. */ protected function getExpectedUnauthorizedAccessCacheability() { - return (new CacheableMetadata()) + return (new CacheabilityMetadata()) ->setCacheTags(['4xx-response', 'http_response']) ->setCacheContexts(['user.roles']); } diff --git a/core/modules/block/tests/src/Unit/BlockRepositoryTest.php b/core/modules/block/tests/src/Unit/BlockRepositoryTest.php index f22694140a..71afdd3c78 100644 --- a/core/modules/block/tests/src/Unit/BlockRepositoryTest.php +++ b/core/modules/block/tests/src/Unit/BlockRepositoryTest.php @@ -107,8 +107,8 @@ public function testGetVisibleBlocksPerRegion(array $blocks_config, array $expec ->with(['theme' => $this->theme]) ->willReturn($blocks); $result = []; - $cacheable_metadata = []; - foreach ($this->blockRepository->getVisibleBlocksPerRegion($cacheable_metadata) as $region => $resulting_blocks) { + $cacheability_metadata = []; + foreach ($this->blockRepository->getVisibleBlocksPerRegion($cacheability_metadata) as $region => $resulting_blocks) { $result[$region] = []; foreach ($resulting_blocks as $plugin_id => $block) { $result[$region][] = $plugin_id; @@ -169,8 +169,8 @@ public function testGetVisibleBlocksPerRegionWithContext() { ->with(['theme' => $this->theme]) ->willReturn($blocks); $result = []; - $cacheable_metadata = []; - foreach ($this->blockRepository->getVisibleBlocksPerRegion($cacheable_metadata) as $region => $resulting_blocks) { + $cacheability_metadata = []; + foreach ($this->blockRepository->getVisibleBlocksPerRegion($cacheability_metadata) as $region => $resulting_blocks) { $result[$region] = []; foreach ($resulting_blocks as $plugin_id => $block) { $result[$region][] = $plugin_id; @@ -187,7 +187,7 @@ public function testGetVisibleBlocksPerRegionWithContext() { // Assert that the cacheable metadata from the block access results was // collected. - $this->assertEquals(['config:block.block.block_id'], $cacheable_metadata['top']->getCacheTags()); + $this->assertEquals(['config:block.block.block_id'], $cacheability_metadata['top']->getCacheTags()); } } diff --git a/core/modules/block/tests/src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php b/core/modules/block/tests/src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php index a5e2e72e84..373670a79a 100644 --- a/core/modules/block/tests/src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php +++ b/core/modules/block/tests/src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\block\Unit\Plugin\DisplayVariant; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\DependencyInjection\Container; use Drupal\Tests\UnitTestCase; @@ -222,8 +222,8 @@ public function testBuild(array $blocks_config, $visible_block_count, array $exp ->will($this->returnValue([])); $this->blockRepository->expects($this->once()) ->method('getVisibleBlocksPerRegion') - ->willReturnCallback(function (&$cacheable_metadata) use ($blocks) { - $cacheable_metadata['top'] = (new CacheableMetadata())->addCacheTags(['route']); + ->willReturnCallback(function (&$cacheability_metadata) use ($blocks) { + $cacheability_metadata['top'] = (new CacheabilityMetadata())->addCacheTags(['route']); return $blocks; }); diff --git a/core/modules/book/src/Cache/BookNavigationCacheContext.php b/core/modules/book/src/Cache/BookNavigationCacheContext.php index 521d50bc49..8c7a35e20c 100644 --- a/core/modules/book/src/Cache/BookNavigationCacheContext.php +++ b/core/modules/book/src/Cache/BookNavigationCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\book\Cache; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\Context\CacheContextInterface; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerAwareTrait; @@ -72,21 +72,21 @@ public function getContext() { /** * {@inheritdoc} */ - public function getCacheableMetadata() { + public function getCacheabilityMetadata() { // The book active trail depends on the node and data attached to it. // That information is however not stored as part of the node. - $cacheable_metadata = new CacheableMetadata(); + $cacheability_metadata = new CacheabilityMetadata(); if ($node = $this->requestStack->getCurrentRequest()->get('node')) { // If the node is part of a book then we can use the cache tag for that // book. If not, then it can't be optimized away. if (!empty($node->book['bid'])) { - $cacheable_metadata->addCacheTags(['bid:' . $node->book['bid']]); + $cacheability_metadata->addCacheTags(['bid:' . $node->book['bid']]); } else { - $cacheable_metadata->setCacheMaxAge(0); + $cacheability_metadata->setCacheMaxAge(0); } } - return $cacheable_metadata; + return $cacheability_metadata; } } diff --git a/core/modules/color/color.module b/core/modules/color/color.module index 92c6110b08..625efe9279 100644 --- a/core/modules/color/color.module +++ b/core/modules/color/color.module @@ -11,7 +11,7 @@ use Drupal\Component\Utility\Environment; use Drupal\Core\Asset\CssOptimizer; use Drupal\Core\Block\BlockPluginInterface; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\File\Exception\FileException; use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Form\FormStateInterface; @@ -125,7 +125,7 @@ function color_block_view_system_branding_block_alter(array &$build, BlockPlugin function color_block_view_pre_render(array $build) { $theme_key = \Drupal::theme()->getActiveTheme()->getName(); $config = \Drupal::config('color.theme.' . $theme_key); - CacheableMetadata::createFromRenderArray($build) + CacheabilityMetadata::createFromRenderArray($build) ->addCacheableDependency($config) ->applyTo($build); diff --git a/core/modules/config/tests/config_entity_static_cache_test/src/ConfigOverrider.php b/core/modules/config/tests/config_entity_static_cache_test/src/ConfigOverrider.php index 9d48e0b1b9..bf347dc773 100644 --- a/core/modules/config/tests/config_entity_static_cache_test/src/ConfigOverrider.php +++ b/core/modules/config/tests/config_entity_static_cache_test/src/ConfigOverrider.php @@ -2,7 +2,7 @@ namespace Drupal\config_entity_static_cache_test; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Config\ConfigFactoryOverrideInterface; use Drupal\Core\Config\StorageInterface; @@ -39,8 +39,8 @@ public function createConfigObject($name, $collection = StorageInterface::DEFAUL /** * {@inheritdoc} */ - public function getCacheableMetadata($name) { - return new CacheableMetadata(); + public function getCacheabilityMetadata($name) { + return new CacheabilityMetadata(); } } diff --git a/core/modules/config/tests/config_override_integration_test/src/Cache/ConfigOverrideIntegrationTestCacheContext.php b/core/modules/config/tests/config_override_integration_test/src/Cache/ConfigOverrideIntegrationTestCacheContext.php index de9fefcc4a..0126daba2d 100644 --- a/core/modules/config/tests/config_override_integration_test/src/Cache/ConfigOverrideIntegrationTestCacheContext.php +++ b/core/modules/config/tests/config_override_integration_test/src/Cache/ConfigOverrideIntegrationTestCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\config_override_integration_test\Cache; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\Context\CacheContextInterface; /** @@ -31,10 +31,10 @@ public function getContext() { /** * {@inheritdoc} */ - public function getCacheableMetadata() { + public function getCacheabilityMetadata() { // Since this depends on State this can change at any time and is not // cacheable. - $metadata = new CacheableMetadata(); + $metadata = new CacheabilityMetadata(); $metadata->setCacheMaxAge(0); return $metadata; } diff --git a/core/modules/config/tests/config_override_integration_test/src/CacheabilityMetadataConfigOverride.php b/core/modules/config/tests/config_override_integration_test/src/CacheabilityMetadataConfigOverride.php index 4ae2fe6326..f52bc3c13d 100644 --- a/core/modules/config/tests/config_override_integration_test/src/CacheabilityMetadataConfigOverride.php +++ b/core/modules/config/tests/config_override_integration_test/src/CacheabilityMetadataConfigOverride.php @@ -2,7 +2,7 @@ namespace Drupal\config_override_integration_test; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Config\ConfigFactoryOverrideInterface; use Drupal\Core\Config\StorageInterface; @@ -47,8 +47,8 @@ public function createConfigObject($name, $collection = StorageInterface::DEFAUL /** * {@inheritdoc} */ - public function getCacheableMetadata($name) { - $metadata = new CacheableMetadata(); + public function getCacheabilityMetadata($name) { + $metadata = new CacheabilityMetadata(); if ($name === 'block.block.config_override_test') { $metadata ->setCacheContexts(['config_override_integration_test']) diff --git a/core/modules/config/tests/config_override_test/src/Cache/PirateDayCacheContext.php b/core/modules/config/tests/config_override_test/src/Cache/PirateDayCacheContext.php index b9e2490f37..de419ba84c 100644 --- a/core/modules/config/tests/config_override_test/src/Cache/PirateDayCacheContext.php +++ b/core/modules/config/tests/config_override_test/src/Cache/PirateDayCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\config_override_test\Cache; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\Context\CacheContextInterface; /** @@ -54,8 +54,8 @@ public static function isPirateDay() { /** * {@inheritdoc} */ - public function getCacheableMetadata() { - return new CacheableMetadata(); + public function getCacheabilityMetadata() { + return new CacheabilityMetadata(); } } diff --git a/core/modules/config/tests/config_override_test/src/ConfigOverrider.php b/core/modules/config/tests/config_override_test/src/ConfigOverrider.php index c8ffc694b3..233a497e07 100644 --- a/core/modules/config/tests/config_override_test/src/ConfigOverrider.php +++ b/core/modules/config/tests/config_override_test/src/ConfigOverrider.php @@ -2,7 +2,7 @@ namespace Drupal\config_override_test; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Config\ConfigFactoryOverrideInterface; /** @@ -43,8 +43,8 @@ public function createConfigObject($name, $collection = StorageInterface::DEFAUL /** * {@inheritdoc} */ - public function getCacheableMetadata($name) { - return new CacheableMetadata(); + public function getCacheabilityMetadata($name) { + return new CacheabilityMetadata(); } } diff --git a/core/modules/config/tests/config_override_test/src/ConfigOverriderLowPriority.php b/core/modules/config/tests/config_override_test/src/ConfigOverriderLowPriority.php index 1156b00f22..9325a6146d 100644 --- a/core/modules/config/tests/config_override_test/src/ConfigOverriderLowPriority.php +++ b/core/modules/config/tests/config_override_test/src/ConfigOverriderLowPriority.php @@ -2,7 +2,7 @@ namespace Drupal\config_override_test; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Config\ConfigFactoryOverrideInterface; use Drupal\Core\Config\StorageInterface; @@ -48,8 +48,8 @@ public function createConfigObject($name, $collection = StorageInterface::DEFAUL /** * {@inheritdoc} */ - public function getCacheableMetadata($name) { - return new CacheableMetadata(); + public function getCacheabilityMetadata($name) { + return new CacheabilityMetadata(); } } diff --git a/core/modules/config/tests/config_override_test/src/PirateDayCacheabilityMetadataConfigOverride.php b/core/modules/config/tests/config_override_test/src/PirateDayCacheabilityMetadataConfigOverride.php index 8610eadeea..c3cb92f040 100644 --- a/core/modules/config/tests/config_override_test/src/PirateDayCacheabilityMetadataConfigOverride.php +++ b/core/modules/config/tests/config_override_test/src/PirateDayCacheabilityMetadataConfigOverride.php @@ -3,7 +3,7 @@ namespace Drupal\config_override_test; use Drupal\config_override_test\Cache\PirateDayCacheContext; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Config\ConfigFactoryOverrideInterface; use Drupal\Core\Config\StorageInterface; @@ -52,8 +52,8 @@ public function createConfigObject($name, $collection = StorageInterface::DEFAUL /** * {@inheritdoc} */ - public function getCacheableMetadata($name) { - $metadata = new CacheableMetadata(); + public function getCacheabilityMetadata($name) { + $metadata = new CacheabilityMetadata(); $metadata ->setCacheContexts(['pirate_day']) ->setCacheTags(['pirate-day-tag']) diff --git a/core/modules/content_translation/src/Controller/ContentTranslationController.php b/core/modules/content_translation/src/Controller/ContentTranslationController.php index 22c5a40982..1759dc4d2d 100644 --- a/core/modules/content_translation/src/Controller/ContentTranslationController.php +++ b/core/modules/content_translation/src/Controller/ContentTranslationController.php @@ -4,7 +4,7 @@ use Drupal\content_translation\ContentTranslationManager; use Drupal\content_translation\ContentTranslationManagerInterface; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityFieldManagerInterface; @@ -110,7 +110,7 @@ public function overview(RouteMatchInterface $route_match, $entity_type_id = NUL // Start collecting the cacheability metadata, starting with the entity and // later merge in the access result cacheability metadata. - $cacheability = CacheableMetadata::createFromObject($entity); + $cacheability = CacheabilityMetadata::createFromObject($entity); $languages = $this->languageManager()->getLanguages(); $original = $entity->getUntranslated()->language()->getId(); @@ -202,8 +202,8 @@ public function overview(RouteMatchInterface $route_match, $entity_type_id = NUL $update_access = $entity->access('update', NULL, TRUE); $translation_access = $handler->getTranslationAccess($entity, 'update'); $cacheability = $cacheability - ->merge(CacheableMetadata::createFromObject($update_access)) - ->merge(CacheableMetadata::createFromObject($translation_access)); + ->merge(CacheabilityMetadata::createFromObject($update_access)) + ->merge(CacheabilityMetadata::createFromObject($translation_access)); if ($update_access->isAllowed() && $entity_type->hasLinkTemplate('edit-form')) { $links['edit']['url'] = $entity->toUrl('edit-form'); $links['edit']['language'] = $language; @@ -269,7 +269,7 @@ public function overview(RouteMatchInterface $route_match, $entity_type_id = NUL $create_translation_access = $handler->getTranslationAccess($entity, 'create'); $cacheability = $cacheability - ->merge(CacheableMetadata::createFromObject($create_translation_access)); + ->merge(CacheabilityMetadata::createFromObject($create_translation_access)); if ($source != $langcode && $create_translation_access->isAllowed()) { if ($translatable) { $links['add'] = [ diff --git a/core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php b/core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php index e99caa1b89..d4258df1f4 100644 --- a/core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php +++ b/core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php @@ -3,7 +3,7 @@ namespace Drupal\dynamic_page_cache\EventSubscriber; use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\CacheableResponseInterface; use Drupal\Core\PageCache\RequestPolicyInterface; use Drupal\Core\PageCache\ResponsePolicyInterface; @@ -229,7 +229,7 @@ public function onResponse(FilterResponseEvent $event) { protected function shouldCacheResponse(CacheableResponseInterface $response) { $conditions = $this->rendererConfig['auto_placeholder_conditions']; - $cacheability = $response->getCacheableMetadata(); + $cacheability = $response->getCacheabilityMetadata(); // Response's max-age is at or below the configured threshold. if ($cacheability->getCacheMaxAge() !== Cache::PERMANENT && $cacheability->getCacheMaxAge() <= $conditions['max-age']) { @@ -279,8 +279,8 @@ protected function responseToRenderArray(CacheableResponseInterface $response) { // Merge the response's cacheability metadata, so that RenderCache can take // care of cache redirects for us. - CacheableMetadata::createFromObject($response->getCacheableMetadata()) - ->merge(CacheableMetadata::createFromRenderArray($response_as_render_array)) + CacheabilityMetadata::createFromObject($response->getCacheabilityMetadata()) + ->merge(CacheabilityMetadata::createFromRenderArray($response_as_render_array)) ->applyTo($response_as_render_array); return $response_as_render_array; diff --git a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php index e7558803ed..1501c1f42c 100644 --- a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php +++ b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\field\Kernel\EntityReference; use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceEntityFormatter; use Drupal\field\Entity\FieldConfig; @@ -363,7 +363,7 @@ public function testLabelFormatter() { ], ]; $this->assertEqual($renderer->renderRoot($build[0]), $renderer->renderRoot($expected_item_1), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter)); - $this->assertEqual(CacheableMetadata::createFromRenderArray($build[0]), CacheableMetadata::createFromRenderArray($expected_item_1)); + $this->assertEqual(CacheabilityMetadata::createFromRenderArray($build[0]), CacheabilityMetadata::createFromRenderArray($expected_item_1)); // The second referenced entity is "autocreated", therefore not saved and // lacking any URL info. diff --git a/core/modules/filter/src/Element/ProcessedText.php b/core/modules/filter/src/Element/ProcessedText.php index 1a3392ba42..06c7f74633 100644 --- a/core/modules/filter/src/Element/ProcessedText.php +++ b/core/modules/filter/src/Element/ProcessedText.php @@ -3,7 +3,7 @@ namespace Drupal\filter\Element; use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Render\BubbleableMetadata; use Drupal\Core\Render\Element\RenderElement; use Drupal\filter\Entity\FilterFormat; @@ -73,7 +73,7 @@ public static function preRenderText($element) { $filter_settings = static::configFactory()->get('filter.settings'); $format_id = $filter_settings->get('fallback_format'); // Ensure 'filter.settings' config's cacheability is respected. - CacheableMetadata::createFromRenderArray($element) + CacheabilityMetadata::createFromRenderArray($element) ->addCacheableDependency($filter_settings) ->applyTo($element); } diff --git a/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestCacheMerge.php b/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestCacheMerge.php index 678d1e8495..e352d21795 100644 --- a/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestCacheMerge.php +++ b/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestCacheMerge.php @@ -4,10 +4,10 @@ use Drupal\filter\FilterProcessResult; use Drupal\filter\Plugin\FilterBase; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; /** - * Provides a test filter to merge with CacheableMetadata. + * Provides a test filter to merge with CacheabilityMetadata. * * @Filter( * id = "filter_test_cache_merge", @@ -24,7 +24,7 @@ class FilterTestCacheMerge extends FilterBase { public function process($text, $langcode) { $result = new FilterProcessResult($text); - $metadata = new CacheableMetadata(); + $metadata = new CacheabilityMetadata(); $metadata->addCacheTags(['merge:tag']); $metadata->addCacheContexts(['user.permissions']); $result = $result->merge($metadata); diff --git a/core/modules/hal/tests/src/Kernel/HalLinkManagerTest.php b/core/modules/hal/tests/src/Kernel/HalLinkManagerTest.php index 05a6b39f1e..8237c33622 100644 --- a/core/modules/hal/tests/src/Kernel/HalLinkManagerTest.php +++ b/core/modules/hal/tests/src/Kernel/HalLinkManagerTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\hal\Kernel; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Url; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; @@ -72,10 +72,10 @@ public function testGetTypeUri($link_domain, $entity_type, $bundle, array $conte public function providerTestGetTypeUri() { $serialization_context_collecting_cacheability = [ - CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => new CacheableMetadata(), + CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => new CacheabilityMetadata(), ]; $expected_serialization_context_cacheability_url_site = [ - CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => (new CacheableMetadata())->setCacheContexts(['url.site']), + CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => (new CacheabilityMetadata())->setCacheContexts(['url.site']), ]; $base_test_case = [ @@ -135,7 +135,7 @@ public function providerTestGetTypeUri() { 'context' => $serialization_context_collecting_cacheability, 'expected return' => 'http://llamas-rock.com/for-real/rest/type/node/page', 'expected context' => [ - CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => (new CacheableMetadata())->setCacheTags(['config:hal.settings']), + CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => (new CacheabilityMetadata())->setCacheTags(['config:hal.settings']), ], ], ]; @@ -166,10 +166,10 @@ public function testGetRelationUri($link_domain, $entity_type, $bundle, $field_n public function providerTestGetRelationUri() { $serialization_context_collecting_cacheability = [ - CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => new CacheableMetadata(), + CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => new CacheabilityMetadata(), ]; $expected_serialization_context_cacheability_url_site = [ - CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => (new CacheableMetadata())->setCacheContexts(['url.site']), + CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => (new CacheabilityMetadata())->setCacheContexts(['url.site']), ]; $field_name = $this->randomMachineName(); @@ -233,7 +233,7 @@ public function providerTestGetRelationUri() { 'context' => $serialization_context_collecting_cacheability, 'expected return' => 'http://llamas-rock.com/for-real/rest/relation/node/page/' . $field_name, 'expected context' => [ - CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => (new CacheableMetadata())->setCacheTags(['config:hal.settings']), + CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => (new CacheabilityMetadata())->setCacheTags(['config:hal.settings']), ], ], ]; @@ -261,7 +261,7 @@ public function testGetRelationInternalIds() { */ public function testHalLinkManagersSetLinkDomain() { $serialization_context = [ - CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => new CacheableMetadata(), + CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => new CacheabilityMetadata(), ]; /* @var \Drupal\rest\LinkManager\LinkManager $link_manager */ @@ -269,10 +269,10 @@ public function testHalLinkManagersSetLinkDomain() { $link_manager->setLinkDomain('http://example.com/'); $link = $link_manager->getTypeUri('node', 'page', $serialization_context); $this->assertEqual($link, 'http://example.com/rest/type/node/page'); - $this->assertEqual(new CacheableMetadata(), $serialization_context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY]); + $this->assertEqual(new CacheabilityMetadata(), $serialization_context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY]); $link = $link_manager->getRelationUri('node', 'page', 'field_ref', $serialization_context); $this->assertEqual($link, 'http://example.com/rest/relation/node/page/field_ref'); - $this->assertEqual(new CacheableMetadata(), $serialization_context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY]); + $this->assertEqual(new CacheabilityMetadata(), $serialization_context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY]); } } diff --git a/core/modules/help/src/Controller/HelpController.php b/core/modules/help/src/Controller/HelpController.php index 0ccf354e70..eed3dafc56 100644 --- a/core/modules/help/src/Controller/HelpController.php +++ b/core/modules/help/src/Controller/HelpController.php @@ -2,7 +2,7 @@ namespace Drupal\help\Controller; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\help\HelpSectionManager; @@ -64,7 +64,7 @@ public function helpMain() { $output = []; // We are checking permissions, so add the user.permissions cache context. - $cacheability = new CacheableMetadata(); + $cacheability = new CacheabilityMetadata(); $cacheability->addCacheContexts(['user.permissions']); $plugins = $this->helpManager->getDefinitions(); diff --git a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageUrlFormatter.php b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageUrlFormatter.php index 7109627a43..0d312338fd 100644 --- a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageUrlFormatter.php +++ b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageUrlFormatter.php @@ -2,7 +2,7 @@ namespace Drupal\image\Plugin\Field\FieldFormatter; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Form\FormStateInterface; @@ -68,9 +68,9 @@ public function viewElements(FieldItemListInterface $items, $langcode) { $url = file_url_transform_relative($url); // Add cacheability metadata from the image and image style. - $cacheability = CacheableMetadata::createFromObject($image); + $cacheability = CacheabilityMetadata::createFromObject($image); if ($image_style) { - $cacheability->addCacheableDependency(CacheableMetadata::createFromObject($image_style)); + $cacheability->addCacheableDependency(CacheabilityMetadata::createFromObject($image_style)); } $elements[$delta] = ['#markup' => $url]; diff --git a/core/modules/jsonapi/src/Access/RelationshipFieldAccess.php b/core/modules/jsonapi/src/Access/RelationshipFieldAccess.php index ff0e103745..2ad14c0823 100644 --- a/core/modules/jsonapi/src/Access/RelationshipFieldAccess.php +++ b/core/modules/jsonapi/src/Access/RelationshipFieldAccess.php @@ -4,7 +4,7 @@ use Drupal\Core\Access\AccessResult; use Drupal\Core\Access\AccessResultReasonInterface; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Http\Exception\CacheableAccessDeniedHttpException; use Drupal\Core\Routing\Access\AccessInterface; @@ -81,7 +81,7 @@ public function access(Request $request, Route $route, AccountInterface $account $detailed_reason = empty($access_reason) ? $reason : $reason . " {$access_reason}"; $access_result->setReason($detailed_reason); if ($request->isMethodCacheable()) { - throw new CacheableAccessDeniedHttpException(CacheableMetadata::createFromObject($access_result), $detailed_reason); + throw new CacheableAccessDeniedHttpException(CacheabilityMetadata::createFromObject($access_result), $detailed_reason); } } return $access_result; diff --git a/core/modules/jsonapi/src/Access/TemporaryQueryGuard.php b/core/modules/jsonapi/src/Access/TemporaryQueryGuard.php index 5c6c9c8d4e..fbb2648eb1 100644 --- a/core/modules/jsonapi/src/Access/TemporaryQueryGuard.php +++ b/core/modules/jsonapi/src/Access/TemporaryQueryGuard.php @@ -3,7 +3,7 @@ namespace Drupal\jsonapi\Access; use Drupal\Core\Access\AccessResult; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Config\Entity\ConfigEntityTypeInterface; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityTypeInterface; @@ -83,10 +83,10 @@ public static function setModuleHandler(ModuleHandlerInterface $module_handler) * The filters applicable to the query. * @param \Drupal\Core\Entity\Query\QueryInterface $query * The query to which access controls should be applied. - * @param \Drupal\Core\Cache\CacheableMetadata $cacheability + * @param \Drupal\Core\Cache\CacheabilityMetadata $cacheability * Collects cacheability for the query. */ - public static function applyAccessControls(Filter $filter, QueryInterface $query, CacheableMetadata $cacheability) { + public static function applyAccessControls(Filter $filter, QueryInterface $query, CacheabilityMetadata $cacheability) { assert(static::$fieldManager !== NULL); assert(static::$moduleHandler !== NULL); $filtered_fields = static::collectFilteredFields($filter->root()); @@ -107,8 +107,7 @@ public static function applyAccessControls(Filter $filter, QueryInterface $query * A tree of field specifiers in an entity query condition. The tree is a * multi-dimensional array where the keys are field specifiers and the * values are multi-dimensional array of the same form, containing only - * subsequent specifiers. @see ::buildTree(). - * @param \Drupal\Core\Cache\CacheableMetadata $cacheability + * subsequent specifiers. @param \Drupal\Core\Cache\CacheabilityMetadata $cacheability * Collects cacheability for the query. * @param string|null $field_prefix * Internal use only. Contains a string representation of the previously @@ -116,11 +115,12 @@ public static function applyAccessControls(Filter $filter, QueryInterface $query * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $field_storage_definition * Internal use only. The current field storage definition, if known. * + * @see ::buildTree(). * @see \Drupal\Core\Database\Query\AlterableInterface::addTag() * @see \Drupal\Core\Database\Query\AlterableInterface::addMetaData() * @see \Drupal\Core\Database\Query\ConditionInterface */ - protected static function secureQuery(QueryInterface $query, $entity_type_id, array $tree, CacheableMetadata $cacheability, $field_prefix = NULL, FieldStorageDefinitionInterface $field_storage_definition = NULL) { + protected static function secureQuery(QueryInterface $query, $entity_type_id, array $tree, CacheabilityMetadata $cacheability, $field_prefix = NULL, FieldStorageDefinitionInterface $field_storage_definition = NULL) { $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id); // Config entity types are not fieldable, therefore they do not have field // access restrictions, nor entity references to other entity types. @@ -192,10 +192,10 @@ protected static function secureQuery(QueryInterface $query, $entity_type_id, ar * @param string|null $field_prefix * A prefix to add before any query condition fields. NULL if no prefix * should be added. - * @param \Drupal\Core\Cache\CacheableMetadata $cacheability + * @param \Drupal\Core\Cache\CacheabilityMetadata $cacheability * Collects cacheability for the query. */ - protected static function applyAccessConditions(QueryInterface $query, $entity_type_id, $field_prefix, CacheableMetadata $cacheability) { + protected static function applyAccessConditions(QueryInterface $query, $entity_type_id, $field_prefix, CacheabilityMetadata $cacheability) { $access_condition = static::getAccessCondition($entity_type_id, $cacheability); if ($access_condition) { $prefixed_condition = !is_null($field_prefix) @@ -228,14 +228,14 @@ protected static function addConditionFieldPrefix(EntityConditionGroup $group, $ * * @param string $entity_type_id * The entity type ID for which to get an EntityConditionGroup. - * @param \Drupal\Core\Cache\CacheableMetadata $cacheability + * @param \Drupal\Core\Cache\CacheabilityMetadata $cacheability * Collects cacheability for the query. * * @return \Drupal\jsonapi\Query\EntityConditionGroup|null * An EntityConditionGroup or NULL if no conditions need to be applied to * secure an entity query. */ - protected static function getAccessCondition($entity_type_id, CacheableMetadata $cacheability) { + protected static function getAccessCondition($entity_type_id, CacheabilityMetadata $cacheability) { $current_user = \Drupal::currentUser(); $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id); @@ -350,14 +350,14 @@ protected static function getAccessCondition($entity_type_id, CacheableMetadata * The entity type for which to check filter access. * @param \Drupal\Core\Session\AccountInterface $account * The account for which to check access. - * @param \Drupal\Core\Cache\CacheableMetadata $cacheability + * @param \Drupal\Core\Cache\CacheabilityMetadata $cacheability * Collects cacheability for the query. * * @return \Drupal\jsonapi\Query\EntityConditionGroup|null * An EntityConditionGroup or NULL if no conditions need to be applied to * secure an entity query. */ - protected static function getAccessConditionForKnownSubsets(EntityTypeInterface $entity_type, AccountInterface $account, CacheableMetadata $cacheability) { + protected static function getAccessConditionForKnownSubsets(EntityTypeInterface $entity_type, AccountInterface $account, CacheabilityMetadata $cacheability) { // Get the combined access results for each JSONAPI_FILTER_AMONG_* subset. $access_results = static::getAccessResultsFromEntityFilterHook($entity_type, $account); @@ -483,7 +483,7 @@ protected static function getAccessResultsFromEntityFilterHook(EntityTypeInterfa * The comment entity type object. * @param \Drupal\Core\Session\AccountInterface $current_user * The current user. - * @param \Drupal\Core\Cache\CacheableMetadata $cacheability + * @param \Drupal\Core\Cache\CacheabilityMetadata $cacheability * Collects cacheability for the query. * @param int $depth * Internal use only. The recursion depth. It is possible to have comments @@ -494,7 +494,7 @@ protected static function getAccessResultsFromEntityFilterHook(EntityTypeInterfa * An EntityConditionGroup or NULL if no conditions need to be applied to * secure an entity query. */ - protected static function getCommentAccessCondition(EntityTypeInterface $comment_entity_type, AccountInterface $current_user, CacheableMetadata $cacheability, $depth = 1) { + protected static function getCommentAccessCondition(EntityTypeInterface $comment_entity_type, AccountInterface $current_user, CacheabilityMetadata $cacheability, $depth = 1) { // If a comment is assigned to another entity or author the cache needs to // be invalidated. $cacheability->addCacheTags($comment_entity_type->getListCacheTags()); diff --git a/core/modules/jsonapi/src/Context/FieldResolver.php b/core/modules/jsonapi/src/Context/FieldResolver.php index e41b8527d1..2c03bc0af7 100644 --- a/core/modules/jsonapi/src/Context/FieldResolver.php +++ b/core/modules/jsonapi/src/Context/FieldResolver.php @@ -6,7 +6,7 @@ use Drupal\Core\Access\AccessResult; use Drupal\Core\Access\AccessResultInterface; use Drupal\Core\Access\AccessResultReasonInterface; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; @@ -173,7 +173,7 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Ent * Thrown if the path contains invalid specifiers. */ public static function resolveInternalIncludePath(ResourceType $resource_type, array $path_parts, $depth = 0) { - $cacheability = (new CacheableMetadata())->addCacheContexts(['url.query_args:include']); + $cacheability = (new CacheabilityMetadata())->addCacheContexts(['url.query_args:include']); if (empty($path_parts[0])) { throw new CacheableBadRequestHttpException($cacheability, 'Empty include path.'); } @@ -264,7 +264,7 @@ public static function resolveInternalIncludePath(ResourceType $resource_type, a * @throws \Drupal\Core\Http\Exception\CacheableBadRequestHttpException */ public function resolveInternalEntityQueryPath($entity_type_id, $bundle, $external_field_name) { - $cacheability = (new CacheableMetadata())->addCacheContexts(['url.query_args:filter', 'url.query_args:sort']); + $cacheability = (new CacheabilityMetadata())->addCacheContexts(['url.query_args:filter', 'url.query_args:sort']); $resource_type = $this->resourceTypeRepository->get($entity_type_id, $bundle); if (empty($external_field_name)) { throw new CacheableBadRequestHttpException($cacheability, 'No field name was provided for the filter.'); @@ -671,7 +671,7 @@ protected static function getDataReferencePropertyName(array $candidate_definiti }, $unique_reference_names); // @todo Add test coverage for this in https://www.drupal.org/project/jsonapi/issues/2971281 $message = sprintf('Ambiguous path. Try one of the following: %s, in place of the given path: %s', implode(', ', $choices), implode('.', $unresolved_path_parts)); - $cacheability = (new CacheableMetadata())->addCacheContexts(['url.query_args:filter', 'url.query_args:sort']); + $cacheability = (new CacheabilityMetadata())->addCacheContexts(['url.query_args:filter', 'url.query_args:sort']); throw new CacheableBadRequestHttpException($cacheability, $message); } return $unique_reference_names[0]; diff --git a/core/modules/jsonapi/src/Controller/EntityResource.php b/core/modules/jsonapi/src/Controller/EntityResource.php index 5c43d3ee24..1f918659af 100644 --- a/core/modules/jsonapi/src/Controller/EntityResource.php +++ b/core/modules/jsonapi/src/Controller/EntityResource.php @@ -5,7 +5,7 @@ use Drupal\Component\Assertion\Inspector; use Drupal\Component\Datetime\TimeInterface; use Drupal\Component\Serialization\Json; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityFieldManagerInterface; @@ -376,7 +376,7 @@ public function getCollection(ResourceType $resource_type, Request $request) { $entity_type_id = $resource_type->getEntityTypeId(); $params = $this->getJsonApiParams($request, $resource_type); - $query_cacheability = new CacheableMetadata(); + $query_cacheability = new CacheabilityMetadata(); $query = $this->getCollectionQuery($resource_type, $params, $query_cacheability); // If the request is for the latest revision, toggle it on entity query. @@ -398,7 +398,7 @@ public function getCollection(ResourceType $resource_type, Request $request) { if (strpos($e->getMessage(), 'Getting the base fields is not supported for entity type') === 0) { preg_match('/entity type (.*)\./', $e->getMessage(), $matches); $config_entity_type_id = $matches[1]; - $cacheability = (new CacheableMetadata())->addCacheContexts(['url.path', 'url.query_args:filter']); + $cacheability = (new CacheabilityMetadata())->addCacheContexts(['url.path', 'url.query_args:filter']); throw new CacheableBadRequestHttpException($cacheability, sprintf("Filtering on config entities is not supported by Drupal's entity API. You tried to filter on a %s config entity.", $config_entity_type_id)); } else { @@ -421,7 +421,7 @@ public function getCollection(ResourceType $resource_type, Request $request) { $primary_data->setHasNextPage($has_next_page); // Calculate all the results and pass into a JSON:API Data object. - $count_query_cacheability = new CacheableMetadata(); + $count_query_cacheability = new CacheabilityMetadata(); if ($resource_type->includeCount()) { $count_query = $this->getCollectionCountQuery($resource_type, $params, $count_query_cacheability); $total_results = $this->executeQueryInRenderContext( @@ -436,7 +436,7 @@ public function getCollection(ResourceType $resource_type, Request $request) { $response->addCacheableDependency($query_cacheability); $response->addCacheableDependency($count_query_cacheability); - $response->addCacheableDependency((new CacheableMetadata()) + $response->addCacheableDependency((new CacheabilityMetadata()) ->addCacheContexts([ 'url.query_args:filter', 'url.query_args:sort', @@ -444,7 +444,7 @@ public function getCollection(ResourceType $resource_type, Request $request) { ])); if ($resource_type->isVersionable()) { - $response->addCacheableDependency((new CacheableMetadata())->addCacheContexts([ResourceVersionRouteEnhancer::CACHE_CONTEXT])); + $response->addCacheableDependency((new CacheabilityMetadata())->addCacheContexts([ResourceVersionRouteEnhancer::CACHE_CONTEXT])); } return $response; @@ -455,7 +455,7 @@ public function getCollection(ResourceType $resource_type, Request $request) { * * @param \Drupal\Core\Entity\Query\QueryInterface $query * The query to execute to get the return results. - * @param \Drupal\Core\Cache\CacheableMetadata $query_cacheability + * @param \Drupal\Core\Cache\CacheabilityMetadata $query_cacheability * The value object to carry the query cacheability. * * @return int|array @@ -468,7 +468,7 @@ public function getCollection(ResourceType $resource_type, Request $request) { * @see https://www.drupal.org/project/drupal/issues/2794385 * @todo Remove this after https://www.drupal.org/project/drupal/issues/3028976 is fixed. */ - protected function executeQueryInRenderContext(QueryInterface $query, CacheableMetadata $query_cacheability) { + protected function executeQueryInRenderContext(QueryInterface $query, CacheabilityMetadata $query_cacheability) { $context = new RenderContext(); $results = $this->renderer->executeInRenderContext($context, function () use ($query) { return $query->execute(); @@ -550,7 +550,7 @@ public function getRelationship(ResourceType $resource_type, FieldableEntityInte $resource_object = ResourceObject::createFromEntity($resource_type, $entity); $relationship_object_urls = EntityReferenceFieldNormalizer::getRelationshipLinks($resource_object, $related); $response = $this->buildWrappedResponse($field_list, $request, $this->getIncludes($request, $resource_object), $response_code, [], array_reduce(array_keys($relationship_object_urls), function (LinkCollection $links, $key) use ($relationship_object_urls) { - return $links->withLink($key, new Link(new CacheableMetadata(), $relationship_object_urls[$key], [$key])); + return $links->withLink($key, new Link(new CacheabilityMetadata(), $relationship_object_urls[$key], [$key])); }, new LinkCollection([]))); // Add the host entity as a cacheable dependency. $response->addCacheableDependency($entity); @@ -836,13 +836,13 @@ protected function deserialize(ResourceType $resource_type, Request $request, $c * The base JSON:API resource type for the query. * @param array $params * The parameters for the query. - * @param \Drupal\Core\Cache\CacheableMetadata $query_cacheability + * @param \Drupal\Core\Cache\CacheabilityMetadata $query_cacheability * Collects cacheability for the query. * * @return \Drupal\Core\Entity\Query\QueryInterface * A new query. */ - protected function getCollectionQuery(ResourceType $resource_type, array $params, CacheableMetadata $query_cacheability) { + protected function getCollectionQuery(ResourceType $resource_type, array $params, CacheabilityMetadata $query_cacheability) { $entity_type = $this->entityTypeManager->getDefinition($resource_type->getEntityTypeId()); $entity_storage = $this->entityTypeManager->getStorage($resource_type->getEntityTypeId()); @@ -898,13 +898,13 @@ protected function getCollectionQuery(ResourceType $resource_type, array $params * The base JSON:API resource type for the query. * @param array $params * The parameters for the query. - * @param \Drupal\Core\Cache\CacheableMetadata $query_cacheability + * @param \Drupal\Core\Cache\CacheabilityMetadata $query_cacheability * Collects cacheability for the query. * * @return \Drupal\Core\Entity\Query\QueryInterface * A new query. */ - protected function getCollectionCountQuery(ResourceType $resource_type, array $params, CacheableMetadata $query_cacheability) { + protected function getCollectionCountQuery(ResourceType $resource_type, array $params, CacheabilityMetadata $query_cacheability) { // Reset the range to get all the available results. return $this->getCollectionQuery($resource_type, $params, $query_cacheability)->range()->count(); } @@ -977,11 +977,11 @@ protected function buildWrappedResponse($data, Request $request, IncludedData $i assert($data instanceof Data || $data instanceof FieldItemListInterface); $links = ($links ?: new LinkCollection([])); if (!$links->hasLinkWithKey('self')) { - $self_link = new Link(new CacheableMetadata(), self::getRequestLink($request), ['self']); + $self_link = new Link(new CacheabilityMetadata(), self::getRequestLink($request), ['self']); $links = $links->withLink('self', $self_link); } $response = new ResourceResponse(new JsonApiDocumentTopLevel($data, $includes, $links, $meta), $response_code, $headers); - $cacheability = (new CacheableMetadata())->addCacheContexts([ + $cacheability = (new CacheabilityMetadata())->addCacheContexts([ // Make sure that different sparse fieldsets are cached differently. 'url.query_args:fields', // Make sure that different sets of includes are cached differently. @@ -1024,7 +1024,7 @@ protected function respondWithCollection(ResourceObjectData $primary_data, Data // the validity of this cached list. Add the list tag to deal with that. $list_tag = $this->entityTypeManager->getDefinition($resource_type->getEntityTypeId()) ->getListCacheTags(); - $response->getCacheableMetadata()->addCacheTags($list_tag); + $response->getCacheabilityMetadata()->addCacheTags($list_tag); foreach ($primary_data as $entity) { $response->addCacheableDependency($entity); } @@ -1253,27 +1253,27 @@ protected static function getPagerLinks(Request $request, OffsetPage $page_param $offset = $page_param->getOffset(); $size = $page_param->getSize(); if ($size <= 0) { - $cacheability = (new CacheableMetadata())->addCacheContexts(['url.query_args:page']); + $cacheability = (new CacheabilityMetadata())->addCacheContexts(['url.query_args:page']); throw new CacheableBadRequestHttpException($cacheability, sprintf('The page size needs to be a positive integer.')); } $query = (array) $request->query->getIterator(); // Check if this is not the last page. if ($link_context['has_next_page']) { $next_url = static::getRequestLink($request, static::getPagerQueries('next', $offset, $size, $query)); - $pager_links = $pager_links->withLink('next', new Link(new CacheableMetadata(), $next_url, ['next'])); + $pager_links = $pager_links->withLink('next', new Link(new CacheabilityMetadata(), $next_url, ['next'])); if (!empty($total)) { $last_url = static::getRequestLink($request, static::getPagerQueries('last', $offset, $size, $query, $total)); - $pager_links = $pager_links->withLink('last', new Link(new CacheableMetadata(), $last_url, ['last'])); + $pager_links = $pager_links->withLink('last', new Link(new CacheabilityMetadata(), $last_url, ['last'])); } } // Check if this is not the first page. if ($offset > 0) { $first_url = static::getRequestLink($request, static::getPagerQueries('first', $offset, $size, $query)); - $pager_links = $pager_links->withLink('first', new Link(new CacheableMetadata(), $first_url, ['first'])); + $pager_links = $pager_links->withLink('first', new Link(new CacheabilityMetadata(), $first_url, ['first'])); $prev_url = static::getRequestLink($request, static::getPagerQueries('prev', $offset, $size, $query)); - $pager_links = $pager_links->withLink('prev', new Link(new CacheableMetadata(), $prev_url, ['prev'])); + $pager_links = $pager_links->withLink('prev', new Link(new CacheabilityMetadata(), $prev_url, ['prev'])); } return $pager_links; diff --git a/core/modules/jsonapi/src/Controller/EntryPoint.php b/core/modules/jsonapi/src/Controller/EntryPoint.php index bbbc2d56d1..32dd641255 100644 --- a/core/modules/jsonapi/src/Controller/EntryPoint.php +++ b/core/modules/jsonapi/src/Controller/EntryPoint.php @@ -2,7 +2,7 @@ namespace Drupal\jsonapi\Controller; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Url; @@ -73,7 +73,7 @@ public static function create(ContainerInterface $container) { * The response object. */ public function index() { - $cacheability = (new CacheableMetadata()) + $cacheability = (new CacheabilityMetadata()) ->addCacheContexts(['user.roles:authenticated']) ->addCacheTags(['jsonapi_resource_types']); @@ -82,14 +82,14 @@ public function index() { return !$resource->isInternal(); }); - $self_link = new Link(new CacheableMetadata(), Url::fromRoute('jsonapi.resource_list'), ['self']); + $self_link = new Link(new CacheabilityMetadata(), Url::fromRoute('jsonapi.resource_list'), ['self']); $urls = array_reduce($resources, function (LinkCollection $carry, ResourceType $resource_type) { if ($resource_type->isLocatable() || $resource_type->isMutable()) { $route_suffix = $resource_type->isLocatable() ? 'collection' : 'collection.post'; $url = Url::fromRoute(sprintf('jsonapi.%s.%s', $resource_type->getTypeName(), $route_suffix))->setAbsolute(); // @todo: implement an extension relation type to signal that this is a primary collection resource. $link_relation_types = []; - return $carry->withLink($resource_type->getTypeName(), new Link(new CacheableMetadata(), $url, $link_relation_types)); + return $carry->withLink($resource_type->getTypeName(), new Link(new CacheabilityMetadata(), $url, $link_relation_types)); } return $carry; }, new LinkCollection(['self' => $self_link])); diff --git a/core/modules/jsonapi/src/Controller/FileUpload.php b/core/modules/jsonapi/src/Controller/FileUpload.php index b07dd51d0d..1124f463ea 100644 --- a/core/modules/jsonapi/src/Controller/FileUpload.php +++ b/core/modules/jsonapi/src/Controller/FileUpload.php @@ -4,7 +4,7 @@ use Drupal\Component\Render\PlainTextOutput; use Drupal\Core\Access\AccessResultReasonInterface; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Entity\EntityConstraintViolationListInterface; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\FieldableEntityInterface; @@ -178,8 +178,8 @@ public function handleFileUploadForNewResource(Request $request, ResourceType $r } // @todo Remove line below in favor of commented line in https://www.drupal.org/project/jsonapi/issues/2878463. - $self_link = new Link(new CacheableMetadata(), Url::fromRoute('jsonapi.file--file.individual', ['entity' => $file->uuid()]), ['self']); - /* $self_link = new Link(new CacheableMetadata(), $this->entity->toUrl('jsonapi'), ['self']); */ + $self_link = new Link(new CacheabilityMetadata(), Url::fromRoute('jsonapi.file--file.individual', ['entity' => $file->uuid()]), ['self']); + /* $self_link = new Link(new CacheabilityMetadata(), $this->entity->toUrl('jsonapi'), ['self']); */ $links = new LinkCollection(['self' => $self_link]); $relatable_resource_types = $resource_type->getRelatableResourceTypesByField($file_field_name); diff --git a/core/modules/jsonapi/src/EventSubscriber/JsonApiRequestValidator.php b/core/modules/jsonapi/src/EventSubscriber/JsonApiRequestValidator.php index d030784e83..4c91737559 100644 --- a/core/modules/jsonapi/src/EventSubscriber/JsonApiRequestValidator.php +++ b/core/modules/jsonapi/src/EventSubscriber/JsonApiRequestValidator.php @@ -2,7 +2,7 @@ namespace Drupal\jsonapi\EventSubscriber; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\jsonapi\JsonApiSpec; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; @@ -65,7 +65,7 @@ protected function validateQueryParams(Request $request) { // direction. (This is special cased because using it is pretty common.) if (in_array('_format', $invalid_query_params, TRUE)) { $uri_without_query_string = $request->getSchemeAndHttpHost() . $request->getBaseUrl() . $request->getPathInfo(); - $exception = new CacheableBadRequestHttpException((new CacheableMetadata())->addCacheContexts(['url.query_args:_format']), 'JSON:API does not need that ugly \'_format\' query string! 🤘 Use the URL provided in \'links\' 🙏'); + $exception = new CacheableBadRequestHttpException((new CacheabilityMetadata())->addCacheContexts(['url.query_args:_format']), 'JSON:API does not need that ugly \'_format\' query string! 🤘 Use the URL provided in \'links\' 🙏'); $exception->setHeaders(['Link' => $uri_without_query_string]); throw $exception; } @@ -75,7 +75,7 @@ protected function validateQueryParams(Request $request) { } $message = sprintf('The following query parameters violate the JSON:API spec: \'%s\'.', implode("', '", $invalid_query_params)); - $exception = new CacheableBadRequestHttpException((new CacheableMetadata())->addCacheContexts(['url.query_args']), $message); + $exception = new CacheableBadRequestHttpException((new CacheabilityMetadata())->addCacheContexts(['url.query_args']), $message); $exception->setHeaders(['Link' => 'http://jsonapi.org/format/#query-parameters']); throw $exception; } diff --git a/core/modules/jsonapi/src/EventSubscriber/ResourceResponseSubscriber.php b/core/modules/jsonapi/src/EventSubscriber/ResourceResponseSubscriber.php index 9bf6aaa43a..27919c9191 100644 --- a/core/modules/jsonapi/src/EventSubscriber/ResourceResponseSubscriber.php +++ b/core/modules/jsonapi/src/EventSubscriber/ResourceResponseSubscriber.php @@ -178,7 +178,7 @@ protected static function flattenResponse(ResourceResponse $response, Request $r } $final_response->headers = clone $response->headers; if ($final_response instanceof CacheableResponseInterface) { - $final_response->addCacheableDependency($response->getCacheableMetadata()); + $final_response->addCacheableDependency($response->getCacheabilityMetadata()); } return $final_response; } diff --git a/core/modules/jsonapi/src/Exception/EntityAccessDeniedHttpException.php b/core/modules/jsonapi/src/Exception/EntityAccessDeniedHttpException.php index 6b067ebe6f..799b74a1ba 100644 --- a/core/modules/jsonapi/src/Exception/EntityAccessDeniedHttpException.php +++ b/core/modules/jsonapi/src/Exception/EntityAccessDeniedHttpException.php @@ -4,7 +4,7 @@ use Drupal\Core\Access\AccessResultInterface; use Drupal\Core\Access\AccessResultReasonInterface; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\DependencyInjection\DependencySerializationTrait; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Http\Exception\CacheableAccessDeniedHttpException; @@ -60,7 +60,7 @@ class EntityAccessDeniedHttpException extends CacheableAccessDeniedHttpException */ public function __construct($entity, AccessResultInterface $entity_access, $pointer, $message = 'The current user is not allowed to GET the selected resource.', $relationship_field = NULL, \Exception $previous = NULL, $code = 0) { assert(is_null($entity) || $entity instanceof EntityInterface); - parent::__construct(CacheableMetadata::createFromObject($entity_access), $message, $previous, $code); + parent::__construct(CacheabilityMetadata::createFromObject($entity_access), $message, $previous, $code); $error = [ 'entity' => $entity, 'pointer' => $pointer, diff --git a/core/modules/jsonapi/src/JsonApiResource/Link.php b/core/modules/jsonapi/src/JsonApiResource/Link.php index 1da2d0afe8..54d1460b07 100644 --- a/core/modules/jsonapi/src/JsonApiResource/Link.php +++ b/core/modules/jsonapi/src/JsonApiResource/Link.php @@ -5,7 +5,7 @@ use Drupal\Component\Assertion\Inspector; use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Cache\CacheableDependencyTrait; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Url; /** @@ -56,7 +56,7 @@ /** * JSON:API Link constructor. * - * @param \Drupal\Core\Cache\CacheableMetadata $cacheability + * @param \Drupal\Core\Cache\CacheabilityMetadata $cacheability * Any cacheability metadata associated with the link. For example, a * 'call-to-action' link might reference a registration resource if an event * has vacancies or a wait-list resource otherwise. Therefore, the link's @@ -71,7 +71,7 @@ * * @see https://tools.ietf.org/html/rfc8288#section-2.1 */ - public function __construct(CacheableMetadata $cacheability, Url $url, array $link_relation_types, array $target_attributes = []) { + public function __construct(CacheabilityMetadata $cacheability, Url $url, array $link_relation_types, array $target_attributes = []) { // @todo: uncomment the extra assertion below when JSON:API begins to use its own extension relation types. assert(/* !empty($link_relation_types) && */Inspector::assertAllStrings($link_relation_types)); assert(Inspector::assertAllStrings(array_keys($target_attributes))); @@ -171,7 +171,7 @@ public static function merge(Link $a, Link $b) { } $merged_attributes[$key] = count($value) === 1 ? reset($value) : $value; } - $merged_cacheability = (new CacheableMetadata())->addCacheableDependency($a)->addCacheableDependency($b); + $merged_cacheability = (new CacheabilityMetadata())->addCacheableDependency($a)->addCacheableDependency($b); return new static($merged_cacheability, $a->getUri(), $merged_rels, $merged_attributes); } diff --git a/core/modules/jsonapi/src/JsonApiResource/ResourceObject.php b/core/modules/jsonapi/src/JsonApiResource/ResourceObject.php index 8a08cb3d4e..939791e25c 100644 --- a/core/modules/jsonapi/src/JsonApiResource/ResourceObject.php +++ b/core/modules/jsonapi/src/JsonApiResource/ResourceObject.php @@ -4,7 +4,7 @@ use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Cache\CacheableDependencyTrait; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityInterface; @@ -243,19 +243,19 @@ protected static function buildLinksFromEntity(ResourceType $resource_type, Enti // revision changes and to disambiguate resource objects with the same // `type` and `id` in a `version-history` collection. $self_with_version_url = $self_url->setOption('query', [JsonApiSpec::VERSION_QUERY_PARAMETER => 'id:' . $entity->getRevisionId()]); - $links = $links->withLink('self', new Link(new CacheableMetadata(), $self_with_version_url, ['self'])); + $links = $links->withLink('self', new Link(new CacheabilityMetadata(), $self_with_version_url, ['self'])); } if (!$entity->isDefaultRevision()) { $latest_version_url = $self_url->setOption('query', [JsonApiSpec::VERSION_QUERY_PARAMETER => 'rel:' . VersionByRel::LATEST_VERSION]); - $links = $links->withLink(VersionByRel::LATEST_VERSION, new Link(new CacheableMetadata(), $latest_version_url, [VersionByRel::LATEST_VERSION])); + $links = $links->withLink(VersionByRel::LATEST_VERSION, new Link(new CacheabilityMetadata(), $latest_version_url, [VersionByRel::LATEST_VERSION])); } if (!$entity->isLatestRevision()) { $working_copy_url = $self_url->setOption('query', [JsonApiSpec::VERSION_QUERY_PARAMETER => 'rel:' . VersionByRel::WORKING_COPY]); - $links = $links->withLink(VersionByRel::WORKING_COPY, new Link(new CacheableMetadata(), $working_copy_url, [VersionByRel::WORKING_COPY])); + $links = $links->withLink(VersionByRel::WORKING_COPY, new Link(new CacheabilityMetadata(), $working_copy_url, [VersionByRel::WORKING_COPY])); } } if (!$links->hasLinkWithKey('self')) { - $links = $links->withLink('self', new Link(new CacheableMetadata(), $self_url, ['self'])); + $links = $links->withLink('self', new Link(new CacheabilityMetadata(), $self_url, ['self'])); } } return $links; diff --git a/core/modules/jsonapi/src/Normalizer/EntityReferenceFieldNormalizer.php b/core/modules/jsonapi/src/Normalizer/EntityReferenceFieldNormalizer.php index 1096de42d3..7b8fb814ac 100644 --- a/core/modules/jsonapi/src/Normalizer/EntityReferenceFieldNormalizer.php +++ b/core/modules/jsonapi/src/Normalizer/EntityReferenceFieldNormalizer.php @@ -2,7 +2,7 @@ namespace Drupal\jsonapi\Normalizer; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Field\EntityReferenceFieldItemListInterface; use Drupal\Core\Url; use Drupal\jsonapi\JsonApiResource\ResourceIdentifier; @@ -45,7 +45,7 @@ public function normalize($field, $format = NULL, array $context = []) { $context['field_name'] = $field->getName(); $normalized_items = CacheableNormalization::aggregate($this->serializer->normalize($resource_identifiers, $format, $context)); assert($context['resource_object'] instanceof ResourceObject); - $link_cacheability = new CacheableMetadata(); + $link_cacheability = new CacheabilityMetadata(); $links = array_map(function (Url $link) use ($link_cacheability) { $href = $link->setAbsolute()->toString(TRUE); $link_cacheability->addCacheableDependency($href); diff --git a/core/modules/jsonapi/src/Normalizer/FieldItemNormalizer.php b/core/modules/jsonapi/src/Normalizer/FieldItemNormalizer.php index 618d97e21d..c20c490e03 100644 --- a/core/modules/jsonapi/src/Normalizer/FieldItemNormalizer.php +++ b/core/modules/jsonapi/src/Normalizer/FieldItemNormalizer.php @@ -2,7 +2,7 @@ namespace Drupal\jsonapi\Normalizer; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Field\FieldItemInterface; use Drupal\Core\Field\FieldItemListInterface; @@ -62,7 +62,7 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager) { public function normalize($field_item, $format = NULL, array $context = []) { /** @var \Drupal\Core\TypedData\TypedDataInterface $property */ $values = []; - $context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY] = new CacheableMetadata(); + $context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY] = new CacheabilityMetadata(); if (!empty($field_item->getProperties(TRUE))) { // We normalize each individual value, so each can do their own casting, // if needed. diff --git a/core/modules/jsonapi/src/Normalizer/HttpExceptionNormalizer.php b/core/modules/jsonapi/src/Normalizer/HttpExceptionNormalizer.php index 2c562ae29c..ea5472e708 100644 --- a/core/modules/jsonapi/src/Normalizer/HttpExceptionNormalizer.php +++ b/core/modules/jsonapi/src/Normalizer/HttpExceptionNormalizer.php @@ -2,7 +2,7 @@ namespace Drupal\jsonapi\Normalizer; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Session\AccountInterface; use Drupal\jsonapi\Normalizer\Value\HttpExceptionNormalizerValue; use Symfony\Component\HttpFoundation\Response; @@ -49,7 +49,7 @@ public function __construct(AccountInterface $current_user) { * {@inheritdoc} */ public function normalize($object, $format = NULL, array $context = []) { - return new HttpExceptionNormalizerValue(new CacheableMetadata(), $this->buildErrorObjects($object)); + return new HttpExceptionNormalizerValue(new CacheabilityMetadata(), $this->buildErrorObjects($object)); } /** diff --git a/core/modules/jsonapi/src/Normalizer/JsonApiDocumentTopLevelNormalizer.php b/core/modules/jsonapi/src/Normalizer/JsonApiDocumentTopLevelNormalizer.php index 02bb732d7e..40ddfce1d7 100644 --- a/core/modules/jsonapi/src/Normalizer/JsonApiDocumentTopLevelNormalizer.php +++ b/core/modules/jsonapi/src/Normalizer/JsonApiDocumentTopLevelNormalizer.php @@ -5,7 +5,7 @@ use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Component\Utility\Crypt; use Drupal\Component\Uuid\Uuid; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Field\EntityReferenceFieldItemListInterface; use Drupal\jsonapi\JsonApiResource\ErrorCollection; @@ -209,7 +209,7 @@ public function normalize($object, $format = NULL, array $context = []) { // Add document links. $document['links'] = $this->serializer->normalize($object->getLinks(), $format, $context)->omitIfEmpty(); // Every JSON:API document contains absolute URLs. - return CacheableNormalization::aggregate($document)->withCacheableDependency((new CacheableMetadata())->addCacheContexts(['url.site'])); + return CacheableNormalization::aggregate($document)->withCacheableDependency((new CacheabilityMetadata())->addCacheContexts(['url.site'])); } /** @@ -231,7 +231,7 @@ protected function normalizeErrorDocument(JsonApiDocumentTopLevel $document, $fo $normalized_values = array_map(function (HttpExceptionInterface $exception) use ($format, $context) { return $this->serializer->normalize($exception, $format, $context); }, (array) $document->getData()->getIterator()); - $cacheability = new CacheableMetadata(); + $cacheability = new CacheabilityMetadata(); $errors = []; foreach ($normalized_values as $normalized_error) { $cacheability->addCacheableDependency($normalized_error); @@ -285,7 +285,7 @@ protected function normalizeOmissionsLinks(OmittedData $omissions, $format, arra $normalized_omissions = array_map(function (HttpExceptionInterface $exception) use ($format, $context) { return $this->serializer->normalize($exception, $format, $context); }, $omissions->toArray()); - $cacheability = CacheableMetadata::createFromObject(CacheableNormalization::aggregate($normalized_omissions)); + $cacheability = CacheabilityMetadata::createFromObject(CacheableNormalization::aggregate($normalized_omissions)); if (empty($normalized_omissions)) { return new CacheableOmission($cacheability); } diff --git a/core/modules/jsonapi/src/Normalizer/ResourceObjectNormalizer.php b/core/modules/jsonapi/src/Normalizer/ResourceObjectNormalizer.php index 4e0f881e1c..c6c0d1a904 100644 --- a/core/modules/jsonapi/src/Normalizer/ResourceObjectNormalizer.php +++ b/core/modules/jsonapi/src/Normalizer/ResourceObjectNormalizer.php @@ -2,7 +2,7 @@ namespace Drupal\jsonapi\Normalizer; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Field\FieldItemListInterface; use Drupal\jsonapi\JsonApiResource\ResourceObject; use Drupal\jsonapi\Normalizer\Value\CacheableNormalization; @@ -88,11 +88,11 @@ protected function serializeField($field, array $context, $format) { if ($field instanceof FieldItemListInterface) { $field_access_result = $field->access('view', $context['account'], TRUE); if (!$field_access_result->isAllowed()) { - return new CacheableOmission(CacheableMetadata::createFromObject($field_access_result)); + return new CacheableOmission(CacheabilityMetadata::createFromObject($field_access_result)); } $normalized_field = $this->serializer->normalize($field, $format, $context); assert($normalized_field instanceof CacheableNormalization); - return $normalized_field->withCacheableDependency(CacheableMetadata::createFromObject($field_access_result)); + return $normalized_field->withCacheableDependency(CacheabilityMetadata::createFromObject($field_access_result)); } else { // @todo Replace this workaround after https://www.drupal.org/node/3043245 diff --git a/core/modules/jsonapi/src/Normalizer/Value/CacheableNormalization.php b/core/modules/jsonapi/src/Normalizer/Value/CacheableNormalization.php index 538422284e..1e8b2a3d30 100644 --- a/core/modules/jsonapi/src/Normalizer/Value/CacheableNormalization.php +++ b/core/modules/jsonapi/src/Normalizer/Value/CacheableNormalization.php @@ -5,7 +5,7 @@ use Drupal\Component\Assertion\Inspector; use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Cache\CacheableDependencyTrait; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; /** * Use to store normalized data and its cacheability. @@ -53,7 +53,7 @@ public function __construct(CacheableDependencyInterface $cacheability, $normali * The CacheableNormalization. */ public static function permanent($normalization) { - return new static(new CacheableMetadata(), $normalization); + return new static(new CacheabilityMetadata(), $normalization); } /** @@ -88,7 +88,7 @@ public function omitIfEmpty() { * dependency. */ public function withCacheableDependency(CacheableDependencyInterface $dependency) { - return new static(CacheableMetadata::createFromObject($this)->addCacheableDependency($dependency), $this->normalization); + return new static(CacheabilityMetadata::createFromObject($this)->addCacheableDependency($dependency), $this->normalization); } /** @@ -106,9 +106,9 @@ public function withCacheableDependency(CacheableDependencyInterface $dependency public static function aggregate(array $cacheable_normalizations) { assert(Inspector::assertAllObjects($cacheable_normalizations, CacheableNormalization::class)); return new static( - array_reduce($cacheable_normalizations, function (CacheableMetadata $merged, CacheableNormalization $item) { + array_reduce($cacheable_normalizations, function (CacheabilityMetadata $merged, CacheableNormalization $item) { return $merged->addCacheableDependency($item); - }, new CacheableMetadata()), + }, new CacheabilityMetadata()), array_reduce(array_keys($cacheable_normalizations), function ($merged, $key) use ($cacheable_normalizations) { if (!$cacheable_normalizations[$key] instanceof CacheableOmission) { $merged[$key] = $cacheable_normalizations[$key]->getNormalization(); diff --git a/core/modules/jsonapi/src/Query/EntityCondition.php b/core/modules/jsonapi/src/Query/EntityCondition.php index 3e2d460b2c..f5b5038ebb 100644 --- a/core/modules/jsonapi/src/Query/EntityCondition.php +++ b/core/modules/jsonapi/src/Query/EntityCondition.php @@ -2,7 +2,7 @@ namespace Drupal\jsonapi\Query; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Http\Exception\CacheableBadRequestHttpException; /** @@ -151,7 +151,7 @@ protected static function validate($parameter) { $has_path_key = isset($parameter[static::PATH_KEY]); $has_value_key = isset($parameter[static::VALUE_KEY]); - $cacheability = (new CacheableMetadata())->addCacheContexts(['url.query_args:filter']); + $cacheability = (new CacheabilityMetadata())->addCacheContexts(['url.query_args:filter']); if (!$valid_key_set) { // Try to provide a more specific exception is a key is missing. if (!$has_operator_key) { diff --git a/core/modules/jsonapi/src/Query/OffsetPage.php b/core/modules/jsonapi/src/Query/OffsetPage.php index e620ca8e61..4c96b222c1 100644 --- a/core/modules/jsonapi/src/Query/OffsetPage.php +++ b/core/modules/jsonapi/src/Query/OffsetPage.php @@ -2,7 +2,7 @@ namespace Drupal\jsonapi\Query; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Http\Exception\CacheableBadRequestHttpException; /** @@ -109,7 +109,7 @@ public function getSize() { */ public static function createFromQueryParameter($parameter) { if (!is_array($parameter)) { - $cacheability = (new CacheableMetadata())->addCacheContexts(['url.query_args:page']); + $cacheability = (new CacheabilityMetadata())->addCacheContexts(['url.query_args:page']); throw new CacheableBadRequestHttpException($cacheability, 'The page parameter needs to be an array.'); } diff --git a/core/modules/jsonapi/src/Query/Sort.php b/core/modules/jsonapi/src/Query/Sort.php index 5052623346..87dcc86be6 100644 --- a/core/modules/jsonapi/src/Query/Sort.php +++ b/core/modules/jsonapi/src/Query/Sort.php @@ -2,7 +2,7 @@ namespace Drupal\jsonapi\Query; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Http\Exception\CacheableBadRequestHttpException; /** @@ -92,7 +92,7 @@ public function fields() { */ public static function createFromQueryParameter($parameter) { if (empty($parameter)) { - $cacheability = (new CacheableMetadata())->addCacheContexts(['url.query_args:sort']); + $cacheability = (new CacheabilityMetadata())->addCacheContexts(['url.query_args:sort']); throw new CacheableBadRequestHttpException($cacheability, 'You need to provide a value for the sort parameter.'); } @@ -146,7 +146,7 @@ protected static function expandFieldString($fields) { * The expanded sort item. */ protected static function expandItem(array $sort_item) { - $cacheability = (new CacheableMetadata())->addCacheContexts(['url.query_args:sort']); + $cacheability = (new CacheabilityMetadata())->addCacheContexts(['url.query_args:sort']); $defaults = [ static::DIRECTION_KEY => 'ASC', static::LANGUAGE_KEY => NULL, diff --git a/core/modules/jsonapi/src/Revisions/ResourceVersionRouteEnhancer.php b/core/modules/jsonapi/src/Revisions/ResourceVersionRouteEnhancer.php index 50cb8b8c5d..c32a1376f4 100644 --- a/core/modules/jsonapi/src/Revisions/ResourceVersionRouteEnhancer.php +++ b/core/modules/jsonapi/src/Revisions/ResourceVersionRouteEnhancer.php @@ -2,7 +2,7 @@ namespace Drupal\jsonapi\Revisions; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Http\Exception\CacheableBadRequestHttpException; use Drupal\Core\Http\Exception\CacheableHttpException; @@ -99,7 +99,7 @@ public function enhance(array $defaults, Request $request) { // to support the `node` and `media` entity types because they are the // only // entity types that have revision access checks for forward // revisions that are not the default and not the latest revision. - $cacheability = (new CacheableMetadata())->addCacheContexts(['url.path', static::CACHE_CONTEXT]); + $cacheability = (new CacheabilityMetadata())->addCacheContexts(['url.path', static::CACHE_CONTEXT]); /* Uncomment the next line and remove the following one when https://www.drupal.org/project/drupal/issues/3002352 lands in core. */ /* throw new CacheableHttpException($cacheability, 501, 'Resource versioning is not yet supported for this resource type.'); */ $message = 'JSON:API does not yet support resource versioning for this resource type.'; @@ -132,7 +132,7 @@ public function enhance(array $defaults, Request $request) { $resource_version_identifier = $request->query->get(static::RESOURCE_VERSION_QUERY_PARAMETER); if (!static::isValidVersionIdentifier($resource_version_identifier)) { - $cacheability = (new CacheableMetadata())->addCacheContexts([static::CACHE_CONTEXT]); + $cacheability = (new CacheabilityMetadata())->addCacheContexts([static::CACHE_CONTEXT]); $message = sprintf('A resource version identifier was provided in an invalid format: `%s`', $resource_version_identifier); throw new CacheableBadRequestHttpException($cacheability, $message); } @@ -149,14 +149,14 @@ public function enhance(array $defaults, Request $request) { static::CACHE_CONTEXT, 'url.query_args:filter', ]; - $cacheability = (new CacheableMetadata())->addCacheContexts($cache_contexts); + $cacheability = (new CacheabilityMetadata())->addCacheContexts($cache_contexts); $message = 'JSON:API does not support filtering on revisions other than the latest version because a secure Drupal core API does not yet exist to do so.'; throw new CacheableHttpException($cacheability, 501, $message, NULL, []); } // 'latest-version' and 'working-copy' are the only acceptable version // identifiers for a collection resource. if (!in_array($resource_version_identifier, [$latest_version_identifier, $working_copy_identifier])) { - $cacheability = (new CacheableMetadata())->addCacheContexts(['url.path', static::CACHE_CONTEXT]); + $cacheability = (new CacheabilityMetadata())->addCacheContexts(['url.path', static::CACHE_CONTEXT]); $message = sprintf('Collection resources only support the following resource version identifiers: %s', implode(', ', [ $latest_version_identifier, $working_copy_identifier, diff --git a/core/modules/jsonapi/src/Revisions/VersionNegotiator.php b/core/modules/jsonapi/src/Revisions/VersionNegotiator.php index 157efa529f..5eda6a4201 100644 --- a/core/modules/jsonapi/src/Revisions/VersionNegotiator.php +++ b/core/modules/jsonapi/src/Revisions/VersionNegotiator.php @@ -2,7 +2,7 @@ namespace Drupal\jsonapi\Revisions; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Http\Exception\CacheableBadRequestHttpException; use Drupal\Core\Http\Exception\CacheableNotFoundHttpException; @@ -90,7 +90,7 @@ public function getRevision(EntityInterface $entity, $resource_version_identifie * @throws \Drupal\Core\Http\Exception\CacheableNotFoundHttpException */ protected static function throwNotFoundHttpException(EntityInterface $entity, $resource_version_identifier) { - $cacheability = CacheableMetadata::createFromObject($entity)->addCacheContexts(['url.path', 'url.query_args:' . ResourceVersionRouteEnhancer::RESOURCE_VERSION_QUERY_PARAMETER]); + $cacheability = CacheabilityMetadata::createFromObject($entity)->addCacheContexts(['url.path', 'url.query_args:' . ResourceVersionRouteEnhancer::RESOURCE_VERSION_QUERY_PARAMETER]); $reason = sprintf('The requested version, identified by `%s`, could not be found.', $resource_version_identifier); throw new CacheableNotFoundHttpException($cacheability, $reason); } @@ -104,7 +104,7 @@ protected static function throwNotFoundHttpException(EntityInterface $entity, $r * @throws \Drupal\Core\Http\Exception\CacheableBadRequestHttpException */ protected static function throwBadRequestHttpException($resource_version_identifier) { - $cacheability = (new CacheableMetadata())->addCacheContexts(['url.query_args:' . ResourceVersionRouteEnhancer::RESOURCE_VERSION_QUERY_PARAMETER]); + $cacheability = (new CacheabilityMetadata())->addCacheContexts(['url.query_args:' . ResourceVersionRouteEnhancer::RESOURCE_VERSION_QUERY_PARAMETER]); $message = sprintf('An invalid resource version identifier, `%s`, was provided.', $resource_version_identifier); throw new CacheableBadRequestHttpException($cacheability, $message); } diff --git a/core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php b/core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php index 04a173ff71..fde54b3586 100644 --- a/core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php +++ b/core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php @@ -7,7 +7,7 @@ use Drupal\Core\Access\AccessResultInterface; use Drupal\Core\Access\AccessResultReasonInterface; use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\RevisionableInterface; use Drupal\Core\Url; @@ -44,7 +44,7 @@ protected static function toCollectionResourceResponse(array $responses, $self_link, $is_multiple) { assert(count($responses) > 0); $merged_document = []; - $merged_cacheability = new CacheableMetadata(); + $merged_cacheability = new CacheabilityMetadata(); foreach ($responses as $response) { $response_document = $response->getResponseData(); // If any of the response documents had top-level errors, we should later @@ -72,7 +72,7 @@ protected static function toCollectionResourceResponse(array $responses, $self_l } } } - $merged_cacheability->addCacheableDependency($response->getCacheableMetadata()); + $merged_cacheability->addCacheableDependency($response->getCacheabilityMetadata()); } $merged_document['jsonapi'] = [ 'meta' => [ @@ -200,7 +200,7 @@ protected function getExpectedIncludedResourceResponse(array $include_paths, arr ]; } - $basic_cacheability = (new CacheableMetadata()) + $basic_cacheability = (new CacheabilityMetadata()) ->addCacheTags($this->getExpectedCacheTags()) ->addCacheContexts($this->getExpectedCacheContexts()); return static::decorateExpectedResponseForIncludedFields(ResourceResponse::create($individual_document), $resource_data['responses']) @@ -234,7 +234,7 @@ protected static function toResourceResponses(array $responses) { * The ResourceResponse. */ protected static function toResourceResponse(ResponseInterface $response) { - $cacheability = new CacheableMetadata(); + $cacheability = new CacheabilityMetadata(); if ($cache_tags = $response->getHeader('X-Drupal-Cache-Tags')) { $cacheability->addCacheTags(explode(' ', $cache_tags[0])); } @@ -523,7 +523,7 @@ protected static function getAccessDeniedResponse(EntityInterface $entity, Acces 'jsonapi' => static::$jsonApiMember, 'errors' => [$error], ], 403)) - ->addCacheableDependency((new CacheableMetadata())->addCacheTags(['4xx-response', 'http_response'])->addCacheContexts(['url.site'])) + ->addCacheableDependency((new CacheabilityMetadata())->addCacheTags(['4xx-response', 'http_response'])->addCacheContexts(['url.site'])) ->addCacheableDependency($access); } @@ -548,7 +548,7 @@ protected function getEmptyCollectionResponse($cardinality, $self_link) { // Drupal defaults. 'url.site', ], $this->entity->getEntityType()->isRevisionable() ? ['url.query_args:resourceVersion'] : []); - $cacheability = (new CacheableMetadata())->addCacheContexts($cache_contexts)->addCacheTags(['http_response']); + $cacheability = (new CacheabilityMetadata())->addCacheContexts($cache_contexts)->addCacheTags(['http_response']); return (new ResourceResponse([ // Empty to-one relationships should be NULL and empty to-many // relationships should be an empty array. diff --git a/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php b/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php index f50c15804a..b9d846c15e 100644 --- a/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php +++ b/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php @@ -8,7 +8,7 @@ use Drupal\Core\Access\AccessResult; use Drupal\Core\Access\AccessResultReasonInterface; use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\CacheableResponseInterface; use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Entity\ContentEntityInterface; @@ -377,7 +377,7 @@ protected function getData() { * The JSON:API normalization for the given entity. */ protected function normalize(EntityInterface $entity, Url $url) { - $self_link = new Link(new CacheableMetadata(), $url, ['self']); + $self_link = new Link(new CacheabilityMetadata(), $url, ['self']); $resource_type = $this->container->get('jsonapi.resource_type.repository')->getByTypeName(static::$resourceTypeName); $doc = new JsonApiDocumentTopLevel(new ResourceObjectData([ResourceObject::createFromEntity($resource_type, $entity)], 1), new NullIncludedData(), new LinkCollection(['self' => $self_link])); return $this->serializer->normalize($doc, 'api_json', [ @@ -469,11 +469,11 @@ protected function getPatchDocument() { /** * Returns the expected cacheability for an unauthorized response. * - * @return \Drupal\Core\Cache\CacheableMetadata + * @return \Drupal\Core\Cache\CacheabilityMetadata * The expected cacheability. */ protected function getExpectedUnauthorizedAccessCacheability() { - return (new CacheableMetadata()) + return (new CacheabilityMetadata()) ->setCacheTags(['4xx-response', 'http_response']) ->setCacheContexts(['url.site', 'user.permissions']) ->addCacheContexts($this->entity->getEntityType()->isRevisionable() @@ -541,11 +541,11 @@ protected function getExpectedCacheContexts(array $sparse_fieldset = NULL) { * @param bool $filtered * Whether the collection is filtered or not. * - * @return \Drupal\Core\Cache\CacheableMetadata + * @return \Drupal\Core\Cache\CacheabilityMetadata * The expected cacheability for the given entity collection. */ protected static function getExpectedCollectionCacheability(AccountInterface $account, array $collection, array $sparse_fieldset = NULL, $filtered = FALSE) { - $cacheability = array_reduce($collection, function (CacheableMetadata $cacheability, EntityInterface $entity) use ($sparse_fieldset, $account) { + $cacheability = array_reduce($collection, function (CacheabilityMetadata $cacheability, EntityInterface $entity) use ($sparse_fieldset, $account) { $access_result = static::entityAccess($entity, 'view', $account); if (!$access_result->isAllowed()) { $access_result = static::entityAccess($entity, 'view label', $account)->addCacheableDependency($access_result); @@ -563,7 +563,7 @@ protected static function getExpectedCollectionCacheability(AccountInterface $ac foreach ($field_item_list as $field_item) { /* @var \Drupal\Core\Field\FieldItemInterface $field_item */ foreach (TypedDataInternalPropertiesHelper::getNonInternalProperties($field_item) as $property) { - $cacheability->addCacheableDependency(CacheableMetadata::createFromObject($property)); + $cacheability->addCacheableDependency(CacheabilityMetadata::createFromObject($property)); } } } @@ -572,7 +572,7 @@ protected static function getExpectedCollectionCacheability(AccountInterface $ac } } return $cacheability; - }, new CacheableMetadata()); + }, new CacheabilityMetadata()); $entity_type = reset($collection)->getEntityType(); $cacheability->addCacheTags(['http_response']); $cacheability->addCacheTags($entity_type->getListCacheTags()); @@ -1073,7 +1073,7 @@ public function testCollection() { // This asserts that collections will work without a sort, added by default // below, without actually asserting the content of the response. $expected_response = $this->getExpectedCollectionResponse($entity_collection, $collection_url->toString(), $request_options); - $expected_cacheability = $expected_response->getCacheableMetadata(); + $expected_cacheability = $expected_response->getCacheabilityMetadata(); $response = $this->request('HEAD', $collection_url, $request_options); // MISS or UNCACHEABLE depends on the collection data. It must not be HIT. $dynamic_cache = $expected_cacheability->getCacheMaxAge() === 0 ? 'UNCACHEABLE' : 'MISS'; @@ -1088,7 +1088,7 @@ public function testCollection() { // on a per-entity basis, which is handled by // self::getExpectedCollectionResponse(). $expected_response = $this->getExpectedCollectionResponse($entity_collection, $collection_url->toString(), $request_options); - $expected_cacheability = $expected_response->getCacheableMetadata(); + $expected_cacheability = $expected_response->getCacheabilityMetadata(); $expected_document = $expected_response->getResponseData(); $response = $this->request('GET', $collection_url, $request_options); $this->assertResourceResponse(200, $expected_document, $response, $expected_cacheability->getCacheTags(), $expected_cacheability->getCacheContexts(), FALSE, $dynamic_cache); @@ -1097,13 +1097,13 @@ public function testCollection() { // 200 for well-formed HEAD request. $expected_response = $this->getExpectedCollectionResponse($entity_collection, $collection_url->toString(), $request_options); - $expected_cacheability = $expected_response->getCacheableMetadata(); + $expected_cacheability = $expected_response->getCacheabilityMetadata(); $response = $this->request('HEAD', $collection_url, $request_options); $this->assertResourceResponse(200, NULL, $response, $expected_cacheability->getCacheTags(), $expected_cacheability->getCacheContexts(), FALSE, $dynamic_cache); // 200 for well-formed GET request. $expected_response = $this->getExpectedCollectionResponse($entity_collection, $collection_url->toString(), $request_options); - $expected_cacheability = $expected_response->getCacheableMetadata(); + $expected_cacheability = $expected_response->getCacheabilityMetadata(); $expected_document = $expected_response->getResponseData(); $response = $this->request('GET', $collection_url, $request_options); // Dynamic Page Cache HIT unless the HEAD request was UNCACHEABLE. @@ -1158,7 +1158,7 @@ public function testCollection() { ]; $filtered_collection_url->setOption('query', $entity_collection_filter + $default_sort); $expected_response = $this->getExpectedCollectionResponse($filtered_entity_collection, $filtered_collection_url->toString(), $request_options, NULL, TRUE); - $expected_cacheability = $expected_response->getCacheableMetadata(); + $expected_cacheability = $expected_response->getCacheabilityMetadata(); $expected_document = $expected_response->getResponseData(); $response = $this->request('GET', $filtered_collection_url, $request_options); // MISS or UNCACHEABLE depends on the collection data. It must not be HIT. @@ -1173,7 +1173,7 @@ public function testCollection() { $filtered_collection_include_url = clone $collection_url; $filtered_collection_include_url->setOption('query', $entity_collection_filter + $include + $default_sort); $expected_response = $this->getExpectedCollectionResponse($filtered_entity_collection, $filtered_collection_include_url->toString(), $request_options, $relationship_field_names, TRUE); - $expected_cacheability = $expected_response->getCacheableMetadata(); + $expected_cacheability = $expected_response->getCacheabilityMetadata(); $expected_cacheability->setCacheTags(array_values(array_diff($expected_cacheability->getCacheTags(), ['4xx-response']))); $expected_document = $expected_response->getResponseData(); $response = $this->request('GET', $filtered_collection_include_url, $request_options); @@ -1193,7 +1193,7 @@ public function testCollection() { $flattened_permissions = array_unique(array_reduce($applicable_permissions, 'array_merge', [])); $this->grantPermissionsToTestedRole($flattened_permissions); $expected_response = $this->getExpectedCollectionResponse($filtered_entity_collection, $filtered_collection_include_url->toString(), $request_options, $relationship_field_names, TRUE); - $expected_cacheability = $expected_response->getCacheableMetadata(); + $expected_cacheability = $expected_response->getCacheabilityMetadata(); $expected_document = $expected_response->getResponseData(); $response = $this->request('GET', $filtered_collection_include_url, $request_options); $requires_include_only_permissions = !empty($flattened_permissions); @@ -1211,7 +1211,7 @@ public function testCollection() { $sorted_collection_include_url = clone $collection_url; $sorted_collection_include_url->setOption('query', $include + ['sort' => "-id"]); $expected_response = $this->getExpectedCollectionResponse($sorted_entity_collection, $sorted_collection_include_url->toString(), $request_options, $relationship_field_names); - $expected_cacheability = $expected_response->getCacheableMetadata(); + $expected_cacheability = $expected_response->getCacheabilityMetadata(); $expected_cacheability->setCacheTags(array_values(array_diff($expected_cacheability->getCacheTags(), ['4xx-response']))); $expected_document = $expected_response->getResponseData(); $response = $this->request('GET', $sorted_collection_include_url, $request_options); @@ -1251,7 +1251,7 @@ protected function getExpectedCollectionResponse(array $collection, $self_link, } $cacheability = static::getExpectedCollectionCacheability($this->account, $collection, NULL, $filtered); - $cacheability->setCacheMaxAge($merged_response->getCacheableMetadata()->getCacheMaxAge()); + $cacheability->setCacheMaxAge($merged_response->getCacheabilityMetadata()->getCacheMaxAge()); $collection_response = ResourceResponse::create($merged_document); $collection_response->addCacheableDependency($cacheability); @@ -1364,7 +1364,7 @@ protected function doTestRelated(array $request_options) { $actual_response = $related_responses[$relationship_field_name]; // Dynamic Page Cache miss because cache should vary based on the // 'include' query param. - $expected_cacheability = $expected_resource_response->getCacheableMetadata(); + $expected_cacheability = $expected_resource_response->getCacheabilityMetadata(); $this->assertResourceResponse( $expected_resource_response->getStatusCode(), $expected_resource_response->getResponseData(), @@ -1400,7 +1400,7 @@ protected function doTestRelationshipGet(array $request_options) { foreach ($relationship_field_names as $relationship_field_name) { $expected_resource_response = $this->getExpectedGetRelationshipResponse($relationship_field_name); $expected_document = $expected_resource_response->getResponseData(); - $expected_cacheability = $expected_resource_response->getCacheableMetadata(); + $expected_cacheability = $expected_resource_response->getCacheabilityMetadata(); $actual_response = $related_responses[$relationship_field_name]; $this->assertResourceResponse( $expected_resource_response->getStatusCode(), @@ -1683,7 +1683,7 @@ protected function getExpectedGetRelationshipResponse($relationship_field_name, return static::getAccessDeniedResponse($this->entity, $access, $via_link, $relationship_field_name, 'The current user is not allowed to view this relationship.', FALSE); } $expected_document = $this->getExpectedGetRelationshipDocument($relationship_field_name, $entity); - $expected_cacheability = (new CacheableMetadata()) + $expected_cacheability = (new CacheabilityMetadata()) ->addCacheTags(['http_response']) ->addCacheContexts([ 'url.site', @@ -1838,7 +1838,7 @@ protected function getExpectedRelatedResponse($relationship_field_name, array $r // Drupal defaults. 'url.site', ], $this->entity->getEntityType()->isRevisionable() ? ['url.query_args:resourceVersion'] : []); - $cacheability = (new CacheableMetadata())->addCacheContexts($cache_contexts)->addCacheTags(['http_response']); + $cacheability = (new CacheabilityMetadata())->addCacheContexts($cache_contexts)->addCacheTags(['http_response']); $related_response = isset($relationship_document['errors']) ? $relationship_response : (new ResourceResponse(static::getEmptyCollectionResponse(!is_null($relationship_document['data']), $self_link)->getResponseData()))->addCacheableDependency($cacheability); @@ -1860,7 +1860,7 @@ protected function getExpectedRelatedResponse($relationship_field_name, array $r $related_response = static::getEmptyCollectionResponse(!$is_to_one_relationship, $self_link); } } - $related_response->addCacheableDependency($relationship_response->getCacheableMetadata()); + $related_response->addCacheableDependency($relationship_response->getCacheabilityMetadata()); } return $related_response; } @@ -2545,7 +2545,7 @@ protected function getModifiedEntityForPostTesting() { */ protected function doTestSparseFieldSets(Url $url, array $request_options) { $field_sets = $this->getSparseFieldSets(); - $expected_cacheability = new CacheableMetadata(); + $expected_cacheability = new CacheabilityMetadata(); foreach ($field_sets as $type => $field_set) { if ($type === 'all') { assert($this->getExpectedCacheTags($field_set) === $this->getExpectedCacheTags()); @@ -2649,7 +2649,7 @@ protected function doTestIncluded(Url $url, array $request_options) { $expected_document = $expected_response->getResponseData(); // Dynamic Page Cache miss because cache should vary based on the // 'include' query param. - $expected_cacheability = $expected_response->getCacheableMetadata(); + $expected_cacheability = $expected_response->getCacheabilityMetadata(); // MISS or UNCACHEABLE depends on data. It must not be HIT. $dynamic_cache = ($expected_cacheability->getCacheMaxAge() === 0 || !empty(array_intersect(['user', 'session'], $this->getExpectedCacheContexts()))) ? 'UNCACHEABLE' : 'MISS'; $this->assertResourceResponse( @@ -2895,7 +2895,7 @@ public function testRevisions() { $actual_response = $this->request('GET', $rel_latest_version_collection_url, $request_options); $expected_response = $this->getExpectedCollectionResponse([$entity], $rel_latest_version_collection_url->toString(), $request_options); $expected_collection_document = $expected_response->getResponseData(); - $expected_cacheability = $expected_response->getCacheableMetadata(); + $expected_cacheability = $expected_response->getCacheabilityMetadata(); $this->assertResourceResponse(200, $expected_collection_document, $actual_response, $expected_cacheability->getCacheTags(), $expected_cacheability->getCacheContexts(), FALSE, 'MISS'); // Fetch the published revision by using the `working-copy` version // argument. With content_moderation, this is always the most recent @@ -2984,7 +2984,7 @@ public function testRevisions() { $expected_response = static::getExpectedCollectionResponse([$entity], $rel_working_copy_collection_url->toString(), $request_options); $expected_collection_document = $expected_response->getResponseData(); $expected_collection_document['data'] = []; - $expected_cacheability = $expected_response->getCacheableMetadata(); + $expected_cacheability = $expected_response->getCacheabilityMetadata(); $access_denied_response = static::getAccessDeniedResponse($entity, $result, $url, NULL, $detail)->getResponseData(); static::addOmittedObject($expected_collection_document, static::errorsToOmittedObject($access_denied_response['errors'])); $this->assertResourceResponse(200, $expected_collection_document, $actual_response, $expected_cacheability->getCacheTags(), $expected_cacheability->getCacheContexts(), FALSE, 'MISS'); @@ -3020,7 +3020,7 @@ public function testRevisions() { $expected_response = static::getExpectedCollectionResponse([$entity], $rel_working_copy_collection_url->toString(), $request_options); $expected_collection_document = $expected_response->getResponseData(); $expected_collection_document['data'] = [$expected_document['data']]; - $expected_cacheability = $expected_response->getCacheableMetadata(); + $expected_cacheability = $expected_response->getCacheabilityMetadata(); $this->assertResourceResponse(200, $expected_collection_document, $actual_response, $expected_cacheability->getCacheTags(), $expected_cacheability->getCacheContexts(), FALSE, 'MISS'); // Test relationship responses. @@ -3064,7 +3064,7 @@ public function testRevisions() { $actual_response = $this->request('GET', $relationship_url, $request_options); $expected_response = $this->getExpectedGetRelationshipResponse('field_jsonapi_test_entity_ref', $revision); $expected_document = $expected_response->getResponseData(); - $expected_cacheability = $expected_response->getCacheableMetadata(); + $expected_cacheability = $expected_response->getCacheabilityMetadata(); $expected_document['errors'][0]['links']['via']['href'] = $relationship_url->toString(); $this->assertResourceResponse(403, $expected_document, $actual_response, $expected_cacheability->getCacheTags(), $expected_cacheability->getCacheContexts()); // Request the related route. @@ -3072,7 +3072,7 @@ public function testRevisions() { // @todo: refactor self::getExpectedRelatedResponses() into a function which returns a single response. $expected_response = $this->getExpectedRelatedResponses(['field_jsonapi_test_entity_ref'], $request_options, $revision)['field_jsonapi_test_entity_ref']; $expected_document = $expected_response->getResponseData(); - $expected_cacheability = $expected_response->getCacheableMetadata(); + $expected_cacheability = $expected_response->getCacheabilityMetadata(); $expected_document['errors'][0]['links']['via']['href'] = $related_url->toString(); $this->assertResourceResponse(403, $expected_document, $actual_response, $expected_cacheability->getCacheTags(), $expected_cacheability->getCacheContexts()); } @@ -3089,13 +3089,13 @@ public function testRevisions() { $actual_response = $this->request('GET', $relationship_url, $request_options); $expected_response = $this->getExpectedGetRelationshipResponse('field_jsonapi_test_entity_ref', $revision); $expected_document = $expected_response->getResponseData(); - $expected_cacheability = $expected_response->getCacheableMetadata(); + $expected_cacheability = $expected_response->getCacheabilityMetadata(); $this->assertResourceResponse(200, $expected_document, $actual_response, $expected_cacheability->getCacheTags(), $expected_cacheability->getCacheContexts(), FALSE, 'MISS'); // Request the related route. $actual_response = $this->request('GET', $related_url, $request_options); $expected_response = $this->getExpectedRelatedResponse('field_jsonapi_test_entity_ref', $request_options, $revision); $expected_document = $expected_response->getResponseData(); - $expected_cacheability = $expected_response->getCacheableMetadata(); + $expected_cacheability = $expected_response->getCacheabilityMetadata(); $expected_document['links']['self']['href'] = $related_url->toString(); // MISS or UNCACHEABLE depends on data. It must not be HIT. $dynamic_cache = !empty(array_intersect(['user', 'session'], $expected_cacheability->getCacheContexts())) ? 'UNCACHEABLE' : 'MISS'; @@ -3166,10 +3166,10 @@ public function testRevisions() { */ protected static function decorateExpectedResponseForIncludedFields(ResourceResponse $expected_response, array $related_responses) { $expected_document = $expected_response->getResponseData(); - $expected_cacheability = $expected_response->getCacheableMetadata(); + $expected_cacheability = $expected_response->getCacheabilityMetadata(); foreach ($related_responses as $related_response) { $related_document = $related_response->getResponseData(); - $expected_cacheability->addCacheableDependency($related_response->getCacheableMetadata()); + $expected_cacheability->addCacheableDependency($related_response->getCacheabilityMetadata()); $expected_cacheability->setCacheTags(array_values(array_diff($expected_cacheability->getCacheTags(), ['4xx-response']))); // If any of the related response documents had omitted items or errors, // we should later expect the document to have omitted items as well. @@ -3202,7 +3202,7 @@ protected static function decorateExpectedResponseForIncludedFields(ResourceResp */ protected function getExpectedGetIndividualResourceResponse($status_code = 200) { $resource_response = new ResourceResponse($this->getExpectedDocument(), $status_code); - $cacheability = new CacheableMetadata(); + $cacheability = new CacheabilityMetadata(); $cacheability->setCacheContexts($this->getExpectedCacheContexts()); $cacheability->setCacheTags($this->getExpectedCacheTags()); return $resource_response->addCacheableDependency($cacheability); diff --git a/core/modules/jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php b/core/modules/jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php index 7270b63af2..1631d4f327 100644 --- a/core/modules/jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php +++ b/core/modules/jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php @@ -244,7 +244,7 @@ public function testGetCollection() { 'node:3', 'node:4', 'node_list', - ], $response->getCacheableMetadata()->getCacheTags()); + ], $response->getCacheabilityMetadata()->getCacheTags()); } /** @@ -268,7 +268,7 @@ public function testGetFilteredCollection() { 'config:node.type.article', 'config:node_type_list', ]; - $this->assertSame($expected_cache_tags, $response->getCacheableMetadata()->getCacheTags()); + $this->assertSame($expected_cache_tags, $response->getCacheabilityMetadata()->getCacheTags()); } /** @@ -295,7 +295,7 @@ public function testGetSortedCollection() { 'config:node.type.lorem', 'config:node_type_list', ]; - $this->assertSame($expected_cache_tags, $response->getCacheableMetadata()->getCacheTags()); + $this->assertSame($expected_cache_tags, $response->getCacheabilityMetadata()->getCacheTags()); } /** @@ -323,7 +323,7 @@ public function testGetPagedCollection() { $data = $response->getResponseData()->getData(); $this->assertCount(1, $data); $this->assertEquals($this->node2->uuid(), $data->toArray()[0]->getId()); - $this->assertEquals(['node:2', 'node_list'], $response->getCacheableMetadata()->getCacheTags()); + $this->assertEquals(['node:2', 'node_list'], $response->getCacheabilityMetadata()->getCacheTags()); } /** @@ -341,7 +341,7 @@ public function testGetEmptyCollection() { $this->assertInstanceOf(JsonApiDocumentTopLevel::class, $response->getResponseData()); $this->assertInstanceOf(Data::class, $response->getResponseData()->getData()); $this->assertEquals(0, $response->getResponseData()->getData()->count()); - $this->assertEquals(['node_list'], $response->getCacheableMetadata()->getCacheTags()); + $this->assertEquals(['node_list'], $response->getCacheabilityMetadata()->getCacheTags()); } /** @@ -359,7 +359,7 @@ public function testGetRelated() { $this->assertInstanceOf(JsonApiDocumentTopLevel::class, $response->getResponseData()); $this->assertInstanceOf(ResourceObject::class, $response->getResponseData()->getData()->toArray()[0]); $this->assertEquals($this->user->uuid(), $response->getResponseData()->getData()->toArray()[0]->getId()); - $this->assertEquals(['node:1'], $response->getCacheableMetadata()->getCacheTags()); + $this->assertEquals(['node:1'], $response->getCacheabilityMetadata()->getCacheTags()); // to-many relationship. $response = $this->entityResource->getRelated($resource_type, $this->node4, 'field_relationships', Request::create('/jsonapi/node/article/' . $this->node4->uuid(), '/field_relationships')); $this->assertInstanceOf(JsonApiDocumentTopLevel::class, $response @@ -367,7 +367,7 @@ public function testGetRelated() { $this->assertInstanceOf(Data::class, $response ->getResponseData() ->getData()); - $this->assertEquals(['node:4'], $response->getCacheableMetadata()->getCacheTags()); + $this->assertEquals(['node:4'], $response->getCacheabilityMetadata()->getCacheTags()); } /** diff --git a/core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php b/core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php index b1398d0cd9..bdd973a15b 100644 --- a/core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php +++ b/core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php @@ -4,7 +4,7 @@ use Drupal\Component\Serialization\Json; use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Url; use Drupal\file\Entity\File; @@ -677,16 +677,16 @@ protected function denormalizeUuidProviderBuilder(array $options) { /** * Ensure that cacheability metadata is properly added. * - * @param \Drupal\Core\Cache\CacheableMetadata $expected_metadata + * @param \Drupal\Core\Cache\CacheabilityMetadata $expected_metadata * The expected cacheable metadata. * @param array|null $fields * Fields to include in the response, keyed by resource type. * @param array|null $includes * Resources paths to include in the response. * - * @dataProvider testCacheableMetadataProvider + * @dataProvider testCacheabilityMetadataProvider */ - public function testCacheableMetadata(CacheableMetadata $expected_metadata, $fields = NULL, $includes = NULL) { + public function testCacheabilityMetadata(CacheabilityMetadata $expected_metadata, $fields = NULL, $includes = NULL) { list($request, $resource_type) = $this->generateProphecies('node', 'article'); $resource_object = ResourceObject::createFromEntity($resource_type, $this->node); $context = [ @@ -702,14 +702,14 @@ public function testCacheableMetadata(CacheableMetadata $expected_metadata, $fie /** * Provides test cases for asserting cacheable metadata behavior. */ - public function testCacheableMetadataProvider() { - $cacheable_metadata = function ($metadata) { - return CacheableMetadata::createFromRenderArray(['#cache' => $metadata]); + public function testCacheabilityMetadataProvider() { + $cacheability_metadata = function ($metadata) { + return CacheabilityMetadata::createFromRenderArray(['#cache' => $metadata]); }; return [ [ - $cacheable_metadata(['contexts' => ['languages:language_interface']]), + $cacheability_metadata(['contexts' => ['languages:language_interface']]), ['node--article' => 'body'], ], ]; diff --git a/core/modules/language/src/Config/LanguageConfigFactoryOverride.php b/core/modules/language/src/Config/LanguageConfigFactoryOverride.php index 11fcb925b3..dc3b2e6097 100644 --- a/core/modules/language/src/Config/LanguageConfigFactoryOverride.php +++ b/core/modules/language/src/Config/LanguageConfigFactoryOverride.php @@ -2,7 +2,7 @@ namespace Drupal\language\Config; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Config\ConfigCollectionInfo; use Drupal\Core\Config\ConfigCrudEvent; use Drupal\Core\Config\ConfigFactoryOverrideBase; @@ -226,8 +226,8 @@ public function onConfigDelete(ConfigCrudEvent $event) { /** * {@inheritdoc} */ - public function getCacheableMetadata($name) { - $metadata = new CacheableMetadata(); + public function getCacheabilityMetadata($name) { + $metadata = new CacheabilityMetadata(); if ($this->language) { $metadata->setCacheContexts(['languages:language_interface']); } diff --git a/core/modules/layout_builder/layout_builder.module b/core/modules/layout_builder/layout_builder.module index f03e73afd0..d0274cb59a 100644 --- a/core/modules/layout_builder/layout_builder.module +++ b/core/modules/layout_builder/layout_builder.module @@ -6,7 +6,7 @@ */ use Drupal\Core\Breadcrumb\Breadcrumb; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Form\FormStateInterface; @@ -340,7 +340,7 @@ function layout_builder_system_breadcrumb_alter(Breadcrumb &$breadcrumb, RouteMa }); // Links cannot be removed from an existing breadcrumb object. Create a new // object but carry over the cacheable metadata. - $cacheability = CacheableMetadata::createFromObject($breadcrumb); + $cacheability = CacheabilityMetadata::createFromObject($breadcrumb); $breadcrumb = new Breadcrumb(); $breadcrumb->setLinks($links); $breadcrumb->addCacheableDependency($cacheability); diff --git a/core/modules/layout_builder/src/Cache/LayoutBuilderIsActiveCacheContext.php b/core/modules/layout_builder/src/Cache/LayoutBuilderIsActiveCacheContext.php index 5edec7f0e5..b9df59b524 100644 --- a/core/modules/layout_builder/src/Cache/LayoutBuilderIsActiveCacheContext.php +++ b/core/modules/layout_builder/src/Cache/LayoutBuilderIsActiveCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\layout_builder\Cache; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\Context\CalculatedCacheContextInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\layout_builder\OverridesSectionStorageInterface; @@ -58,16 +58,16 @@ public function getContext($entity_type_id = NULL) { /** * {@inheritdoc} */ - public function getCacheableMetadata($entity_type_id = NULL) { + public function getCacheabilityMetadata($entity_type_id = NULL) { if (!$entity_type_id) { throw new \LogicException('Missing entity type ID'); } - $cacheable_metadata = new CacheableMetadata(); + $cacheability_metadata = new CacheabilityMetadata(); if ($display = $this->getDisplay($entity_type_id)) { - $cacheable_metadata->addCacheableDependency($display); + $cacheability_metadata->addCacheableDependency($display); } - return $cacheable_metadata; + return $cacheability_metadata; } /** diff --git a/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php b/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php index 82c8210c23..4d2c818035 100644 --- a/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php +++ b/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php @@ -5,7 +5,7 @@ use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\DerivativeInspectionInterface; use Drupal\Component\Plugin\PluginBase; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Entity\Entity\EntityViewDisplay as BaseEntityViewDisplay; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\FieldableEntityInterface; @@ -289,7 +289,7 @@ protected function buildSections(FieldableEntityInterface $entity) { ]); $contexts['layout_builder.entity'] = EntityContext::fromEntity($entity, $label); - $cacheability = new CacheableMetadata(); + $cacheability = new CacheabilityMetadata(); $storage = $this->sectionStorageManager()->findByContext($contexts, $cacheability); $build = []; @@ -340,7 +340,7 @@ protected function getRuntimeSections(FieldableEntityInterface $entity) { // For backwards compatibility, mimic the functionality of ::buildSections() // by constructing a cacheable metadata object and retrieving the // entity-based contexts. - $cacheability = new CacheableMetadata(); + $cacheability = new CacheabilityMetadata(); $contexts = $this->getContextsForEntity($entity); $storage = $this->sectionStorageManager()->findByContext($contexts, $cacheability); return $storage ? $storage->getSections() : []; diff --git a/core/modules/layout_builder/src/LayoutEntityHelperTrait.php b/core/modules/layout_builder/src/LayoutEntityHelperTrait.php index e1c4216ce7..a8268c42ae 100644 --- a/core/modules/layout_builder/src/LayoutEntityHelperTrait.php +++ b/core/modules/layout_builder/src/LayoutEntityHelperTrait.php @@ -3,7 +3,7 @@ namespace Drupal\layout_builder; use Drupal\Component\Plugin\DerivativeInspectionInterface; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\FieldableEntityInterface; @@ -120,7 +120,7 @@ protected function getSectionStorageForEntity(EntityInterface $entity) { $contexts['view_mode'] = new Context(new ContextDefinition('string'), $view_mode); } } - return $this->sectionStorageManager()->findByContext($contexts, new CacheableMetadata()); + return $this->sectionStorageManager()->findByContext($contexts, new CacheabilityMetadata()); } /** diff --git a/core/modules/layout_builder/src/Plugin/Block/ExtraFieldBlock.php b/core/modules/layout_builder/src/Plugin/Block/ExtraFieldBlock.php index c42d628823..86209fdf99 100644 --- a/core/modules/layout_builder/src/Plugin/Block/ExtraFieldBlock.php +++ b/core/modules/layout_builder/src/Plugin/Block/ExtraFieldBlock.php @@ -3,7 +3,7 @@ namespace Drupal\layout_builder\Plugin\Block; use Drupal\Core\Block\BlockBase; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -133,7 +133,7 @@ public function build() { '#markup' => $this->t('Placeholder for the @preview_fallback', ['@preview_fallback' => $this->getPreviewFallbackString()]), ]; } - CacheableMetadata::createFromObject($this)->applyTo($build); + CacheabilityMetadata::createFromObject($this)->applyTo($build); return $build; } @@ -161,8 +161,8 @@ public function getPreviewFallbackString() { public static function replaceFieldPlaceholder(array &$build, array $built_field, $field_name) { foreach (Element::children($build) as $child) { if (isset($build[$child]['#extra_field_placeholder_field_name']) && $build[$child]['#extra_field_placeholder_field_name'] === $field_name) { - $placeholder_cache = CacheableMetadata::createFromRenderArray($build[$child]); - $built_cache = CacheableMetadata::createFromRenderArray($built_field); + $placeholder_cache = CacheabilityMetadata::createFromRenderArray($build[$child]); + $built_cache = CacheabilityMetadata::createFromRenderArray($built_field); $merged_cache = $placeholder_cache->merge($built_cache); $build[$child] = $built_field; $merged_cache->applyTo($build); diff --git a/core/modules/layout_builder/src/Plugin/Block/FieldBlock.php b/core/modules/layout_builder/src/Plugin/Block/FieldBlock.php index b89f463083..adf6329d5c 100644 --- a/core/modules/layout_builder/src/Plugin/Block/FieldBlock.php +++ b/core/modules/layout_builder/src/Plugin/Block/FieldBlock.php @@ -6,7 +6,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Access\AccessResult; use Drupal\Core\Block\BlockBase; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Entity\EntityDisplayBase; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\FieldableEntityInterface; @@ -167,7 +167,7 @@ public function build() { $build = []; $this->logger->warning('The field "%field" failed to render with the error of "%error".', ['%field' => $this->fieldName, '%error' => $e->getMessage()]); } - CacheableMetadata::createFromObject($this)->applyTo($build); + CacheabilityMetadata::createFromObject($this)->applyTo($build); return $build; } diff --git a/core/modules/layout_builder/src/QuickEditIntegration.php b/core/modules/layout_builder/src/QuickEditIntegration.php index 5492b4f335..1fc15b11ab 100644 --- a/core/modules/layout_builder/src/QuickEditIntegration.php +++ b/core/modules/layout_builder/src/QuickEditIntegration.php @@ -3,7 +3,7 @@ namespace Drupal\layout_builder; use Drupal\Component\Utility\NestedArray; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityInterface; @@ -104,16 +104,16 @@ public function entityViewAlter(array &$build, EntityInterface $entity, EntityVi return; } - $cacheable_metadata = CacheableMetadata::createFromRenderArray($build); + $cacheability_metadata = CacheabilityMetadata::createFromRenderArray($build); $section_list = $this->sectionStorageManager->findByContext( [ 'display' => EntityContext::fromEntity($display), 'entity' => EntityContext::fromEntity($entity), 'view_mode' => new Context(new ContextDefinition('string'), $display->getMode()), ], - $cacheable_metadata + $cacheability_metadata ); - $cacheable_metadata->applyTo($build); + $cacheability_metadata->applyTo($build); if (empty($section_list)) { return; diff --git a/core/modules/layout_builder/src/SectionComponent.php b/core/modules/layout_builder/src/SectionComponent.php index 4003f7e7e7..0bddd32854 100644 --- a/core/modules/layout_builder/src/SectionComponent.php +++ b/core/modules/layout_builder/src/SectionComponent.php @@ -89,7 +89,7 @@ public function toRenderArray(array $contexts = [], $in_preview = FALSE) { $event = new SectionComponentBuildRenderArrayEvent($this, $contexts, $in_preview); $this->eventDispatcher()->dispatch(LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY, $event); $output = $event->getBuild(); - $event->getCacheableMetadata()->applyTo($output); + $event->getCacheabilityMetadata()->applyTo($output); return $output; } diff --git a/core/modules/layout_builder/tests/fixtures/update/layout-builder-tempstore.php b/core/modules/layout_builder/tests/fixtures/update/layout-builder-tempstore.php index 39ef3d8e66e5084692984fb575e2e9efaa42ae41..92e8133dd2518a1cda686a42a2a4692fae887800 100644 GIT binary patch delta 85 zcmaDE`!jY!B|B?oPG(8viCO_bt4q>WqUd(?@7|7mSr<~0KqTi`=vjYH9 CeiU>7 diff --git a/core/modules/layout_builder/tests/src/Unit/BlockComponentRenderArrayTest.php b/core/modules/layout_builder/tests/src/Unit/BlockComponentRenderArrayTest.php index 7b30433b02..78d91744ba 100644 --- a/core/modules/layout_builder/tests/src/Unit/BlockComponentRenderArrayTest.php +++ b/core/modules/layout_builder/tests/src/Unit/BlockComponentRenderArrayTest.php @@ -133,7 +133,7 @@ public function testOnBuildRender($refinable_dependent_access) { $subscriber->onBuildRender($event); $result = $event->getBuild(); $this->assertEquals($expected_build, $result); - $event->getCacheableMetadata()->applyTo($result); + $event->getCacheabilityMetadata()->applyTo($result); $this->assertEquals($expected_cache, $result); } @@ -208,7 +208,7 @@ public function testOnBuildRenderWithoutPreviewFallbackString($refinable_depende $subscriber->onBuildRender($event); $result = $event->getBuild(); $this->assertEquals($expected_build, $result); - $event->getCacheableMetadata()->applyTo($result); + $event->getCacheabilityMetadata()->applyTo($result); $this->assertEquals($expected_cache, $result); } @@ -266,7 +266,7 @@ public function testOnBuildRenderDenied($refinable_dependent_access) { $subscriber->onBuildRender($event); $result = $event->getBuild(); $this->assertEquals($expected_build, $result); - $event->getCacheableMetadata()->applyTo($result); + $event->getCacheabilityMetadata()->applyTo($result); $this->assertEquals($expected_cache, $result); } @@ -337,7 +337,7 @@ public function testOnBuildRenderInPreview($refinable_dependent_access) { $subscriber->onBuildRender($event); $result = $event->getBuild(); $this->assertEquals($expected_build, $result); - $event->getCacheableMetadata()->applyTo($result); + $event->getCacheabilityMetadata()->applyTo($result); $this->assertEquals($expected_cache, $result); } @@ -397,7 +397,7 @@ public function testOnBuildRenderInPreviewEmptyBuild() { $subscriber->onBuildRender($event); $result = $event->getBuild(); $this->assertEquals($expected_build, $result); - $event->getCacheableMetadata()->applyTo($result); + $event->getCacheabilityMetadata()->applyTo($result); $this->assertEquals($expected_cache, $result); } @@ -437,7 +437,7 @@ public function testOnBuildRenderEmptyBuild() { $subscriber->onBuildRender($event); $result = $event->getBuild(); $this->assertEquals($expected_build, $result); - $event->getCacheableMetadata()->applyTo($result); + $event->getCacheabilityMetadata()->applyTo($result); $this->assertEquals($expected_cache, $result); } @@ -466,7 +466,7 @@ public function testOnBuildRenderNoBlock() { $subscriber->onBuildRender($event); $result = $event->getBuild(); $this->assertEquals($expected_build, $result); - $event->getCacheableMetadata()->applyTo($result); + $event->getCacheabilityMetadata()->applyTo($result); $this->assertEquals($expected_cache, $result); } diff --git a/core/modules/layout_builder/tests/src/Unit/SectionStorageManagerTest.php b/core/modules/layout_builder/tests/src/Unit/SectionStorageManagerTest.php index b3b99d1fcd..e24c66cdef 100644 --- a/core/modules/layout_builder/tests/src/Unit/SectionStorageManagerTest.php +++ b/core/modules/layout_builder/tests/src/Unit/SectionStorageManagerTest.php @@ -7,7 +7,7 @@ use Drupal\Component\Plugin\Exception\ContextException; use Drupal\Component\Plugin\Factory\FactoryInterface; use Drupal\Core\Cache\CacheableDependencyInterface; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\Context\Context; @@ -209,7 +209,7 @@ public function testFindDefinitions() { * The result for the plugin's isApplicable() method to return. */ public function testFindByContext($plugin_is_applicable) { - $cacheability = new CacheableMetadata(); + $cacheability = new CacheabilityMetadata(); $contexts = [ 'foo' => new Context(new ContextDefinition('foo')), ]; @@ -263,7 +263,7 @@ public function providerTestFindByContext() { * @covers ::findByContext */ public function testFindByContextCacheableSectionStorage() { - $cacheability = new CacheableMetadata(); + $cacheability = new CacheabilityMetadata(); $contexts = [ 'foo' => new Context(new ContextDefinition('foo')), ]; diff --git a/core/modules/media/src/Controller/OEmbedIframeController.php b/core/modules/media/src/Controller/OEmbedIframeController.php index a001145568..6ec0fcb103 100644 --- a/core/modules/media/src/Controller/OEmbedIframeController.php +++ b/core/modules/media/src/Controller/OEmbedIframeController.php @@ -3,7 +3,7 @@ namespace Drupal\media\Controller; use Drupal\Component\Utility\Crypt; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Render\HtmlResponse; use Drupal\Core\Render\RenderContext; @@ -172,7 +172,7 @@ public function render(Request $request) { ->setContent($content) ->setAttachments($element['#attached']) ->addCacheableDependency($resource) - ->addCacheableDependency(CacheableMetadata::createFromRenderArray($element)); + ->addCacheableDependency(CacheabilityMetadata::createFromRenderArray($element)); } catch (ResourceException $e) { // Prevent the response from being cached. diff --git a/core/modules/media/src/Plugin/Field/FieldFormatter/OEmbedFormatter.php b/core/modules/media/src/Plugin/Field/FieldFormatter/OEmbedFormatter.php index 65d601eb63..935427d8ab 100644 --- a/core/modules/media/src/Plugin/Field/FieldFormatter/OEmbedFormatter.php +++ b/core/modules/media/src/Plugin/Field/FieldFormatter/OEmbedFormatter.php @@ -2,7 +2,7 @@ namespace Drupal\media\Plugin\Field\FieldFormatter; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemListInterface; @@ -229,7 +229,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) { ], ]; - CacheableMetadata::createFromObject($resource) + CacheabilityMetadata::createFromObject($resource) ->addCacheTags($this->config->getCacheTags()) ->applyTo($element[$delta]); } diff --git a/core/modules/menu_ui/menu_ui.module b/core/modules/menu_ui/menu_ui.module index 1e2d9a051c..aa34e3d84d 100644 --- a/core/modules/menu_ui/menu_ui.module +++ b/core/modules/menu_ui/menu_ui.module @@ -10,7 +10,7 @@ use Drupal\Core\Url; use Drupal\Core\Breadcrumb\Breadcrumb; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Block\BlockPluginInterface; use Drupal\Core\Link; use Drupal\Core\Menu\MenuLinkInterface; @@ -382,7 +382,7 @@ function menu_ui_form_node_type_form_alter(&$form, FormStateInterface $form_stat // To avoid an 'illegal option' error after saving the form we have to load // all available menu parents. Otherwise, it is not possible to dynamically // add options to the list using ajax. - $options_cacheability = new CacheableMetadata(); + $options_cacheability = new CacheabilityMetadata(); $options = $menu_parent_selector->getParentSelectOptions('', NULL, $options_cacheability); $form['menu']['menu_parent'] = [ '#type' => 'select', diff --git a/core/modules/menu_ui/src/MenuForm.php b/core/modules/menu_ui/src/MenuForm.php index 74ec5fbb41..863427132a 100644 --- a/core/modules/menu_ui/src/MenuForm.php +++ b/core/modules/menu_ui/src/MenuForm.php @@ -3,7 +3,7 @@ namespace Drupal\menu_ui; use Drupal\Component\Utility\NestedArray; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Entity\EntityForm; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; @@ -383,9 +383,9 @@ protected function buildOverviewForm(array &$form, FormStateInterface $form_stat */ protected function buildOverviewTreeForm($tree, $delta) { $form = &$this->overviewTreeForm; - $tree_access_cacheability = new CacheableMetadata(); + $tree_access_cacheability = new CacheabilityMetadata(); foreach ($tree as $element) { - $tree_access_cacheability = $tree_access_cacheability->merge(CacheableMetadata::createFromObject($element->access)); + $tree_access_cacheability = $tree_access_cacheability->merge(CacheabilityMetadata::createFromObject($element->access)); // Only render accessible links. if (!$element->access->isAllowed()) { @@ -480,7 +480,7 @@ protected function buildOverviewTreeForm($tree, $delta) { } $tree_access_cacheability - ->merge(CacheableMetadata::createFromRenderArray($form)) + ->merge(CacheabilityMetadata::createFromRenderArray($form)) ->applyTo($form); return $form; diff --git a/core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php b/core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php index 9112d81b51..e01192dbcf 100644 --- a/core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php +++ b/core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\node\Cache; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\Context\CalculatedCacheContextInterface; use Drupal\Core\Cache\Context\UserCacheContextBase; @@ -81,21 +81,21 @@ protected function checkNodeGrants($operation) { /** * {@inheritdoc} */ - public function getCacheableMetadata($operation = NULL) { - $cacheable_metadata = new CacheableMetadata(); + public function getCacheabilityMetadata($operation = NULL) { + $cacheability_metadata = new CacheabilityMetadata(); if (!\Drupal::moduleHandler()->getImplementations('node_grants')) { - return $cacheable_metadata; + return $cacheability_metadata; } // The node grants may change if the user is updated. (The max-age is set to // zero below, but sites may override this cache context, and change it to a // non-zero value. In such cases, this cache tag is needed for correctness.) - $cacheable_metadata->setCacheTags(['user:' . $this->user->id()]); + $cacheability_metadata->setCacheTags(['user:' . $this->user->id()]); // If the site is using node grants, this cache context can not be // optimized. - return $cacheable_metadata->setCacheMaxAge(0); + return $cacheability_metadata->setCacheMaxAge(0); } } diff --git a/core/modules/node/src/ContextProvider/NodeRouteContext.php b/core/modules/node/src/ContextProvider/NodeRouteContext.php index 8f0acd7de9..06d13f253b 100644 --- a/core/modules/node/src/ContextProvider/NodeRouteContext.php +++ b/core/modules/node/src/ContextProvider/NodeRouteContext.php @@ -2,7 +2,7 @@ namespace Drupal\node\ContextProvider; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Plugin\Context\Context; use Drupal\Core\Plugin\Context\ContextProviderInterface; use Drupal\Core\Plugin\Context\EntityContext; @@ -52,7 +52,7 @@ public function getRuntimeContexts(array $unqualified_context_ids) { $value = Node::create(['type' => $node_type->id()]); } - $cacheability = new CacheableMetadata(); + $cacheability = new CacheabilityMetadata(); $cacheability->setCacheContexts(['route']); $context = new Context($context_definition, $value); diff --git a/core/modules/node/src/Plugin/Search/NodeSearch.php b/core/modules/node/src/Plugin/Search/NodeSearch.php index 1065568c9d..0111b8830f 100644 --- a/core/modules/node/src/Plugin/Search/NodeSearch.php +++ b/core/modules/node/src/Plugin/Search/NodeSearch.php @@ -3,7 +3,7 @@ namespace Drupal\node\Plugin\Search; use Drupal\Core\Access\AccessResult; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Config\Config; use Drupal\Core\Database\Connection; use Drupal\Core\Database\Database; @@ -364,7 +364,7 @@ protected function prepareResults(StatementInterface $found) { // Fetch comments for snippet. $rendered = $this->renderer->renderPlain($build); - $this->addCacheableDependency(CacheableMetadata::createFromRenderArray($build)); + $this->addCacheableDependency(CacheabilityMetadata::createFromRenderArray($build)); $rendered .= ' ' . $this->moduleHandler->invoke('comment', 'node_update_index', [$node]); $extra = $this->moduleHandler->invokeAll('node_search_result', [$node]); diff --git a/core/modules/page_cache/src/StackMiddleware/PageCache.php b/core/modules/page_cache/src/StackMiddleware/PageCache.php index ba07414d63..83947ef37c 100644 --- a/core/modules/page_cache/src/StackMiddleware/PageCache.php +++ b/core/modules/page_cache/src/StackMiddleware/PageCache.php @@ -278,7 +278,7 @@ protected function storeResponse(Request $request, Response $response) { } if ($expire === Cache::PERMANENT || $expire > $request_time) { - $tags = $response->getCacheableMetadata()->getCacheTags(); + $tags = $response->getCacheabilityMetadata()->getCacheTags(); $this->set($request, $response, $expire, $tags); } diff --git a/core/modules/rest/src/EventSubscriber/ResourceResponseSubscriber.php b/core/modules/rest/src/EventSubscriber/ResourceResponseSubscriber.php index 229413f46a..33fffad887 100644 --- a/core/modules/rest/src/EventSubscriber/ResourceResponseSubscriber.php +++ b/core/modules/rest/src/EventSubscriber/ResourceResponseSubscriber.php @@ -2,7 +2,7 @@ namespace Drupal\rest\EventSubscriber; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\CacheableResponse; use Drupal\Core\Cache\CacheableResponseInterface; use Drupal\Core\Render\RenderContext; @@ -164,7 +164,7 @@ protected function renderResponseBody(Request $request, ResourceResponseInterfac if ($data !== NULL) { $serialization_context = [ 'request' => $request, - CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => new CacheableMetadata(), + CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => new CacheabilityMetadata(), ]; // @deprecated In Drupal 8.5.0, will be removed before Drupal 9.0.0. Use @@ -212,7 +212,7 @@ protected function flattenResponse(ResourceResponseInterface $response) { } $final_response->headers = clone $response->headers; if ($final_response instanceof CacheableResponseInterface) { - $final_response->addCacheableDependency($response->getCacheableMetadata()); + $final_response->addCacheableDependency($response->getCacheabilityMetadata()); } return $final_response; } diff --git a/core/modules/rest/src/Plugin/views/display/RestExport.php b/core/modules/rest/src/Plugin/views/display/RestExport.php index 93605b8e95..9bd345be11 100644 --- a/core/modules/rest/src/Plugin/views/display/RestExport.php +++ b/core/modules/rest/src/Plugin/views/display/RestExport.php @@ -2,7 +2,7 @@ namespace Drupal\rest\Plugin\views\display; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\CacheableResponse; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\RenderContext; @@ -424,7 +424,7 @@ public static function buildResponse($view_id, $display_id, array $args = []) { $output = (string) $renderer->renderRoot($build); $response->setContent($output); - $cache_metadata = CacheableMetadata::createFromRenderArray($build); + $cache_metadata = CacheabilityMetadata::createFromRenderArray($build); $response->addCacheableDependency($cache_metadata); $response->headers->set('Content-type', $build['#content_type']); diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php index 15a4501546..2939956bff 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php @@ -7,7 +7,7 @@ use Drupal\Component\Utility\Random; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheableResponseInterface; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Entity\ContentEntityNullStorage; use Drupal\Core\Entity\EntityInterface; @@ -372,7 +372,7 @@ protected function getExpectedUnauthorizedAccessMessage($method) { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessCacheability() { - return (new CacheableMetadata()) + return (new CacheabilityMetadata()) ->setCacheTags(static::$auth ? ['4xx-response', 'http_response'] : ['4xx-response', 'config:user.role.anonymous', 'http_response']) @@ -386,11 +386,11 @@ protected function getExpectedUnauthorizedAccessCacheability() { * Whether the current request is authenticated or not. This matters for * some entity access control handlers, but not for most. * - * @return \Drupal\Core\Cache\CacheableMetadata + * @return \Drupal\Core\Cache\CacheabilityMetadata * The expected cacheability. */ protected function getExpectedUnauthorizedEntityAccessCacheability($is_authenticated) { - return new CacheableMetadata(); + return new CacheabilityMetadata(); } /** diff --git a/core/modules/settings_tray/tests/modules/settings_tray_override_test/src/ConfigOverrider.php b/core/modules/settings_tray/tests/modules/settings_tray_override_test/src/ConfigOverrider.php index 6921fa8e0d..0e19de31f6 100644 --- a/core/modules/settings_tray/tests/modules/settings_tray_override_test/src/ConfigOverrider.php +++ b/core/modules/settings_tray/tests/modules/settings_tray_override_test/src/ConfigOverrider.php @@ -2,7 +2,7 @@ namespace Drupal\settings_tray_override_test; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Config\ConfigFactoryOverrideInterface; use Drupal\Core\Config\StorageInterface; @@ -53,8 +53,8 @@ public function createConfigObject($name, $collection = StorageInterface::DEFAUL /** * {@inheritdoc} */ - public function getCacheableMetadata($name) { - return new CacheableMetadata(); + public function getCacheabilityMetadata($name) { + return new CacheabilityMetadata(); } } diff --git a/core/modules/simpletest/src/Cache/Context/TestDiscoveryCacheContext.php b/core/modules/simpletest/src/Cache/Context/TestDiscoveryCacheContext.php index e3d5cf351d..d1fc139381 100644 --- a/core/modules/simpletest/src/Cache/Context/TestDiscoveryCacheContext.php +++ b/core/modules/simpletest/src/Cache/Context/TestDiscoveryCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\simpletest\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\Context\CacheContextInterface; use Drupal\Core\PrivateKey; use Drupal\Core\Site\Settings; @@ -74,8 +74,8 @@ public function getContext() { /** * {@inheritdoc} */ - public function getCacheableMetadata() { - return new CacheableMetadata(); + public function getCacheabilityMetadata() { + return new CacheabilityMetadata(); } /** diff --git a/core/modules/system/src/Controller/SystemController.php b/core/modules/system/src/Controller/SystemController.php index 106f4e2915..41074ce398 100644 --- a/core/modules/system/src/Controller/SystemController.php +++ b/core/modules/system/src/Controller/SystemController.php @@ -2,7 +2,7 @@ namespace Drupal\system\Controller; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Extension\ThemeHandlerInterface; use Drupal\Core\Form\FormBuilderInterface; @@ -111,10 +111,10 @@ public function overview($link_id) { ['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'], ]; $tree = $this->menuLinkTree->transform($tree, $manipulators); - $tree_access_cacheability = new CacheableMetadata(); + $tree_access_cacheability = new CacheabilityMetadata(); $blocks = []; foreach ($tree as $key => $element) { - $tree_access_cacheability = $tree_access_cacheability->merge(CacheableMetadata::createFromObject($element->access)); + $tree_access_cacheability = $tree_access_cacheability->merge(CacheabilityMetadata::createFromObject($element->access)); // Only render accessible links. if (!$element->access->isAllowed()) { diff --git a/core/modules/system/tests/modules/common_test/src/Render/MainContent/JsonRenderer.php b/core/modules/system/tests/modules/common_test/src/Render/MainContent/JsonRenderer.php index bcecfbc5f4..a0324ac0d0 100644 --- a/core/modules/system/tests/modules/common_test/src/Render/MainContent/JsonRenderer.php +++ b/core/modules/system/tests/modules/common_test/src/Render/MainContent/JsonRenderer.php @@ -3,7 +3,7 @@ namespace Drupal\common_test\Render\MainContent; use Drupal\Core\Cache\CacheableJsonResponse; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Controller\TitleResolverInterface; use Drupal\Core\Render\MainContent\MainContentRendererInterface; use Drupal\Core\Render\RendererInterface; @@ -57,7 +57,7 @@ public function renderResponse(array $main_content, Request $request, RouteMatch } $response = new CacheableJsonResponse($json, 200); - $response->addCacheableDependency(CacheableMetadata::createFromRenderArray($main_content)); + $response->addCacheableDependency(CacheabilityMetadata::createFromRenderArray($main_content)); return $response; } diff --git a/core/modules/system/tests/modules/display_variant_test/src/Plugin/DisplayVariant/TestDisplayVariant.php b/core/modules/system/tests/modules/display_variant_test/src/Plugin/DisplayVariant/TestDisplayVariant.php index 4280cd416e..09350afb0e 100644 --- a/core/modules/system/tests/modules/display_variant_test/src/Plugin/DisplayVariant/TestDisplayVariant.php +++ b/core/modules/system/tests/modules/display_variant_test/src/Plugin/DisplayVariant/TestDisplayVariant.php @@ -2,7 +2,7 @@ namespace Drupal\display_variant_test\Plugin\DisplayVariant; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Display\VariantBase; use Drupal\Core\Display\PageVariantInterface; use Drupal\Core\Display\ContextAwareVariantInterface; @@ -98,7 +98,7 @@ public function build() { '#markup' => $config['required_configuration'] . ' ' . $contexts['context']->getContextValue(), ]; - CacheableMetadata::createFromObject($this)->applyTo($build); + CacheabilityMetadata::createFromObject($this)->applyTo($build); return $build; } diff --git a/core/modules/system/tests/modules/entity_test/src/Cache/EntityTestViewGrantsCacheContext.php b/core/modules/system/tests/modules/entity_test/src/Cache/EntityTestViewGrantsCacheContext.php index d70dea7c25..1738046650 100644 --- a/core/modules/system/tests/modules/entity_test/src/Cache/EntityTestViewGrantsCacheContext.php +++ b/core/modules/system/tests/modules/entity_test/src/Cache/EntityTestViewGrantsCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\entity_test\Cache; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\Context\CacheContextInterface; /** @@ -33,8 +33,8 @@ public function getContext() { /** * {@inheritdoc} */ - public function getCacheableMetadata() { - return new CacheableMetadata(); + public function getCacheabilityMetadata() { + return new CacheabilityMetadata(); } } diff --git a/core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php b/core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php index cfd0f2f796..2cf42acf1e 100644 --- a/core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php +++ b/core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php @@ -273,7 +273,7 @@ public function setHeader(Request $request) { $query = $request->query->all(); $response = new CacheableResponse(); $response->headers->set($query['name'], $query['value']); - $response->getCacheableMetadata()->addCacheContexts(['url.query_args:name', 'url.query_args:value']); + $response->getCacheabilityMetadata()->addCacheContexts(['url.query_args:name', 'url.query_args:value']); $response->setContent($this->t('The following header was set: %name: %value', ['%name' => $query['name'], '%value' => $query['value']])); return $response; diff --git a/core/modules/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module index 7df073fe60..94faa4041d 100644 --- a/core/modules/toolbar/toolbar.module +++ b/core/modules/toolbar/toolbar.module @@ -5,7 +5,7 @@ * Administration toolbar for quick access to top level administration items. */ -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Menu\MenuTreeParameters; use Drupal\Core\Render\Element; use Drupal\Core\Routing\RouteMatchInterface; @@ -308,7 +308,7 @@ function toolbar_get_rendered_subtrees() { '#cache_properties' => ['#subtrees'], ]; \Drupal::service('renderer')->renderPlain($data); - return [$data['#subtrees'], CacheableMetadata::createFromRenderArray($data)]; + return [$data['#subtrees'], CacheabilityMetadata::createFromRenderArray($data)]; } /** @@ -331,14 +331,14 @@ function _toolbar_do_get_rendered_subtrees(array $data) { $tree = $menu_tree->transform($tree, $manipulators); $subtrees = []; // Calculated the combined cacheability of all subtrees. - $cacheability = new CacheableMetadata(); + $cacheability = new CacheabilityMetadata(); foreach ($tree as $element) { /** @var \Drupal\Core\Menu\MenuLinkInterface $link */ $link = $element->link; if ($element->subtree) { $subtree = $menu_tree->build($element->subtree); $output = \Drupal::service('renderer')->renderPlain($subtree); - $cacheability = $cacheability->merge(CacheableMetadata::createFromRenderArray($subtree)); + $cacheability = $cacheability->merge(CacheabilityMetadata::createFromRenderArray($subtree)); } else { $output = ''; diff --git a/core/modules/user/src/ContextProvider/CurrentUserContext.php b/core/modules/user/src/ContextProvider/CurrentUserContext.php index f1f69ad148..920cad65bf 100644 --- a/core/modules/user/src/ContextProvider/CurrentUserContext.php +++ b/core/modules/user/src/ContextProvider/CurrentUserContext.php @@ -2,7 +2,7 @@ namespace Drupal\user\ContextProvider; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Plugin\Context\ContextProviderInterface; use Drupal\Core\Plugin\Context\EntityContext; @@ -61,7 +61,7 @@ public function getRuntimeContexts(array $unqualified_context_ids) { $context = EntityContext::fromEntityTypeId('user', $this->t('Current user')); } - $cacheability = new CacheableMetadata(); + $cacheability = new CacheabilityMetadata(); $cacheability->setCacheContexts(['user']); $context->addCacheableDependency($cacheability); diff --git a/core/modules/user/src/UserListBuilder.php b/core/modules/user/src/UserListBuilder.php index 8c3cef90df..c87c723e7e 100644 --- a/core/modules/user/src/UserListBuilder.php +++ b/core/modules/user/src/UserListBuilder.php @@ -2,7 +2,7 @@ namespace Drupal\user; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Datetime\DateFormatterInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityListBuilder; @@ -143,7 +143,7 @@ public function buildRow(EntityInterface $entity) { if ($entity->getLastAccessedTime()) { $row['access']['data']['#markup'] = $last_access->getString(); - CacheableMetadata::createFromObject($last_access)->applyTo($row['access']['data']); + CacheabilityMetadata::createFromObject($last_access)->applyTo($row['access']['data']); } else { $row['access']['data']['#markup'] = t('never'); diff --git a/core/modules/views/src/Plugin/views/cache/CachePluginBase.php b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php index 280ccf4d16..5b1c77d61b 100644 --- a/core/modules/views/src/Plugin/views/cache/CachePluginBase.php +++ b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php @@ -3,7 +3,7 @@ namespace Drupal\views\Plugin\views\cache; use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\views\Plugin\views\PluginBase; use Drupal\Core\Database\Query\Select; use Drupal\views\ResultRow; @@ -295,10 +295,10 @@ protected function prepareViewResult(array $result) { /** * Alters the cache metadata of a display upon saving a view. * - * @param \Drupal\Core\Cache\CacheableMetadata $cache_metadata + * @param \Drupal\Core\Cache\CacheabilityMetadata $cache_metadata * The cache metadata. */ - public function alterCacheMetadata(CacheableMetadata $cache_metadata) { + public function alterCacheMetadata(CacheabilityMetadata $cache_metadata) { } /** diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php index 4fe9d1e204..b36b99f899 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php @@ -6,7 +6,7 @@ use Drupal\Component\Utility\Html; use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; @@ -2136,11 +2136,11 @@ protected function applyDisplayCacheabilityMetadata(array &$element) { /** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache */ $cache = $this->getPlugin('cache'); - (new CacheableMetadata()) + (new CacheabilityMetadata()) ->setCacheTags(Cache::mergeTags($this->view->getCacheTags(), isset($this->display['cache_metadata']['tags']) ? $this->display['cache_metadata']['tags'] : [])) ->setCacheContexts(isset($this->display['cache_metadata']['contexts']) ? $this->display['cache_metadata']['contexts'] : []) ->setCacheMaxAge(Cache::mergeMaxAges($cache->getCacheMaxAge(), isset($this->display['cache_metadata']['max-age']) ? $this->display['cache_metadata']['max-age'] : Cache::PERMANENT)) - ->merge(CacheableMetadata::createFromRenderArray($element)) + ->merge(CacheabilityMetadata::createFromRenderArray($element)) ->applyTo($element); } @@ -2280,13 +2280,13 @@ public function preExecute() { * {@inheritdoc} */ public function calculateCacheMetadata() { - $cache_metadata = new CacheableMetadata(); + $cache_metadata = new CacheabilityMetadata(); // Iterate over ordinary views plugins. foreach (Views::getPluginTypes('plugin') as $plugin_type) { $plugin = $this->getPlugin($plugin_type); if ($plugin instanceof CacheableDependencyInterface) { - $cache_metadata = $cache_metadata->merge(CacheableMetadata::createFromObject($plugin)); + $cache_metadata = $cache_metadata->merge(CacheabilityMetadata::createFromObject($plugin)); } } @@ -2296,7 +2296,7 @@ public function calculateCacheMetadata() { $handlers = $this->getHandlers($handler_type); foreach ($handlers as $handler) { if ($handler instanceof CacheableDependencyInterface) { - $cache_metadata = $cache_metadata->merge(CacheableMetadata::createFromObject($handler)); + $cache_metadata = $cache_metadata->merge(CacheabilityMetadata::createFromObject($handler)); } } } @@ -2320,7 +2320,7 @@ public function getCacheMetadata() { $this->display['cache_metadata']['tags'] = $cache_metadata->getCacheTags(); } else { - $cache_metadata = (new CacheableMetadata()) + $cache_metadata = (new CacheabilityMetadata()) ->setCacheMaxAge($this->display['cache_metadata']['max-age']) ->setCacheContexts($this->display['cache_metadata']['contexts']) ->setCacheTags($this->display['cache_metadata']['tags']); diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginInterface.php b/core/modules/views/src/Plugin/views/display/DisplayPluginInterface.php index 80e4783164..e58e99917e 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginInterface.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginInterface.php @@ -437,7 +437,7 @@ public function preExecute(); /** * Calculates the display's cache metadata by inspecting each handler/plugin. * - * @return \Drupal\Core\Cache\CacheableMetadata + * @return \Drupal\Core\Cache\CacheabilityMetadata * The cache metadata. */ public function calculateCacheMetadata(); @@ -445,7 +445,7 @@ public function calculateCacheMetadata(); /** * Gets the cache metadata. * - * @return \Drupal\Core\Cache\CacheableMetadata + * @return \Drupal\Core\Cache\CacheabilityMetadata * The cache metadata. */ public function getCacheMetadata(); diff --git a/core/modules/views/src/Plugin/views/display/Feed.php b/core/modules/views/src/Plugin/views/display/Feed.php index 05169b9a2c..e9aa69c809 100644 --- a/core/modules/views/src/Plugin/views/display/Feed.php +++ b/core/modules/views/src/Plugin/views/display/Feed.php @@ -2,7 +2,7 @@ namespace Drupal\views\Plugin\views\display; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\CacheableResponse; use Drupal\Core\Form\FormStateInterface; use Drupal\views\ViewExecutable; @@ -67,7 +67,7 @@ public static function buildResponse($view_id, $display_id, array $args = []) { } $response->setContent($output); - $cache_metadata = CacheableMetadata::createFromRenderArray($build); + $cache_metadata = CacheabilityMetadata::createFromRenderArray($build); $response->addCacheableDependency($cache_metadata); return $response; diff --git a/core/modules/views/tests/modules/views_test_data/src/Cache/ViewsTestCacheContext.php b/core/modules/views/tests/modules/views_test_data/src/Cache/ViewsTestCacheContext.php index 8fb2d1b435..563450b419 100644 --- a/core/modules/views/tests/modules/views_test_data/src/Cache/ViewsTestCacheContext.php +++ b/core/modules/views/tests/modules/views_test_data/src/Cache/ViewsTestCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\views_test_data\Cache; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\Context\CacheContextInterface; /** @@ -29,8 +29,8 @@ public function getContext() { /** * {@inheritdoc} */ - public function getCacheableMetadata() { - return new CacheableMetadata(); + public function getCacheabilityMetadata() { + return new CacheabilityMetadata(); } } diff --git a/core/modules/workspaces/src/WorkspaceCacheContext.php b/core/modules/workspaces/src/WorkspaceCacheContext.php index a5b697eedc..910151c0e2 100644 --- a/core/modules/workspaces/src/WorkspaceCacheContext.php +++ b/core/modules/workspaces/src/WorkspaceCacheContext.php @@ -2,7 +2,7 @@ namespace Drupal\workspaces; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\Context\CacheContextInterface; /** @@ -46,9 +46,9 @@ public function getContext() { /** * {@inheritdoc} */ - public function getCacheableMetadata($type = NULL) { + public function getCacheabilityMetadata($type = NULL) { // The active workspace will always be stored in the user's session. - $cacheability = new CacheableMetadata(); + $cacheability = new CacheabilityMetadata(); $cacheability->addCacheContexts(['session']); return $cacheability; diff --git a/core/tests/Drupal/Tests/Core/Cache/CacheableMetadataTest.php b/core/tests/Drupal/Tests/Core/Cache/CacheabilityMetadataTest.php similarity index 73% rename from core/tests/Drupal/Tests/Core/Cache/CacheableMetadataTest.php rename to core/tests/Drupal/Tests/Core/Cache/CacheabilityMetadataTest.php index 8b0b759816..d7bb7ea029 100644 --- a/core/tests/Drupal/Tests/Core/Cache/CacheableMetadataTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/CacheabilityMetadataTest.php @@ -3,16 +3,16 @@ namespace Drupal\Tests\Core\Cache; use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Tests\Core\Render\TestCacheableDependency; use Drupal\Tests\UnitTestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; /** - * @coversDefaultClass \Drupal\Core\Cache\CacheableMetadata + * @coversDefaultClass \Drupal\Core\Cache\CacheabilityMetadata * @group Cache */ -class CacheableMetadataTest extends UnitTestCase { +class CacheabilityMetadataTest extends UnitTestCase { /** * @covers ::merge @@ -25,7 +25,7 @@ class CacheableMetadataTest extends UnitTestCase { * @see \Drupal\Tests\Core\Cache\CacheTest::testMergeMaxAges() * @see \Drupal\Tests\Core\Cache\CacheContextsTest */ - public function testMerge(CacheableMetadata $a, CacheableMetadata $b, CacheableMetadata $expected) { + public function testMerge(CacheabilityMetadata $a, CacheabilityMetadata $b, CacheabilityMetadata $expected) { $cache_contexts_manager = $this->getMockBuilder('Drupal\Core\Cache\Context\CacheContextsManager') ->disableOriginalConstructor() ->getMock(); @@ -49,7 +49,7 @@ public function testMerge(CacheableMetadata $a, CacheableMetadata $b, CacheableM * @see \Drupal\Tests\Core\Cache\CacheTest::testMergeMaxAges() * @see \Drupal\Tests\Core\Cache\CacheContextsTest */ - public function testAddCacheableDependency(CacheableMetadata $a, CacheableMetadata $b, CacheableMetadata $expected) { + public function testAddCacheableDependency(CacheabilityMetadata $a, CacheabilityMetadata $b, CacheabilityMetadata $expected) { $cache_contexts_manager = $this->getMockBuilder('Drupal\Core\Cache\Context\CacheContextsManager') ->disableOriginalConstructor() ->getMock(); @@ -69,13 +69,13 @@ public function testAddCacheableDependency(CacheableMetadata $a, CacheableMetada public function providerTestMerge() { return [ // All empty. - [(new CacheableMetadata()), (new CacheableMetadata()), (new CacheableMetadata())], + [(new CacheabilityMetadata()), (new CacheabilityMetadata()), (new CacheabilityMetadata())], // Cache contexts. - [(new CacheableMetadata())->setCacheContexts(['foo']), (new CacheableMetadata())->setCacheContexts(['bar']), (new CacheableMetadata())->setCacheContexts(['bar', 'foo'])], + [(new CacheabilityMetadata())->setCacheContexts(['foo']), (new CacheabilityMetadata())->setCacheContexts(['bar']), (new CacheabilityMetadata())->setCacheContexts(['bar', 'foo'])], // Cache tags. - [(new CacheableMetadata())->setCacheTags(['foo']), (new CacheableMetadata())->setCacheTags(['bar']), (new CacheableMetadata())->setCacheTags(['bar', 'foo'])], + [(new CacheabilityMetadata())->setCacheTags(['foo']), (new CacheabilityMetadata())->setCacheTags(['bar']), (new CacheabilityMetadata())->setCacheTags(['bar', 'foo'])], // Cache max-ages. - [(new CacheableMetadata())->setCacheMaxAge(60), (new CacheableMetadata())->setCacheMaxAge(Cache::PERMANENT), (new CacheableMetadata())->setCacheMaxAge(60)], + [(new CacheabilityMetadata())->setCacheMaxAge(60), (new CacheabilityMetadata())->setCacheMaxAge(Cache::PERMANENT), (new CacheabilityMetadata())->setCacheMaxAge(60)], ]; } @@ -85,7 +85,7 @@ public function providerTestMerge() { * @covers ::addCacheTags */ public function testAddCacheTags() { - $metadata = new CacheableMetadata(); + $metadata = new CacheabilityMetadata(); $add_expected = [ [[], []], [['foo:bar'], ['foo:bar']], @@ -109,7 +109,7 @@ public function testAddCacheTags() { * @dataProvider providerSetCacheMaxAge */ public function testSetCacheMaxAge($data, $expect_exception) { - $metadata = new CacheableMetadata(); + $metadata = new CacheabilityMetadata(); if ($expect_exception) { $this->setExpectedException('\InvalidArgumentException'); } @@ -136,8 +136,8 @@ public function providerSetCacheMaxAge() { * @covers ::createFromRenderArray * @dataProvider providerTestCreateFromRenderArray */ - public function testCreateFromRenderArray(array $render_array, CacheableMetadata $expected) { - $this->assertEquals($expected, CacheableMetadata::createFromRenderArray($render_array)); + public function testCreateFromRenderArray(array $render_array, CacheabilityMetadata $expected) { + $this->assertEquals($expected, CacheabilityMetadata::createFromRenderArray($render_array)); } /** @@ -148,8 +148,8 @@ public function testCreateFromRenderArray(array $render_array, CacheableMetadata public function providerTestCreateFromRenderArray() { $data = []; - $empty_metadata = new CacheableMetadata(); - $nonempty_metadata = new CacheableMetadata(); + $empty_metadata = new CacheabilityMetadata(); + $nonempty_metadata = new CacheabilityMetadata(); $nonempty_metadata->setCacheContexts(['qux']) ->setCacheTags(['foo:bar']); @@ -172,8 +172,8 @@ public function providerTestCreateFromRenderArray() { * @covers ::createFromObject * @dataProvider providerTestCreateFromObject */ - public function testCreateFromObject($object, CacheableMetadata $expected) { - $this->assertEquals($expected, CacheableMetadata::createFromObject($object)); + public function testCreateFromObject($object, CacheabilityMetadata $expected) { + $this->assertEquals($expected, CacheabilityMetadata::createFromObject($object)); } /** @@ -184,13 +184,13 @@ public function testCreateFromObject($object, CacheableMetadata $expected) { public function providerTestCreateFromObject() { $data = []; - $empty_metadata = new CacheableMetadata(); - $nonempty_metadata = new CacheableMetadata(); + $empty_metadata = new CacheabilityMetadata(); + $nonempty_metadata = new CacheabilityMetadata(); $nonempty_metadata->setCacheContexts(['qux']) ->setCacheTags(['foo:bar']) ->setCacheMaxAge(600); - $uncacheable_metadata = new CacheableMetadata(); - $uncacheable_metadata->setCacheMaxAge(0); + $uncacheability_metadata = new CacheabilityMetadata(); + $uncacheability_metadata->setCacheMaxAge(0); $empty_cacheable_object = new TestCacheableDependency([], [], Cache::PERMANENT); $nonempty_cacheable_object = new TestCacheableDependency(['qux'], ['foo:bar'], 600); @@ -198,7 +198,7 @@ public function providerTestCreateFromObject() { $data[] = [$empty_cacheable_object, $empty_metadata]; $data[] = [$nonempty_cacheable_object, $nonempty_metadata]; - $data[] = [$uncacheable_object, $uncacheable_metadata]; + $data[] = [$uncacheable_object, $uncacheability_metadata]; return $data; } diff --git a/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php index f89e639cc7..f2dc03dd9f 100644 --- a/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php @@ -7,7 +7,7 @@ namespace Drupal\Tests\Core\Cache\Context; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\Context\CacheContextsManager; use Drupal\Core\Cache\Context\CacheContextInterface; use Drupal\Core\Cache\Context\CalculatedCacheContextInterface; @@ -239,8 +239,8 @@ public function getContext() { /** * {@inheritdoc} */ - public function getCacheableMetadata() { - return new CacheableMetadata(); + public function getCacheabilityMetadata() { + return new CacheabilityMetadata(); } } @@ -270,8 +270,8 @@ public function getContext($parameter = NULL) { /** * {@inheritdoc} */ - public function getCacheableMetadata($parameter = NULL) { - return new CacheableMetadata(); + public function getCacheabilityMetadata($parameter = NULL) { + return new CacheabilityMetadata(); } } @@ -298,9 +298,9 @@ public function getContext() { /** * {@inheritdoc} */ - public function getCacheableMetadata() { - $cacheable_metadata = new CacheableMetadata(); - return $cacheable_metadata->setCacheMaxAge(0); + public function getCacheabilityMetadata() { + $cacheability_metadata = new CacheabilityMetadata(); + return $cacheability_metadata->setCacheMaxAge(0); } } diff --git a/core/tests/Drupal/Tests/Core/Datetime/DateTest.php b/core/tests/Drupal/Tests/Core/Datetime/DateTest.php index 3b73b67a10..f7e3d2782d 100644 --- a/core/tests/Drupal/Tests/Core/Datetime/DateTest.php +++ b/core/tests/Drupal/Tests/Core/Datetime/DateTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\Core\Datetime; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Datetime\FormattedDateDiff; use Drupal\Core\DependencyInjection\ContainerBuilder; @@ -419,7 +419,7 @@ public function testFormattedDateDiff() { // Test applying cacheability data to an existing build. $build = []; - CacheableMetadata::createFromObject($object)->applyTo($build); + CacheabilityMetadata::createFromObject($object)->applyTo($build); $this->assertEquals($max_age, $build['#cache']['max-age']); // Test the BC layer. $this->assertSame($object->getCacheMaxAge(), $object->getMaxAge()); diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/ExceptionJsonSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/ExceptionJsonSubscriberTest.php index b40dd73df7..b4bad0bdcd 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/ExceptionJsonSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/ExceptionJsonSubscriberTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\Core\EventSubscriber; use Drupal\Core\Cache\CacheableJsonResponse; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\EventSubscriber\ExceptionJsonSubscriber; use Drupal\Core\Http\Exception\CacheableMethodNotAllowedHttpException; use Drupal\Tests\UnitTestCase; @@ -46,7 +46,7 @@ public function providerTestOn4xx() { JsonResponse::class, ], 'cacheable exception' => [ - new CacheableMethodNotAllowedHttpException((new CacheableMetadata())->setCacheContexts(['route']), ['POST', 'PUT'], 'test message'), + new CacheableMethodNotAllowedHttpException((new CacheabilityMetadata())->setCacheContexts(['route']), ['POST', 'PUT'], 'test message'), CacheableJsonResponse::class, ], ]; diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php index 06692ebfeb..055b73d0e9 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php @@ -5,7 +5,7 @@ use Drupal\Core\Access\AccessResult; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheableDependencyInterface; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\Context\CacheContextsManager; use Drupal\Core\Controller\ControllerResolver; use Drupal\Core\DependencyInjection\ContainerBuilder; @@ -460,7 +460,7 @@ public function testGetTasksBuildWithCacheabilityMetadata() { ->method('getRawParameters') ->willReturn(new ParameterBag()); - $cacheability = new CacheableMetadata(); + $cacheability = new CacheabilityMetadata(); $local_tasks = $this->manager->getTasksBuild('menu_local_task_test_tasks_view', $cacheability); // Ensure that all cacheability metadata is merged together. diff --git a/core/tests/Drupal/Tests/Core/Render/BubbleableMetadataTest.php b/core/tests/Drupal/Tests/Core/Render/BubbleableMetadataTest.php index 092525c75d..a23d9fb1af 100644 --- a/core/tests/Drupal/Tests/Core/Render/BubbleableMetadataTest.php +++ b/core/tests/Drupal/Tests/Core/Render/BubbleableMetadataTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\Core\Render; use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Render\BubbleableMetadata; use Drupal\Tests\UnitTestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -31,8 +31,8 @@ class BubbleableMetadataTest extends UnitTestCase { * @see testMergeAttachmentsHtmlHeadLinkMerging() * @see testMergeAttachmentsHttpHeaderMerging() */ - public function testMerge(BubbleableMetadata $a, CacheableMetadata $b, BubbleableMetadata $expected) { - // Verify that if the second operand is a CacheableMetadata object, not a + public function testMerge(BubbleableMetadata $a, CacheabilityMetadata $b, BubbleableMetadata $expected) { + // Verify that if the second operand is a CacheabilityMetadata object, not a // BubbleableMetadata object, that BubbleableMetadata::merge() doesn't // attempt to merge assets. if (!$b instanceof BubbleableMetadata) { @@ -84,15 +84,15 @@ public function providerTestMerge() { // Placeholders. [(new BubbleableMetadata())->setAttachments(['placeholders' => ['' => ['callback', ['A']]]]), (new BubbleableMetadata())->setAttachments(['placeholders' => ['' => ['callback', ['A']]]]), (new BubbleableMetadata())->setAttachments(['placeholders' => ['' => ['callback', ['A']]]])], - // Second operand is a CacheableMetadata object. + // Second operand is a CacheabilityMetadata object. // All empty. - [(new BubbleableMetadata()), (new CacheableMetadata()), (new BubbleableMetadata())], + [(new BubbleableMetadata()), (new CacheabilityMetadata()), (new BubbleableMetadata())], // Cache contexts. - [(new BubbleableMetadata())->setCacheContexts(['foo']), (new CacheableMetadata())->setCacheContexts(['bar']), (new BubbleableMetadata())->setCacheContexts(['bar', 'foo'])], + [(new BubbleableMetadata())->setCacheContexts(['foo']), (new CacheabilityMetadata())->setCacheContexts(['bar']), (new BubbleableMetadata())->setCacheContexts(['bar', 'foo'])], // Cache tags. - [(new BubbleableMetadata())->setCacheTags(['foo']), (new CacheableMetadata())->setCacheTags(['bar']), (new BubbleableMetadata())->setCacheTags(['bar', 'foo'])], + [(new BubbleableMetadata())->setCacheTags(['foo']), (new CacheabilityMetadata())->setCacheTags(['bar']), (new BubbleableMetadata())->setCacheTags(['bar', 'foo'])], // Cache max-ages. - [(new BubbleableMetadata())->setCacheMaxAge(60), (new CacheableMetadata())->setCacheMaxAge(Cache::PERMANENT), (new BubbleableMetadata())->setCacheMaxAge(60)], + [(new BubbleableMetadata())->setCacheMaxAge(60), (new CacheabilityMetadata())->setCacheMaxAge(Cache::PERMANENT), (new BubbleableMetadata())->setCacheMaxAge(60)], ]; } @@ -674,7 +674,7 @@ public function providerTestAddCacheableDependency() { // Merge in a cacheable metadata. 'merge-cacheable-metadata' => [ (new BubbleableMetadata())->setCacheContexts(['foo'])->setCacheTags(['foo'])->setCacheMaxAge(20), - (new CacheableMetadata())->setCacheContexts(['bar'])->setCacheTags(['bar'])->setCacheMaxAge(60), + (new CacheabilityMetadata())->setCacheContexts(['bar'])->setCacheTags(['bar'])->setCacheMaxAge(60), (new BubbleableMetadata())->setCacheContexts(['foo', 'bar'])->setCacheTags(['foo', 'bar'])->setCacheMaxAge(20), ], 'merge-bubbleable-metadata' => [ diff --git a/core/tests/Drupal/Tests/Core/Render/RendererTestBase.php b/core/tests/Drupal/Tests/Core/Render/RendererTestBase.php index 258fa22fad..79a5c44a98 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererTestBase.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererTestBase.php @@ -8,7 +8,7 @@ namespace Drupal\Tests\Core\Render; use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\Context\ContextCacheKeys; use Drupal\Core\Cache\MemoryBackend; use Drupal\Core\Render\PlaceholderGenerator; @@ -164,7 +164,7 @@ protected function setUp() { $keys[] = $context_id; } } - return new ContextCacheKeys($keys, new CacheableMetadata()); + return new ContextCacheKeys($keys, new CacheabilityMetadata()); }); $this->placeholderGenerator = new PlaceholderGenerator($this->rendererConfig); $this->renderCache = new PlaceholderingRenderCache($this->requestStack, $this->cacheFactory, $this->cacheContextsManager, $this->placeholderGenerator); diff --git a/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php b/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php index ded951b2d6..f21edbca20 100644 --- a/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\Core\Routing; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheabilityMetadata; use Drupal\Core\Cache\CacheableRedirectResponse; use Drupal\Core\Cache\CacheableResponseInterface; use Drupal\Core\Routing\RequestContext; @@ -66,8 +66,8 @@ public function testCreateFromRedirectResponse($redirect_response) { // But it is only actually cacheable (non-zero max-age) if the redirect // response passed to TrustedRedirectResponse::createFromRedirectResponse() // is itself cacheable. - $expected_cacheability = ($redirect_response instanceof CacheableResponseInterface) ? $redirect_response->getCacheableMetadata() : (new CacheableMetadata())->setCacheMaxAge(0); - $this->assertEquals($expected_cacheability, $trusted_redirect_response->getCacheableMetadata()); + $expected_cacheability = ($redirect_response instanceof CacheableResponseInterface) ? $redirect_response->getCacheabilityMetadata() : (new CacheabilityMetadata())->setCacheMaxAge(0); + $this->assertEquals($expected_cacheability, $trusted_redirect_response->getCacheabilityMetadata()); } /** @@ -75,8 +75,8 @@ public function testCreateFromRedirectResponse($redirect_response) { */ public function providerCreateFromRedirectResponse() { return [ - 'cacheable-with-tags' => [(new CacheableRedirectResponse('/example'))->addCacheableDependency((new CacheableMetadata())->addCacheTags(['foo']))], - 'cacheable-with-max-age-0' => [(new CacheableRedirectResponse('/example'))->addCacheableDependency((new CacheableMetadata())->setCacheMaxAge(0))], + 'cacheable-with-tags' => [(new CacheableRedirectResponse('/example'))->addCacheableDependency((new CacheabilityMetadata())->addCacheTags(['foo']))], + 'cacheable-with-max-age-0' => [(new CacheableRedirectResponse('/example'))->addCacheableDependency((new CacheabilityMetadata())->setCacheMaxAge(0))], 'uncacheable' => [new RedirectResponse('/example')], ]; } diff --git a/core/tests/Drupal/Tests/Core/Utility/TokenTest.php b/core/tests/Drupal/Tests/Core/Utility/TokenTest.php index 5f8474a0dc..63823c101e 100644 --- a/core/tests/Drupal/Tests/Core/Utility/TokenTest.php +++ b/core/tests/Drupal/Tests/Core/Utility/TokenTest.php @@ -182,10 +182,10 @@ public function testReplaceWithHookTokensWithBubbleableMetadata() { $this->moduleHandler->expects($this->any()) ->method('invokeAll') ->willReturnCallback(function ($hook_name, $args) { - $cacheable_metadata = $args[4]; - $cacheable_metadata->addCacheContexts(['custom_context']); - $cacheable_metadata->addCacheTags(['node:1']); - $cacheable_metadata->setCacheMaxAge(10); + $cacheability_metadata = $args[4]; + $cacheability_metadata->addCacheContexts(['custom_context']); + $cacheability_metadata->addCacheTags(['node:1']); + $cacheability_metadata->setCacheMaxAge(10); return ['[node:title]' => 'hello world']; });