You are here

class ContactPermissionsPermissions in Contact Permissions 8.2

Same name and namespace in other branches
  1. 8 src/ContactPermissionsPermissions.php \Drupal\contact_permissions\ContactPermissionsPermissions

Provides the permissions for accessing per role contact forms.

Hierarchy

Expanded class hierarchy of ContactPermissionsPermissions

File

src/ContactPermissionsPermissions.php, line 10

Namespace

Drupal\contact_permissions
View source
class ContactPermissionsPermissions {
  use StringTranslationTrait;

  /**
   * Get access per role contact forms permissions.
   *
   * @return array
   *   Permissions array.
   */
  public function permissions() {

    // Generate permissions for each user role.
    $permissions = [];

    /* @var \Drupal\user\RoleInterface[] $roles */
    $roles = user_roles(TRUE);
    if (count($roles) < 1) {
      return $permissions;
    }
    foreach ($roles as $role) {
      $role_name = $role
        ->label();
      $role_id = $role
        ->id();
      $permissions["use {$role_id} personal contact forms"] = [
        'title' => $this
          ->t("Use %role_name's personal contact forms", [
          '%role_name' => $role_name,
        ]),
      ];
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContactPermissionsPermissions::permissions public function Get access per role contact forms 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.