You are here

public function ScheduledTransitionsPermissions::permissions in Scheduled Transitions 8

Same name and namespace in other branches
  1. 2.x src/ScheduledTransitionsPermissions.php \Drupal\scheduled_transitions\ScheduledTransitionsPermissions::permissions()

Generate dynamic permissions.

Return value

array An array of permissions.

1 string reference to 'ScheduledTransitionsPermissions::permissions'
scheduled_transitions.permissions.yml in ./scheduled_transitions.permissions.yml
scheduled_transitions.permissions.yml

File

src/ScheduledTransitionsPermissions.php, line 94

Class

ScheduledTransitionsPermissions
Generates permissions for host entity types for scheduled transitions.

Namespace

Drupal\scheduled_transitions

Code

public function permissions() : array {
  $permissions = [];
  $bundleInfo = $this->scheduledTransitionsUtility
    ->getBundles();
  foreach ($bundleInfo as $entityTypeId => $bundles) {
    $entityBundleInfo = $this->bundleInfo
      ->getBundleInfo($entityTypeId);
    foreach ($bundles as $bundleId) {
      $tArgs = [
        '@entity_type' => $this->entityTypeManager
          ->getDefinition($entityTypeId)
          ->getLabel(),
        '@bundle' => $entityBundleInfo[$bundleId]['label'] ?? '',
      ];
      $viewPermission = static::viewScheduledTransitionsPermission($entityTypeId, $bundleId);
      $permissions[$viewPermission] = [
        'title' => $this
          ->t('View scheduled transitions for @entity_type:@bundle entities', $tArgs),
      ];
      $addPermission = static::addScheduledTransitionsPermission($entityTypeId, $bundleId);
      $permissions[$addPermission] = [
        'title' => $this
          ->t('Add scheduled transitions for @entity_type:@bundle entities', $tArgs),
      ];
      $reschedulePermission = static::rescheduleScheduledTransitionsPermission($entityTypeId, $bundleId);
      $permissions[$reschedulePermission] = [
        'title' => $this
          ->t('Reschedule scheduled transitions for @entity_type:@bundle entities', $tArgs),
      ];
    }
  }
  return $permissions;
}