You are here

public function ContextAwarePluginTrait::getCacheTags in Drupal 10

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Plugin/ContextAwarePluginTrait.php \Drupal\Core\Plugin\ContextAwarePluginTrait::getCacheTags()

File

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

Class

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

Namespace

Drupal\Core\Plugin

Code

public function getCacheTags() {
  $tags = [];

  // Applied contexts can affect the cache tags 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) {
      $tags = Cache::mergeTags($tags, $context
        ->getCacheTags());
    }
  }
  return $tags;
}