function PermissionAccessCheck::access

Same name in other branches
  1. 9 core/modules/user/src/Access/PermissionAccessCheck.php \Drupal\user\Access\PermissionAccessCheck::access()
  2. 8.9.x core/modules/user/src/Access/PermissionAccessCheck.php \Drupal\user\Access\PermissionAccessCheck::access()
  3. 11.x core/modules/user/src/Access/PermissionAccessCheck.php \Drupal\user\Access\PermissionAccessCheck::access()

Checks access.

Parameters

\Symfony\Component\Routing\Route $route: The route to check against.

\Drupal\Core\Session\AccountInterface $account: The currently logged in account.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

File

core/modules/user/src/Access/PermissionAccessCheck.php, line 29

Class

PermissionAccessCheck
Permission access check.

Namespace

Drupal\user\Access

Code

public function access(Route $route, AccountInterface $account) {
    $permission = $route->getRequirement('_permission');
    if ($permission === NULL) {
        return AccessResult::neutral();
    }
    // Allow to conjunct the permissions with OR ('+') or AND (',').
    $split = explode(',', $permission);
    if (count($split) > 1) {
        return AccessResult::allowedIfHasPermissions($account, $split, 'AND');
    }
    else {
        $split = explode('+', $permission);
        return AccessResult::allowedIfHasPermissions($account, $split, 'OR');
    }
}

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