You are here

class EntityQueuePermissions in Entityqueue 8

Provides dynamic permissions for the Entityqueue module.

Hierarchy

Expanded class hierarchy of EntityQueuePermissions

File

src/EntityQueuePermissions.php, line 11

Namespace

Drupal\entityqueue
View source
class EntityQueuePermissions {
  use StringTranslationTrait;

  /**
   * Returns an array of queue permissions.
   *
   * @return array
   */
  public function permissions() {
    $perms = [];

    // Generate queue permissions for all queues.
    foreach (EntityQueue::loadMultiple() as $queue) {
      $perms += $this
        ->buildPermissions($queue);
    }
    return $perms;
  }

  /**
   * Returns a set of permissions for a specific queue.
   *
   * @param \Drupal\entityqueue\Entity\EntityQueue $queue
   *   An EntityQueue entity.
   *
   * @return array
   */
  public function buildPermissions(EntityQueue $queue) {
    $queue_id = $queue
      ->id();
    if ($queue
      ->getHandlerPlugin()
      ->supportsMultipleSubqueues()) {
      $permissions["create {$queue_id} entityqueue"] = [
        'title' => $this
          ->t('Add %queue subqueues', [
          '%queue' => $queue
            ->label(),
        ]),
        'description' => $this
          ->t('Access to create new subqueue to the %queue queue.', [
          '%queue' => $queue
            ->label(),
        ]),
      ];
      $permissions["delete {$queue_id} entityqueue"] = [
        'title' => $this
          ->t('Delete %queue subqueues', [
          '%queue' => $queue
            ->label(),
        ]),
        'description' => $this
          ->t('Access to delete subqueues of the %queue queue.', [
          '%queue' => $queue
            ->label(),
        ]),
      ];
    }
    $permissions["update {$queue_id} entityqueue"] = [
      'title' => $this
        ->t('Manipulate %queue queue', [
        '%queue' => $queue
          ->label(),
      ]),
      'description' => $this
        ->t('Access to update the %queue queue.', [
        '%queue' => $queue
          ->label(),
      ]),
    ];
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityQueuePermissions::buildPermissions public function Returns a set of permissions for a specific queue.
EntityQueuePermissions::permissions public function Returns an array of queue 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.