You are here

public function Permissions::transitionPermissions in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/content_moderation/src/Permissions.php \Drupal\content_moderation\Permissions::transitionPermissions()
  2. 9 core/modules/content_moderation/src/Permissions.php \Drupal\content_moderation\Permissions::transitionPermissions()

Returns an array of transition permissions.

Return value

array The transition permissions.

1 string reference to 'Permissions::transitionPermissions'
content_moderation.permissions.yml in core/modules/content_moderation/content_moderation.permissions.yml
core/modules/content_moderation/content_moderation.permissions.yml

File

core/modules/content_moderation/src/Permissions.php, line 24

Class

Permissions
Defines a class for dynamic permissions based on transitions.

Namespace

Drupal\content_moderation

Code

public function transitionPermissions() {
  $permissions = [];

  /** @var \Drupal\workflows\WorkflowInterface $workflow */
  foreach (Workflow::loadMultipleByType('content_moderation') as $workflow) {
    foreach ($workflow
      ->getTypePlugin()
      ->getTransitions() as $transition) {
      $permissions['use ' . $workflow
        ->id() . ' transition ' . $transition
        ->id()] = [
        'title' => $this
          ->t('%workflow workflow: Use %transition transition.', [
          '%workflow' => $workflow
            ->label(),
          '%transition' => $transition
            ->label(),
        ]),
        'description' => $this
          ->formatPlural(count($transition
          ->from()), 'Move content from %from state to %to state.', 'Move content from %from states to %to state.', [
          '%from' => implode(', ', array_map([
            State::class,
            'labelCallback',
          ], $transition
            ->from())),
          '%to' => $transition
            ->to()
            ->label(),
        ]),
        'dependencies' => [
          $workflow
            ->getConfigDependencyKey() => [
            $workflow
              ->getConfigDependencyName(),
          ],
        ],
      ];
    }
  }
  return $permissions;
}