function ContextAwarePluginBase::getCacheContexts

Overrides CacheableDependencyInterface::getCacheContexts

3 calls to ContextAwarePluginBase::getCacheContexts()
CurrentThemeCondition::getCacheContexts in core/modules/system/src/Plugin/Condition/CurrentThemeCondition.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.
UserRole::getCacheContexts in core/modules/user/src/Plugin/Condition/UserRole.php
The cache contexts associated with this object.
3 methods override ContextAwarePluginBase::getCacheContexts()
CurrentThemeCondition::getCacheContexts in core/modules/system/src/Plugin/Condition/CurrentThemeCondition.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.
UserRole::getCacheContexts in core/modules/user/src/Plugin/Condition/UserRole.php
The cache contexts associated with this object.

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.