function BlockAccessControlHandler::mergeCacheabilityFromConditions

Same name in other branches
  1. 8.9.x core/modules/block/src/BlockAccessControlHandler.php \Drupal\block\BlockAccessControlHandler::mergeCacheabilityFromConditions()
  2. 10 core/modules/block/src/BlockAccessControlHandler.php \Drupal\block\BlockAccessControlHandler::mergeCacheabilityFromConditions()
  3. 11.x core/modules/block/src/BlockAccessControlHandler.php \Drupal\block\BlockAccessControlHandler::mergeCacheabilityFromConditions()

Merges cacheable metadata from conditions onto the access result object.

Parameters

\Drupal\Core\Access\AccessResult $access: The access result object.

\Drupal\Core\Condition\ConditionInterface[] $conditions: List of visibility conditions.

1 call to BlockAccessControlHandler::mergeCacheabilityFromConditions()
BlockAccessControlHandler::checkAccess in core/modules/block/src/BlockAccessControlHandler.php
Performs access checks.

File

core/modules/block/src/BlockAccessControlHandler.php, line 160

Class

BlockAccessControlHandler
Defines the access control handler for the block entity type.

Namespace

Drupal\block

Code

protected function mergeCacheabilityFromConditions(AccessResult $access, array $conditions) {
    foreach ($conditions as $condition) {
        if ($condition instanceof CacheableDependencyInterface) {
            $access->addCacheTags($condition->getCacheTags());
            $access->addCacheContexts($condition->getCacheContexts());
            $access->setCacheMaxAge(Cache::mergeMaxAges($access->getCacheMaxAge(), $condition->getCacheMaxAge()));
        }
    }
}

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