You are here

class PermissionGenerator in Role Delegation 8

The PermissionGenerator class.

Hierarchy

Expanded class hierarchy of PermissionGenerator

1 file declares its use of PermissionGenerator
RoleDelegationAccessCheck.php in src/Access/RoleDelegationAccessCheck.php
1 string reference to 'PermissionGenerator'
role_delegation.services.yml in ./role_delegation.services.yml
role_delegation.services.yml
1 service uses PermissionGenerator
permission_generator.role_delegation in ./role_delegation.services.yml
Drupal\role_delegation\PermissionGenerator

File

src/PermissionGenerator.php, line 10

Namespace

Drupal\role_delegation
View source
class PermissionGenerator {
  use StringTranslationTrait;

  /**
   * The delegatable role service for getting all the roles.
   *
   * @var \Drupal\role_delegation\DelegatableRolesInterface
   */
  protected $delegatableRoles;

  /**
   * Construct a new permission generator.
   *
   * @param \Drupal\role_delegation\DelegatableRolesInterface $delegatable_roles
   *   The delegatable roles service.
   */
  public function __construct(DelegatableRolesInterface $delegatable_roles) {
    $this->delegatableRoles = $delegatable_roles;
  }

  /**
   * Returns an array of permissions to assign specific roles.
   *
   * @return array
   *   An array of permissions in the correct format for permission_callbacks.
   */
  public function rolePermissions() {
    $permissions = [];
    foreach ($this->delegatableRoles
      ->getAllRoles() as $rid => $role) {
      $permissions[sprintf('assign %s role', $rid)] = [
        'title' => $this
          ->t('Assign %role role', [
          '%role' => $role
            ->label(),
        ]),
      ];
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PermissionGenerator::$delegatableRoles protected property The delegatable role service for getting all the roles.
PermissionGenerator::rolePermissions public function Returns an array of permissions to assign specific roles.
PermissionGenerator::__construct public function Construct a new permission generator.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.