class DelegatableRoles in Role Delegation 8
Class DelegatableRoles.
@package Drupal\role_delegation
Hierarchy
- class \Drupal\role_delegation\DelegatableRoles implements DelegatableRolesInterface uses StringTranslationTrait
Expanded class hierarchy of DelegatableRoles
2 files declare their use of DelegatableRoles
- RoleChangeSelection.php in src/
Plugin/ EntityReferenceSelection/ RoleChangeSelection.php - role_delegation.module in ./
role_delegation.module - Allows admins to grant roles the authority to assign selected roles to users.
1 string reference to 'DelegatableRoles'
1 service uses DelegatableRoles
File
- src/
DelegatableRoles.php, line 15
Namespace
Drupal\role_delegationView source
class DelegatableRoles implements DelegatableRolesInterface {
use StringTranslationTrait;
/**
* A value used to indicate that nothing has been submitted.
*
* @var array
*/
public static $emptyFieldValue = [
'__role_delegation_empty_field_value__',
];
/**
* {@inheritdoc}
*/
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;
}
/**
* {@inheritdoc}
*/
public function getAllRoles() {
$all_roles = Role::loadMultiple();
unset($all_roles[RoleInterface::ANONYMOUS_ID], $all_roles[RoleInterface::AUTHENTICATED_ID]);
return $all_roles;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DelegatableRoles:: |
public static | property | A value used to indicate that nothing has been submitted. | |
DelegatableRoles:: |
public | function |
Gets all roles apart from anonymous and authenticated. Overrides DelegatableRolesInterface:: |
|
DelegatableRoles:: |
public | function |
Gets the roles a user is allowed to assing. Overrides DelegatableRolesInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |