You are here

class AdministerusersbyrolePermissions in Administer Users by Role 8.2

Same name and namespace in other branches
  1. 8.3 src/AdministerusersbyrolePermissions.php \Drupal\administerusersbyrole\AdministerusersbyrolePermissions

Provides dynamic permissions of the administerusersbyrole module.

Hierarchy

Expanded class hierarchy of AdministerusersbyrolePermissions

File

src/AdministerusersbyrolePermissions.php, line 13

Namespace

Drupal\administerusersbyrole
View source
class AdministerusersbyrolePermissions implements ContainerInjectionInterface {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static();
  }

  /**
   * Returns an array of administerusersbyrole permissions.
   *
   * @return array
   */
  public function permissions() {
    $roles = user_roles(TRUE);
    $perms = [];
    $ops = array(
      'edit' => t('Edit'),
      'cancel' => t('Cancel'),
    );
    foreach ($roles as $rid => $role) {
      if ($role
        ->isAdmin()) {

        // Exclude the admin role.  Once you can edit an admin, you can set their password, log in and do anything,
        // which defeats the point of using this module.
        continue;
      }
      foreach ($ops as $op => $operation) {
        $perm_string = _administerusersbyrole_build_perm_string($rid, $op);
        if ($rid == AccountInterface::AUTHENTICATED_ROLE) {
          $perm_title = $this
            ->t("@operation users with no custom roles", array(
            '@operation' => $operation,
          ));
        }
        else {
          $perm_title = $this
            ->t("@operation users with role %role", array(
            '@operation' => $operation,
            '%role' => $role
              ->label(),
          ));
        }
        $perms[$perm_string] = array(
          'title' => $perm_title,
        );
      }
    }
    return $perms;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AdministerusersbyrolePermissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
AdministerusersbyrolePermissions::permissions public function Returns an array of administerusersbyrole permissions.
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.