function AccessPolicyProcessor::getPersistentCacheContexts

Same name in other branches
  1. 11.x core/lib/Drupal/Core/Session/AccessPolicyProcessor.php \Drupal\Core\Session\AccessPolicyProcessor::getPersistentCacheContexts()

Gets the persistent cache contexts of all policies within a given scope.

Parameters

string $scope: The scope to get the persistent cache contexts for.

Return value

string[] The persistent cache contexts of all policies within the scope.

1 call to AccessPolicyProcessor::getPersistentCacheContexts()
AccessPolicyProcessor::processAccessPolicies in core/lib/Drupal/Core/Session/AccessPolicyProcessor.php
Processes the access policies for an account within a given scope.

File

core/lib/Drupal/Core/Session/AccessPolicyProcessor.php, line 165

Class

AccessPolicyProcessor
Processes access policies into permissions for an account.

Namespace

Drupal\Core\Session

Code

protected function getPersistentCacheContexts(string $scope) : array {
    $cid = 'access_policies:access_policy_processor:contexts:' . $scope;
    // Retrieve the contexts from the regular static cache if available.
    if ($static_cache = $this->static
        ->get($cid)) {
        return $static_cache->data;
    }
    $contexts = [];
    foreach ($this->accessPolicies as $access_policy) {
        if ($access_policy->applies($scope)) {
            $contexts[] = $access_policy->getPersistentCacheContexts();
        }
    }
    $contexts = array_merge(...$contexts);
    // Store the contexts in the regular static cache.
    $this->static
        ->set($cid, $contexts);
    return $contexts;
}

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