function ContextAwarePluginTrait::getCacheMaxAge

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Plugin/ContextAwarePluginTrait.php \Drupal\Core\Plugin\ContextAwarePluginTrait::getCacheMaxAge()
1 method overrides ContextAwarePluginTrait::getCacheMaxAge()
LanguageBlock::getCacheMaxAge in core/modules/language/src/Plugin/Block/LanguageBlock.php
@todo Make cacheable in https://www.drupal.org/node/2232375.

File

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

Class

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

Namespace

Drupal\Core\Plugin

Code

public function getCacheMaxAge() {
  $max_age = Cache::PERMANENT;
  // Applied contexts can affect the cache max age 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) {
      $max_age = Cache::mergeMaxAges($max_age, $context->getCacheMaxAge());
    }
  }
  return $max_age;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.