You are here

function administerusersbyrole_user_access in Administer Users by Role 8.3

Same name and namespace in other branches
  1. 8.2 administerusersbyrole.module \administerusersbyrole_user_access()

Implements hook_ENTITY_TYPE_access() for entity type "user".

Parameters

\Drupal\user\UserInterface $user: The user object to check access for.

string $operation: The operation that is to be performed on $entity.

\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 administerusersbyrole_user_access()
administerusersbyrole_entity_field_access in ./administerusersbyrole.module
Implements hook_entity_field_access().
administerusersbyrole_user_assign_role in ./administerusersbyrole.module
Check for permission to assign roles to a user.

File

./administerusersbyrole.module, line 59
Administer Users by Role main module file.

Code

function administerusersbyrole_user_access(UserInterface $user, $operation, AccountInterface $account) {

  // Never allow uid 0 (anonymous) or 1 (master admin).
  if (!$user
    ->isNew() && $user
    ->id() <= 1) {
    return AccessResult::neutral();
  }

  // Grant access to view blocked users if we can update them.
  if ($user
    ->isBlocked() && $operation == 'view') {
    $operation = 'update';
  }
  $result = \Drupal::service('administerusersbyrole.access')
    ->access($user
    ->getRoles(TRUE), $operation, $account);
  return $result
    ->cachePerPermissions()
    ->addCacheableDependency($user);
}