reverted: --- b/core/lib/Drupal/Core/Access/AccessResult.php +++ a/core/lib/Drupal/Core/Access/AccessResult.php @@ -177,6 +177,27 @@ } /** + * {@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 -u b/core/lib/Drupal/Core/Breadcrumb/Breadcrumb.php b/core/lib/Drupal/Core/Breadcrumb/Breadcrumb.php --- b/core/lib/Drupal/Core/Breadcrumb/Breadcrumb.php +++ b/core/lib/Drupal/Core/Breadcrumb/Breadcrumb.php @@ -7,16 +7,30 @@ namespace Drupal\Core\Breadcrumb; +use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Cache\RefinableCacheableDependencyInterface; -use Drupal\Core\Cache\RefinableCacheableDependencyTrait; use Drupal\Core\Link; /** * Used to return generated breadcrumbs with associated cacheability metadata. + * + * @todo implement RenderableInterface once https://www.drupal.org/node/2529560 lands. */ class Breadcrumb implements RefinableCacheableDependencyInterface { - use RefinableCacheableDependencyTrait; + /** + * {@inheritdoc} + */ + public function __construct(RefinableCacheableDependencyInterface $cacheable_metadata = NULL) { + $this->cacheableMetadata = $cacheable_metadata ?: new CacheableMetadata(); + } + + /** + * The wrapped cacheable metadata. + * + * @var \Drupal\Core\Cache\RefinableCacheableDependencyInterface + */ + protected $cacheableMetadata; /** * An ordered list of links for the breadcrumb. @@ -70,6 +84,55 @@ } /** + * {@inheritdoc} + */ + public function getCacheContexts() { + return $this->cacheableMetadata->getCacheContexts(); + } + + /** + * {@inheritdoc} + */ + public function getCacheTags() { + return $this->cacheableMetadata->getCacheTags(); + } + + /** + * {@inheritdoc} + */ + public function getCacheMaxAge() { + return $this->cacheableMetadata->getCacheMaxAge(); + } + + /** + * {@inheritdoc} + */ + public function addCacheContexts(array $cache_contexts) { + return $this->cacheableMetadata->addCacheContexts($cache_contexts); + } + + /** + * {@inheritdoc} + */ + public function addCacheTags(array $cache_tags) { + return $this->cacheableMetadata->addCacheTags($cache_tags); + } + + /** + * {@inheritdoc} + */ + public function mergeCacheMaxAge($max_age) { + return $this->cacheableMetadata->setCacheMaxAge($max_age); + } + + /** + * {@inheritdoc} + */ + public function addCacheableDependency($other_object) { + return $this->cacheableMetadata->addCacheableDependency($other_object); + } + + /** * Returns a render array representation of the object. * * @return mixed[] @@ -80,12 +143,12 @@ public function toRenderable() { $build = [ '#cache' => [ - 'contexts' => $this->cacheContexts, - 'tags' => $this->cacheTags, - 'max-age' => $this->cacheMaxAge, + 'contexts' => $this->cacheableMetadata->getCacheContexts(), + 'tags' => $this->cacheableMetadata->getCacheTags(), + 'max-age' => $this->getCacheMaxAge(), ], ]; - if (!empty($this->links)) { + if ($this->links) { $build += [ '#theme' => 'breadcrumb', '#links' => $this->links, reverted: --- b/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; - } - -} reverted: --- b/core/lib/Drupal/Core/Cache/CacheableMetadata.php +++ a/core/lib/Drupal/Core/Cache/CacheableMetadata.php @@ -9,17 +9,21 @@ /** * Defines a generic class for passing cacheability metadata. * + * @ingroup cache - * 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 @@ } /** + * {@inheritdoc} + */ + public function getCacheContexts() { + return $this->cacheContexts; + } + + /** * Sets cache contexts. * * @param string[] $cache_contexts @@ -46,6 +57,13 @@ } /** + * {@inheritdoc} + */ + public function getCacheMaxAge() { + return $this->cacheMaxAge; + } + + /** * Sets the maximum age (in seconds). * * Defaults to Cache::PERMANENT reverted: --- b/core/lib/Drupal/Core/Cache/RefinableCacheableDependencyTrait.php +++ a/core/lib/Drupal/Core/Cache/RefinableCacheableDependencyTrait.php @@ -12,7 +12,26 @@ */ trait RefinableCacheableDependencyTrait { + /** + * Cache contexts. + * + * @var string[] + */ + protected $cacheContexts = []; + + /** + * Cache tags. + * + * @var string[] + */ + protected $cacheTags = []; + + /** + * Cache max-age. + * + * @var int + */ + protected $cacheMaxAge = Cache::PERMANENT; - use CacheableDependencyTrait; /** * {@inheritdoc} reverted: --- b/core/lib/Drupal/Core/Config/ConfigBase.php +++ a/core/lib/Drupal/Core/Config/ConfigBase.php @@ -262,8 +262,22 @@ /** * {@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; + } + }