public function SwitchAccessCheck::access in Masquerade 8.2
Check to see if user has any permissions to masquerade.
Parameters
\Drupal\Core\Session\AccountInterface $account: Run access checks for this account.
Return value
\Drupal\Core\Access\AccessResultInterface The access result.
File
- src/
Access/ SwitchAccessCheck.php, line 41
Class
- SwitchAccessCheck
- Checks access for any masquerade permissions.
Namespace
Drupal\masquerade\AccessCode
public function access(AccountInterface $account) {
if ($this->masquerade
->isMasquerading()) {
// Do now allow to masquerade when already masquerading.
$result = AccessResult::forbidden();
}
elseif ($account
->id() == 1) {
// Uid 1 may masquerade as anyone.
$result = AccessResult::allowed();
}
else {
// Ability to masquerade defined by permissions.
$permissions = $this->masquerade
->getPermissions();
$result = AccessResult::allowedIfHasPermissions($account, $permissions, 'OR');
}
return $result
->addCacheContexts([
'session.is_masquerading',
]);
}