function ContextAwarePluginTrait::getCacheContexts

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Plugin/ContextAwarePluginTrait.php \Drupal\Core\Plugin\ContextAwarePluginTrait::getCacheContexts()
  2. 10 core/lib/Drupal/Core/Plugin/ContextAwarePluginTrait.php \Drupal\Core\Plugin\ContextAwarePluginTrait::getCacheContexts()
9 calls to ContextAwarePluginTrait::getCacheContexts()
BookNavigationBlock::getCacheContexts in core/modules/book/src/Plugin/Block/BookNavigationBlock.php
CurrentThemeCondition::getCacheContexts in core/modules/system/src/Plugin/Condition/CurrentThemeCondition.php
ForumBlockBase::getCacheContexts in core/modules/forum/src/Plugin/Block/ForumBlockBase.php
HelpBlock::getCacheContexts in core/modules/help/src/Plugin/Block/HelpBlock.php
RequestPath::getCacheContexts in core/modules/system/src/Plugin/Condition/RequestPath.php

... See full list

10 methods override ContextAwarePluginTrait::getCacheContexts()
BookNavigationBlock::getCacheContexts in core/modules/book/src/Plugin/Block/BookNavigationBlock.php
CurrentThemeCondition::getCacheContexts in core/modules/system/src/Plugin/Condition/CurrentThemeCondition.php
ForumBlockBase::getCacheContexts in core/modules/forum/src/Plugin/Block/ForumBlockBase.php
HelpBlock::getCacheContexts in core/modules/help/src/Plugin/Block/HelpBlock.php
RequestPath::getCacheContexts in core/modules/system/src/Plugin/Condition/RequestPath.php

... See full list

File

core/lib/Drupal/Core/Plugin/ContextAwarePluginTrait.php, line 171

Class

ContextAwarePluginTrait
Provides a trait to add context-aware functionality to plugins.

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 \Drupal\Core\Cache\CacheableDependencyInterface $context */
        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.