You are here

public function EditOwnUserAccountAccessCheck::access in Edit own user account permission 8

Checks access for editing own user account while current user being the target account.

Parameters

AccountInterface $user: The user account that is to be edited.

AccountInterface $account: User account that is from the current session.

Return value

AccessResult

File

src/Access/EditOwnUserAccountAccessCheck.php, line 21

Class

EditOwnUserAccountAccessCheck

Namespace

Drupal\edit_own_user_account_permission\Access

Code

public function access(AccountInterface $user, AccountInterface $account) {
  $can_edit_own_account = $account
    ->hasPermission('edit own user account') && $user
    ->id() == $account
    ->id();
  return AccessResult::allowedIf($can_edit_own_account || $account
    ->hasPermission('administer users'));
}