class MasqueradePermissions in Masquerade 8.2
Provides dynamic permissions of the masquerade module.
Hierarchy
- class \Drupal\masquerade\MasqueradePermissions uses StringTranslationTrait
Expanded class hierarchy of MasqueradePermissions
File
- src/
MasqueradePermissions.php, line 12
Namespace
Drupal\masqueradeView source
class MasqueradePermissions {
use StringTranslationTrait;
/**
* Returns an array of masquerade permissions.
*
* @todo Allow permissions for each role to masquerade as as subset of roles
* https://drupal.org/node/1171500
*
* @return array
* The permissions array.
*/
public function permissions() {
$permissions = [];
// Anonymous was intentionally left out. Logout instead.
$roles = $this
->getUserRoles();
foreach ($roles as $role) {
$permissions['masquerade as ' . $role
->id()] = [
'title' => $this
->t('Masquerade as @role', [
'@role' => $role
->label(),
]),
'restrict access' => TRUE,
];
}
return $permissions;
}
/**
* Returns role entities allowed to masquerade as.
*
* @return \Drupal\user\RoleInterface[]
* An associative array with the role id as the key and the role object as
* value.
*/
protected function getUserRoles() {
$roles = Role::loadMultiple();
// Do not allow masquerade as anonymous user, use private browsing.
unset($roles[RoleInterface::ANONYMOUS_ID]);
return $roles;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MasqueradePermissions:: |
protected | function | Returns role entities allowed to masquerade as. | |
MasqueradePermissions:: |
public | function | Returns an array of masquerade permissions. | |
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. |