public function BadgeAccessCheck::access in User Badges 8
Checks access to the badge listing pages.
Parameters
\Drupal\Core\Session\AccountInterface $account: The currently logged in account.
Return value
\Drupal\Core\Access\AccessResultInterface The access result.
File
- src/
Access/ BadgeAccessCheck.php, line 41
Class
- BadgeAccessCheck
- Defines the access control handler for the badge listing.
Namespace
Drupal\user_badges\AccessCode
public function access(AccountInterface $account) {
$badge_admin = $account
->hasPermission('administer badge entities');
if ($badge_admin) {
return AccessResult::allowed();
}
else {
$user_from_url = $this->routeMatch
->getParameter('user');
// GetParameter returns the entity and sometimes returns a string.
if (!is_string($user_from_url)) {
$user_from_url = $user_from_url
->id();
}
return AccessResult::allowedIf($account
->id() && $account
->id() == $user_from_url && $account
->hasPermission('re-order badges'))
->cachePerPermissions()
->cachePerUser();
}
}