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'
File
- src/
Form/ UserKeyAuthForm.php, line 188
Class
- UserKeyAuthForm
- Class UserKeyAuthForm.
Namespace
Drupal\key_auth\FormCode
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;
}