You are here

class SupportTicketPermissions in Support Ticketing System 8

Defines a class containing permission callbacks.

Hierarchy

Expanded class hierarchy of SupportTicketPermissions

File

modules/support_ticket/src/SupportTicketPermissions.php, line 17
Contains \Drupal\support_ticket\SupportTicketPermissions.

Namespace

Drupal\support_ticket
View source
class SupportTicketPermissions {
  use StringTranslationTrait;
  use UrlGeneratorTrait;

  /**
   * Gets an array of support ticket type permissions.
   *
   * @return array
   *   The support ticket type permissions.
   *   @see \Drupal\user\PermissionHandlerInterface::getPermissions()
   */
  public function supportTicketTypePermissions() {
    $perms = array();

    // Generate support ticket permissions for all support ticket types.
    foreach (SupportTicketType::loadMultiple() as $type) {
      $perms += $this
        ->buildPermissions($type);
    }
    return $perms;
  }

  /**
   * Builds a standard list of support ticket permissions for a given type.
   *
   * @param \Drupal\support_ticket\Entity\SupportTicketType $type
   *   The machine name of the support ticket type.
   *
   * @return array
   *   An array of permission names and descriptions.
   */
  protected function buildPermissions(SupportTicketType $type) {
    $type_id = $type
      ->id();
    $type_params = array(
      '%type_name' => $type
        ->label(),
    );
    return array(
      "create {$type_id} ticket" => array(
        'title' => $this
          ->t('%type_name: Create new ticket', $type_params),
      ),
      "edit own {$type_id} ticket" => array(
        'title' => $this
          ->t('%type_name: Edit own ticket', $type_params),
      ),
      "edit any {$type_id} ticket" => array(
        'title' => $this
          ->t('%type_name: Edit any ticket', $type_params),
      ),
      "delete own {$type_id} ticket" => array(
        'title' => $this
          ->t('%type_name: Delete own ticket', $type_params),
      ),
      "delete any {$type_id} ticket" => array(
        'title' => $this
          ->t('%type_name: Delete any ticket', $type_params),
      ),
      "view {$type_id} revisions" => array(
        'title' => $this
          ->t('%type_name: View revisions', $type_params),
      ),
      "modify locked {$type_id} ticket" => array(
        'title' => $this
          ->t('%type_name: Modify locked ticket', $type_params),
      ),
      "revert {$type_id} revisions" => array(
        'title' => $this
          ->t('%type_name: Revert revisions', $type_params),
        'description' => t('Role requires permission <em>view revisions</em> and <em>edit rights</em> for support tickets in question, or <em>administer support tickets</em>.'),
      ),
      "delete {$type_id} revisions" => array(
        'title' => $this
          ->t('%type_name: Delete revisions', $type_params),
        'description' => $this
          ->t('Role requires permission to <em>view revisions</em> and <em>delete rights</em> for support tickets in question, or <em>administer support tickets</em>.'),
      ),
    );
  }

}

Members

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