function TempstoreAccess::access

Same name in other branches
  1. 4.0.x src/Access/TempstoreAccess.php \Drupal\ctools\Access\TempstoreAccess::access()

Access method to find if user has access to a particular tempstore.

Parameters

\Symfony\Component\Routing\Route $route:

\Drupal\Core\Routing\RouteMatchInterface $match:

\Drupal\Core\Session\AccountInterface $account:

Return value

\Drupal\Core\Access\AccessResultAllowed|\Drupal\Core\Access\AccessResultForbidden

File

src/Access/TempstoreAccess.php, line 48

Class

TempstoreAccess
Tempstore Access for ctools.

Namespace

Drupal\ctools\Access

Code

public function access(Route $route, RouteMatchInterface $match, AccountInterface $account) {
    $tempstore_id = $match->getParameter('tempstore_id') ? $match->getParameter('tempstore_id') : $route->getDefault('tempstore_id');
    $id = $match->getParameter($route->getRequirement('_ctools_access'));
    if ($tempstore_id && $id) {
        $cached_values = $this->getTempstore()
            ->get($tempstore_id)
            ->get($id);
        if (!empty($cached_values['access']) && $cached_values['access'] instanceof CToolsAccessInterface) {
            $access = $cached_values['access']->access($account);
        }
        else {
            $access = AccessResult::allowed();
        }
    }
    else {
        $access = AccessResult::forbidden();
    }
    // The different wizards will have different tempstore ids and adding this
    // cache context allows us to nuance the access per wizard.
    $access->addCacheContexts([
        'url.query_args:tempstore_id',
    ]);
    return $access;
}