You are here

public function Permissions::transitionPermissions in Workbench Moderation 8

Same name and namespace in other branches
  1. 8.2 src/Permissions.php \Drupal\workbench_moderation\Permissions::transitionPermissions()

Returns an array of transition permissions.

Return value

array The transition permissions.

1 string reference to 'Permissions::transitionPermissions'
workbench_moderation.permissions.yml in ./workbench_moderation.permissions.yml
workbench_moderation.permissions.yml

File

src/Permissions.php, line 22

Class

Permissions
Defines a class for dynamic permissions based on transitions.

Namespace

Drupal\workbench_moderation

Code

public function transitionPermissions() {

  // @todo write a test for this.
  $perms = [];

  /* @var \Drupal\workbench_moderation\ModerationStateInterface[] $states */
  $states = ModerationState::loadMultiple();

  /* @var \Drupal\workbench_moderation\ModerationStateTransitionInterface $transition */
  foreach (ModerationStateTransition::loadMultiple() as $id => $transition) {
    $perms['use ' . $id . ' transition'] = [
      'title' => $this
        ->t('Use the %transition_name transition', [
        '%transition_name' => $transition
          ->label(),
      ]),
      'description' => $this
        ->t('Move content from %from state to %to state.', [
        '%from' => $states[$transition
          ->getFromState()]
          ->label(),
        '%to' => $states[$transition
          ->getToState()]
          ->label(),
      ]),
    ];
  }
  return $perms;
}