private function CacheableContextTrait::applyCaching in Core Context 8
Adds cache metadata to a set of contexts.
Parameters
\Drupal\Component\Plugin\Context\ContextInterface[] $contexts: The contexts to which cache metadata should be added.
\Drupal\Core\Cache\CacheableDependencyInterface $cache_metadata: The object carrying the cache metadata.
Return value
\Drupal\Component\Plugin\Context\ContextInterface[] The passed contexts, with cache metadata added.
3 calls to CacheableContextTrait::applyCaching()
- FieldContextHandler::getContexts in src/
FieldContextHandler.php - Returns all contexts attached to an entity.
- RouteAwareContextProviderBase::getRuntimeContexts in src/
ContextProvider/ RouteAwareContextProviderBase.php - Gets runtime context values for the given context IDs.
- SettingsContextHandler::getContexts in src/
SettingsContextHandler.php - Returns all contexts attached to an entity.
File
- src/
CacheableContextTrait.php, line 24
Class
- CacheableContextTrait
- Provides methods for working with contexts that can be cached.
Namespace
Drupal\core_contextCode
private function applyCaching(array $contexts, CacheableDependencyInterface $cache_metadata) {
foreach ($contexts as $context) {
if ($context instanceof CacheableContextInterface) {
$context
->addCacheableDependency($cache_metadata);
}
}
return $contexts;
}