You are here

public function ContextAwarePluginBase::getCacheContexts in Drupal 8

The cache contexts associated with this object.

These identify a specific variation/representation of the object.

Cache contexts are tokens: placeholders that are converted to cache keys by the @cache_contexts_manager service. The replacement value depends on the request context (the current URL, language, and so on). They're converted before storing an object in cache.

Return value

string[] An array of cache context tokens, used to generate a cache ID.

Overrides CacheableDependencyInterface::getCacheContexts

See also

\Drupal\Core\Cache\Context\CacheContextsManager::convertTokensToKeys()

8 calls to ContextAwarePluginBase::getCacheContexts()
BookNavigationBlock::getCacheContexts in core/modules/book/src/Plugin/Block/BookNavigationBlock.php
The cache contexts associated with this object.
CurrentThemeCondition::getCacheContexts in core/modules/system/src/Plugin/Condition/CurrentThemeCondition.php
The cache contexts associated with this object.
ForumBlockBase::getCacheContexts in core/modules/forum/src/Plugin/Block/ForumBlockBase.php
The cache contexts associated with this object.
HelpBlock::getCacheContexts in core/modules/help/src/Plugin/Block/HelpBlock.php
The cache contexts associated with this object.
RequestPath::getCacheContexts in core/modules/system/src/Plugin/Condition/RequestPath.php
The cache contexts associated with this object.

... See full list

9 methods override ContextAwarePluginBase::getCacheContexts()
BookNavigationBlock::getCacheContexts in core/modules/book/src/Plugin/Block/BookNavigationBlock.php
The cache contexts associated with this object.
CurrentThemeCondition::getCacheContexts in core/modules/system/src/Plugin/Condition/CurrentThemeCondition.php
The cache contexts associated with this object.
ForumBlockBase::getCacheContexts in core/modules/forum/src/Plugin/Block/ForumBlockBase.php
The cache contexts associated with this object.
HelpBlock::getCacheContexts in core/modules/help/src/Plugin/Block/HelpBlock.php
The cache contexts associated with this object.
RequestPath::getCacheContexts in core/modules/system/src/Plugin/Condition/RequestPath.php
The cache contexts associated with this object.

... See full list

File

core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php, line 130

Class

ContextAwarePluginBase
Base class for plugins that are context aware.

Namespace

Drupal\Core\Plugin

Code

public function getCacheContexts() {
  $cache_contexts = [];

  // Applied contexts can affect the cache contexts when this plugin is
  // involved in caching, collect and return them.
  foreach ($this
    ->getContexts() as $context) {

    /** @var $context \Drupal\Core\Cache\CacheableDependencyInterface */
    if ($context instanceof CacheableDependencyInterface) {
      $cache_contexts = Cache::mergeContexts($cache_contexts, $context
        ->getCacheContexts());
    }
  }
  return $cache_contexts;
}