core/lib/Drupal/Core/Access/AccessResult.php | 21 ++++++++ .../Drupal/Core/Cache/CacheableDependencyTrait.php | 57 ---------------------- core/lib/Drupal/Core/Cache/CacheableMetadata.php | 26 ++++++++-- .../Cache/RefinableCacheableDependencyTrait.php | 42 +++++++++++++++- core/lib/Drupal/Core/Config/ConfigBase.php | 14 ++++++ 5 files changed, 98 insertions(+), 62 deletions(-) diff --git a/core/lib/Drupal/Core/Access/AccessResult.php b/core/lib/Drupal/Core/Access/AccessResult.php index 390ab96..de15945 100644 --- a/core/lib/Drupal/Core/Access/AccessResult.php +++ b/core/lib/Drupal/Core/Access/AccessResult.php @@ -177,6 +177,27 @@ public function isNeutral() { } /** + * {@inheritdoc} + */ + public function getCacheContexts() { + return $this->cacheContexts; + } + + /** + * {@inheritdoc} + */ + public function getCacheTags() { + return $this->cacheTags; + } + + /** + * {@inheritdoc} + */ + public function getCacheMaxAge() { + return $this->cacheMaxAge; + } + + /** * Resets cache contexts (to the empty array). * * @return $this diff --git a/core/lib/Drupal/Core/Cache/CacheableDependencyTrait.php b/core/lib/Drupal/Core/Cache/CacheableDependencyTrait.php deleted file mode 100644 index 1281462..0000000 --- a/core/lib/Drupal/Core/Cache/CacheableDependencyTrait.php +++ /dev/null @@ -1,57 +0,0 @@ -cacheTags; - } - - /** - * {@inheritdoc} - */ - public function getCacheContexts() { - return $this->cacheContexts; - } - - /** - * {@inheritdoc} - */ - public function getCacheMaxAge() { - return $this->cacheMaxAge; - } - -} diff --git a/core/lib/Drupal/Core/Cache/CacheableMetadata.php b/core/lib/Drupal/Core/Cache/CacheableMetadata.php index d9b5da0..33429bf 100644 --- a/core/lib/Drupal/Core/Cache/CacheableMetadata.php +++ b/core/lib/Drupal/Core/Cache/CacheableMetadata.php @@ -9,17 +9,21 @@ /** * Defines a generic class for passing cacheability metadata. * - * Setters are present because this is a pure metadata container. This is unlike - * other classes implementing this interface; other classes are not only about - * cacheability metadata. - * * @ingroup cache + * */ class CacheableMetadata implements RefinableCacheableDependencyInterface { use RefinableCacheableDependencyTrait; /** + * {@inheritdoc} + */ + public function getCacheTags() { + return $this->cacheTags; + } + + /** * Sets cache tags. * * @param string[] $cache_tags @@ -33,6 +37,13 @@ public function setCacheTags(array $cache_tags) { } /** + * {@inheritdoc} + */ + public function getCacheContexts() { + return $this->cacheContexts; + } + + /** * Sets cache contexts. * * @param string[] $cache_contexts @@ -46,6 +57,13 @@ public function setCacheContexts(array $cache_contexts) { } /** + * {@inheritdoc} + */ + public function getCacheMaxAge() { + return $this->cacheMaxAge; + } + + /** * Sets the maximum age (in seconds). * * Defaults to Cache::PERMANENT diff --git a/core/lib/Drupal/Core/Cache/RefinableCacheableDependencyTrait.php b/core/lib/Drupal/Core/Cache/RefinableCacheableDependencyTrait.php index cf04526..2928938 100644 --- a/core/lib/Drupal/Core/Cache/RefinableCacheableDependencyTrait.php +++ b/core/lib/Drupal/Core/Cache/RefinableCacheableDependencyTrait.php @@ -12,7 +12,47 @@ */ trait RefinableCacheableDependencyTrait { - use CacheableDependencyTrait; + /** + * Cache contexts. + * + * @var string[] + */ + protected $cacheContexts = []; + + /** + * Cache tags. + * + * @var string[] + */ + protected $cacheTags = []; + + /** + * Cache max-age. + * + * @var int + */ + protected $cacheMaxAge = Cache::PERMANENT; + + /** + * {@inheritdoc} + */ + public function getCacheTags() { + return $this->cacheTags; + } + + /** + * {@inheritdoc} + */ + public function getCacheContexts() { + return $this->cacheContexts; + } + + /** + * {@inheritdoc} + */ + public function getCacheMaxAge() { + return $this->cacheMaxAge; + } /** * {@inheritdoc} diff --git a/core/lib/Drupal/Core/Config/ConfigBase.php b/core/lib/Drupal/Core/Config/ConfigBase.php index 6632647..6fbdd29 100644 --- a/core/lib/Drupal/Core/Config/ConfigBase.php +++ b/core/lib/Drupal/Core/Config/ConfigBase.php @@ -262,8 +262,22 @@ public function merge(array $data_to_merge) { /** * {@inheritdoc} */ + public function getCacheContexts() { + return $this->cacheContexts; + } + + /** + * {@inheritdoc} + */ public function getCacheTags() { return Cache::mergeTags(['config:' . $this->name], $this->cacheTags); } + /** + * {@inheritdoc} + */ + public function getCacheMaxAge() { + return $this->cacheMaxAge; + } + }