You are here

public function UserKeyAuthForm::checkAccess in Key auth 8

Access handler for the form.

Parameters

\Drupal\user\UserInterface $user: The user entity being edited.

Return value

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

1 string reference to 'UserKeyAuthForm::checkAccess'
key_auth.routing.yml in ./key_auth.routing.yml
key_auth.routing.yml

File

src/Form/UserKeyAuthForm.php, line 188

Class

UserKeyAuthForm
Class UserKeyAuthForm.

Namespace

Drupal\key_auth\Form

Code

public function checkAccess(UserInterface $user) {

  // Load the current user.
  $current_user = User::load($this
    ->currentUser()
    ->id());

  // Check if the user being edited is not the current user.
  if ($user
    ->id() != $current_user
    ->id()) {

    // Check admin-access.
    $access = AccessResult::allowedIfHasPermission($current_user, 'administer users');
  }
  else {
    $access = AccessResult::allowedIf($this->keyAuth
      ->access($current_user));
  }

  // Add caching.
  $access
    ->addCacheContexts([
    'user.permissions',
  ]);
  $access
    ->addCacheableDependency($user);
  return $access;
}