You are here

public function UserProtectPermissions::permissions in User protect 8

Returns an array of userprotect permissions.

Return value

array An array of permissions to bypass protection rules.

1 string reference to 'UserProtectPermissions::permissions'
userprotect.permissions.yml in ./userprotect.permissions.yml
userprotect.permissions.yml

File

src/UserProtectPermissions.php, line 47

Class

UserProtectPermissions
Provides dynamic permissions for bypassing user protect rules.

Namespace

Drupal\userprotect

Code

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;
}