You are here

public function RoleDelegationAccessCheck::access in Role Delegation 8

Custom access check for the /user/%/roles page.

Parameters

\Drupal\Core\Session\AccountInterface $account: Run access checks for this account.

Return value

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

File

src/Access/RoleDelegationAccessCheck.php, line 41

Class

RoleDelegationAccessCheck
Checks access for displaying configuration edit user pages.

Namespace

Drupal\role_delegation\Access

Code

public function access(AccountInterface $account) {

  // If the user has any of the "assign custom role" permissions then we give
  // them access to the form.
  foreach ($this->permissionGenerator
    ->rolePermissions() as $perm => $title) {
    if ($account
      ->hasPermission($perm)) {
      return AccessResult::allowed()
        ->cachePerPermissions();
    }
  }

  // If the user can administer all permissions then they can also view the
  // roles page.
  return AccessResult::allowedIfHasPermission($account, 'assign all roles');
}