public function AdministrativeRoleCheck::access in Lightning Core 8
Same name and namespace in other branches
- 8.5 src/Access/AdministrativeRoleCheck.php \Drupal\lightning_core\Access\AdministrativeRoleCheck::access()
- 8.2 src/Access/AdministrativeRoleCheck.php \Drupal\lightning_core\Access\AdministrativeRoleCheck::access()
- 8.3 src/Access/AdministrativeRoleCheck.php \Drupal\lightning_core\Access\AdministrativeRoleCheck::access()
- 8.4 src/Access/AdministrativeRoleCheck.php \Drupal\lightning_core\Access\AdministrativeRoleCheck::access()
Checks if the user has at least one administrative role.
Parameters
\Symfony\Component\Routing\Route $route: The route being checked.
\Drupal\Core\Routing\RouteMatchInterface $route_match: The route matcher.
\Drupal\Core\Session\AccountInterface $account: The user account to check.
Return value
\Drupal\Core\Access\AccessResult The access result.
File
- src/
Access/ AdministrativeRoleCheck.php, line 44
Class
Namespace
Drupal\lightning_core\AccessCode
public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) {
/** @var \Drupal\user\RoleInterface[] $roles */
$roles = $this->entityTypeManager
->getStorage('user_role')
->loadMultiple($account
->getRoles(TRUE));
foreach ($roles as $role) {
if ($role
->isAdmin()) {
return AccessResult::allowed();
}
}
return AccessResult::forbidden('The user must have at least one administrative role.');
}