You are here

protected function AccessManager::preAccess in Administer Users by Role 8.3

Initial access check for an operation to test if access might be granted for some roles.

Parameters

string $operation: The operation that is to be performed on the user. Value is updated to match the canonical value used in this module.

\Drupal\Core\Session\AccountInterface $account: The account trying to access the entity.

Return value

\Drupal\Core\Access\AccessResultInterface The access result. hook_entity_access() has detailed documentation.

2 calls to AccessManager::preAccess()
AccessManager::access in src/Services/AccessManager.php
Check access for the specified roles.
AccessManager::listRoles in src/Services/AccessManager.php
List all accessible roles for the specified operation.

File

src/Services/AccessManager.php, line 163

Class

AccessManager
Access Manager.

Namespace

Drupal\administerusersbyrole\Services

Code

protected function preAccess(&$operation, AccountInterface $account) {

  // Full admins already have permissions so we are wasting our time to continue.
  if ($account
    ->hasPermission('administer users')) {
    return FALSE;
  }

  // Ignore unrecognised operation.
  if (!array_key_exists($operation, self::CONVERT_OP)) {
    return FALSE;
  }

  // Check the base permission.
  $operation = self::CONVERT_OP[$operation];
  return $this
    ->hasPerm($operation, $account);
}