You are here

class Permissions in Workbench Moderation 8

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

Defines a class for dynamic permissions based on transitions.

Hierarchy

Expanded class hierarchy of Permissions

File

src/Permissions.php, line 12

Namespace

Drupal\workbench_moderation
View source
class Permissions {
  use StringTranslationTrait;

  /**
   * Returns an array of transition permissions.
   *
   * @return array
   *   The transition permissions.
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Permissions::transitionPermissions public function Returns an array of transition 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.