You are here

class RoleDelegationAccessCheck in Role Delegation 8

Checks access for displaying configuration edit user pages.

Hierarchy

Expanded class hierarchy of RoleDelegationAccessCheck

1 string reference to 'RoleDelegationAccessCheck'
role_delegation.services.yml in ./role_delegation.services.yml
role_delegation.services.yml
1 service uses RoleDelegationAccessCheck
access_check.role_delegation in ./role_delegation.services.yml
Drupal\role_delegation\Access\RoleDelegationAccessCheck

File

src/Access/RoleDelegationAccessCheck.php, line 13

Namespace

Drupal\role_delegation\Access
View source
class RoleDelegationAccessCheck implements AccessInterface {

  /**
   * The permission generator service.
   *
   * @var \Drupal\role_delegation\PermissionGenerator
   */
  protected $permissionGenerator;

  /**
   * The Role Delegation access check.
   *
   * @param \Drupal\role_delegation\PermissionGenerator $permission_generator
   *   The role delegation service.
   */
  public function __construct(PermissionGenerator $permission_generator) {
    $this->permissionGenerator = $permission_generator;
  }

  /**
   * Custom access check for the /user/%/roles page.
   *
   * @param \Drupal\Core\Session\AccountInterface $account
   *   Run access checks for this account.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  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');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RoleDelegationAccessCheck::$permissionGenerator protected property The permission generator service.
RoleDelegationAccessCheck::access public function Custom access check for the /user/%/roles page.
RoleDelegationAccessCheck::__construct public function The Role Delegation access check.