public function DelegatableRoles::getAssignableRoles in Role Delegation 8
Gets the roles a user is allowed to assing.
Parameters
\Drupal\Core\Session\AccountInterface $account: The account for which you want to know which roles they can assign.
Return value
array An array of roles with machine names as keys and labels as values.
Overrides DelegatableRolesInterface::getAssignableRoles
File
- src/
DelegatableRoles.php, line 29
Class
- DelegatableRoles
- Class DelegatableRoles.
Namespace
Drupal\role_delegationCode
public function getAssignableRoles(AccountInterface $account) {
$assignable_roles = [];
foreach ($this
->getAllRoles() as $role) {
if ($account
->hasPermission('assign all roles') || $account
->hasPermission(sprintf('assign %s role', $role
->id()))) {
$assignable_roles[$role
->id()] = $role
->label();
}
}
return $assignable_roles;
}