You are here

class MailingListPermissions in Mailing List 8

Provides dynamic permissions for each mailing list.

Hierarchy

Expanded class hierarchy of MailingListPermissions

File

src/MailingListPermissions.php, line 12

Namespace

Drupal\mailing_list
View source
class MailingListPermissions {
  use StringTranslationTrait;
  use UrlGeneratorTrait;

  /**
   * Returns an array of mailing list permissions.
   *
   * @return array
   *   The mailing list type permissions.
   */
  public function mailListPermissions() {
    $perms = [];

    // Generate mailing list permissions for each list.
    foreach (MailingList::loadMultiple() as $list) {
      $perms += $this
        ->buildPermissions($list);
    }
    return $perms;
  }

  /**
   * Returns a list of mailing list permissions for a given list.
   *
   * @param \Drupal\mailing_list\Entity\MailingList $list
   *   The mailing list.
   *
   * @return array
   *   An associative array of permission names and descriptions.
   */
  protected function buildPermissions(MailingList $list) {
    $list_id = $list
      ->id();
    $list_params = [
      '%list_name' => $list
        ->label(),
    ];
    return [
      "subscribe to {$list_id} mailing list" => [
        'title' => $this
          ->t('Subscribe to %list_name mailing list', $list_params),
      ],
      "access inactive {$list_id} mailing list subscriptions" => [
        'title' => $this
          ->t('%list_name: access inactive subscriptions', $list_params),
      ],
      "view any {$list_id} mailing list subscriptions" => [
        'title' => $this
          ->t('%list_name: view any subscriptions', $list_params),
      ],
      "update any {$list_id} mailing list subscriptions" => [
        'title' => $this
          ->t('%list_name: edit any subscriptions', $list_params),
      ],
      "delete any {$list_id} mailing list subscriptions" => [
        'title' => $this
          ->t('%list_name: delete any subscriptions', $list_params),
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MailingListPermissions::buildPermissions protected function Returns a list of mailing list permissions for a given list.
MailingListPermissions::mailListPermissions public function Returns an array of mailing list 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.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::redirect Deprecated protected function Returns a redirect response object for the specified route. 3
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.