function AccessAwareRouter::checkAccess

Same name in other branches
  1. 9 core/lib/Drupal/Core/Routing/AccessAwareRouter.php \Drupal\Core\Routing\AccessAwareRouter::checkAccess()
  2. 8.9.x core/lib/Drupal/Core/Routing/AccessAwareRouter.php \Drupal\Core\Routing\AccessAwareRouter::checkAccess()
  3. 10 core/lib/Drupal/Core/Routing/AccessAwareRouter.php \Drupal\Core\Routing\AccessAwareRouter::checkAccess()

Apply access check service to the route and parameters in the request.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request to access check.

1 call to AccessAwareRouter::checkAccess()
AccessAwareRouter::matchRequest in core/lib/Drupal/Core/Routing/AccessAwareRouter.php

File

core/lib/Drupal/Core/Routing/AccessAwareRouter.php, line 101

Class

AccessAwareRouter
A router class for Drupal with access check and upcasting.

Namespace

Drupal\Core\Routing

Code

protected function checkAccess(Request $request) {
    // The cacheability (if any) of this request's access check result must be
    // applied to the response.
    $access_result = $this->accessManager
        ->checkRequest($request, $this->account, TRUE);
    // Allow a master request to set the access result for a subrequest: if an
    // access result attribute is already set, don't overwrite it.
    if (!$request->attributes
        ->has(AccessAwareRouterInterface::ACCESS_RESULT)) {
        $request->attributes
            ->set(AccessAwareRouterInterface::ACCESS_RESULT, $access_result);
    }
    if (!$access_result->isAllowed()) {
        if ($access_result instanceof CacheableDependencyInterface && $request->isMethodCacheable()) {
            throw new CacheableAccessDeniedHttpException($access_result, $access_result instanceof AccessResultReasonInterface ? $access_result->getReason() : '');
        }
        else {
            throw new AccessDeniedHttpException($access_result instanceof AccessResultReasonInterface ? $access_result->getReason() : '');
        }
    }
}

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