You are here

trait CacheableContextTrait in Core Context 8

Provides methods for working with contexts that can be cached.

Hierarchy

1 file declares its use of CacheableContextTrait
RouteAwareContextProviderBase.php in src/ContextProvider/RouteAwareContextProviderBase.php

File

src/CacheableContextTrait.php, line 11

Namespace

Drupal\core_context
View source
trait CacheableContextTrait {

  /**
   * Adds cache metadata to a set of contexts.
   *
   * @param \Drupal\Component\Plugin\Context\ContextInterface[] $contexts
   *   The contexts to which cache metadata should be added.
   * @param \Drupal\Core\Cache\CacheableDependencyInterface $cache_metadata
   *   The object carrying the cache metadata.
   *
   * @return \Drupal\Component\Plugin\Context\ContextInterface[]
   *   The passed contexts, with cache metadata added.
   */
  private function applyCaching(array $contexts, CacheableDependencyInterface $cache_metadata) {
    foreach ($contexts as $context) {
      if ($context instanceof CacheableContextInterface) {
        $context
          ->addCacheableDependency($cache_metadata);
      }
    }
    return $contexts;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableContextTrait::applyCaching private function Adds cache metadata to a set of contexts.