You are here

public function SchedulerPermissions::permissions in Scheduler 2.x

Build permissions for each entity type.

SchedulerManager function permissionName() can be used to return the permission name for a given entity type and permission type.

Return value

array|array[] The full list of permissions to schedule and to view each entity type.

1 string reference to 'SchedulerPermissions::permissions'
scheduler.permissions.yml in ./scheduler.permissions.yml
scheduler.permissions.yml

File

src/SchedulerPermissions.php, line 60

Class

SchedulerPermissions
Provides dynamic permissions for scheduler plugins.

Namespace

Drupal\scheduler

Code

public function permissions() {
  $permissions = [];
  $types = $this->schedulerManager
    ->getPluginEntityTypes();
  foreach ($types as $entity_type_id) {
    $entity_type = $this->entityTypeManager
      ->getDefinition($entity_type_id);

    // For backwards-compatibility with existing permissions, the node
    // permission names have to end with 'nodes' and 'content'. For all other
    // entity types we use $entity_type_id for both permissions.
    if ($entity_type_id == 'node') {
      $edit_key = 'nodes';
      $view_key = 'content';
    }
    else {
      $edit_key = $view_key = $entity_type_id;
    }
    $t_args = [
      '%label' => $entity_type
        ->getLabel(),
      '%singular_label' => $entity_type
        ->getSingularLabel(),
      '%plural_label' => $entity_type
        ->getPluralLabel(),
    ];
    $permissions += [
      "schedule publishing of {$edit_key}" => [
        'title' => $this
          ->t('Schedule publishing and unpublishing of %label', $t_args),
        'description' => $this
          ->t('Allows users to set a start and end time for %singular_label publication.', $t_args),
      ],
      "view scheduled {$view_key}" => [
        'title' => $this
          ->t('View scheduled %label', $t_args),
        'description' => $this
          ->t('Allows users to see a list of all %plural_label that are scheduled.', $t_args),
      ],
    ];
  }
  return $permissions;
}