trait CacheableContextTrait in Core Context 8
Provides methods for working with contexts that can be cached.
Hierarchy
- trait \Drupal\core_context\CacheableContextTrait
1 file declares its use of CacheableContextTrait
- RouteAwareContextProviderBase.php in src/
ContextProvider/ RouteAwareContextProviderBase.php
File
- src/
CacheableContextTrait.php, line 11
Namespace
Drupal\core_contextView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableContextTrait:: |
private | function | Adds cache metadata to a set of contexts. |