class UserProtectPermissions in User protect 8
Provides dynamic permissions for bypassing user protect rules.
Hierarchy
- class \Drupal\userprotect\UserProtectPermissions implements ContainerInjectionInterface uses StringTranslationTrait
Expanded class hierarchy of UserProtectPermissions
File
- src/
UserProtectPermissions.php, line 13
Namespace
Drupal\userprotectView source
class UserProtectPermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a new UserProtectPermissions instance.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'));
}
/**
* Returns an array of userprotect permissions.
*
* @return array
* An array of permissions to bypass protection rules.
*/
public function permissions() {
$permissions = [];
// For each protection rule, create a permission to bypass the rule.
/** @var \Drupal\userprotect\Entity\ProtectionRuleInterface[] $rules */
$rules = $this->entityTypeManager
->getStorage('userprotect_rule')
->loadMultiple();
uasort($rules, 'Drupal\\Core\\Config\\Entity\\ConfigEntityBase::sort');
foreach ($rules as $rule) {
$vars = [
'%label' => $rule
->label(),
];
$permissions += [
$rule
->getPermissionName() => [
'title' => $this
->t('Bypass user protection for %label', $vars),
'description' => $this
->t('The user protection rule %label is ignored for users with this permission.', $vars),
],
];
}
return $permissions;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
UserProtectPermissions:: |
protected | property | The entity manager. | |
UserProtectPermissions:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
UserProtectPermissions:: |
public | function | Returns an array of userprotect permissions. | |
UserProtectPermissions:: |
public | function | Constructs a new UserProtectPermissions instance. |