You are here

class MessagePermissions in Message UI 8

Defines a class containing permission callbacks.

Hierarchy

Expanded class hierarchy of MessagePermissions

1 file declares its use of MessagePermissions
MessageUiPermissionsTest.php in tests/src/Functional/MessageUiPermissionsTest.php

File

src/MessagePermissions.php, line 11

Namespace

Drupal\message_ui
View source
class MessagePermissions {
  use StringTranslationTrait;

  /**
   * Gets an array of message type permissions.
   *
   * @return array
   *   The message template permissions.
   *
   * @see \Drupal\user\PermissionHandlerInterface::getPermissions()
   */
  public function messageTemplatePermissions() {
    $perms = [];

    // Generate node permissions for all message templates.
    foreach (MessageTemplate::loadMultiple() as $template) {
      $perms += $this
        ->buildPermissions($template);
    }
    return $perms;
  }

  /**
   * Builds a standard list of message permissions for a given template.
   *
   * @param \Drupal\message\Entity\MessageTemplate $template
   *   The machine name of the message template.
   *
   * @return array
   *   An array of permission names and descriptions.
   */
  protected function buildPermissions(MessageTemplate $template) {
    $template_params = [
      '%template_name' => $template
        ->label(),
    ];
    return [
      'view ' . $template
        ->id() . ' message' => [
        'title' => $this
          ->t('%template_name: View a message instance', $template_params),
      ],
      'edit ' . $template
        ->id() . ' message' => [
        'title' => $this
          ->t('%template_name: Edit a message instance', $template_params),
      ],
      'create ' . $template
        ->id() . ' message' => [
        'title' => $this
          ->t('%template_name: Create a new message instance', $template_params),
      ],
      'delete ' . $template
        ->id() . ' message' => [
        'title' => $this
          ->t('%template_name: Delete a message instance', $template_params),
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MessagePermissions::buildPermissions protected function Builds a standard list of message permissions for a given template.
MessagePermissions::messageTemplatePermissions public function Gets an array of message type 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.