You are here

class DelegatableRoles in Role Delegation 8

Class DelegatableRoles.

@package Drupal\role_delegation

Hierarchy

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'
role_delegation.services.yml in ./role_delegation.services.yml
role_delegation.services.yml
1 service uses DelegatableRoles
delegatable_roles in ./role_delegation.services.yml
Drupal\role_delegation\DelegatableRoles

File

src/DelegatableRoles.php, line 15

Namespace

Drupal\role_delegation
View 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

Namesort descending Modifiers Type Description Overrides
DelegatableRoles::$emptyFieldValue public static property A value used to indicate that nothing has been submitted.
DelegatableRoles::getAllRoles public function Gets all roles apart from anonymous and authenticated. Overrides DelegatableRolesInterface::getAllRoles
DelegatableRoles::getAssignableRoles public function Gets the roles a user is allowed to assing. Overrides DelegatableRolesInterface::getAssignableRoles
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.