You are here

Permissions.php in Workflows Field 8

Same filename and directory in other branches
  1. 2.x src/Permissions.php

File

src/Permissions.php
View source
<?php

namespace Drupal\workflows_field;

use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\workflows\Entity\Workflow;

/**
 * Defines a class for dynamic permissions based on transitions.
 *
 * @internal
 */
class Permissions {
  use StringTranslationTrait;

  /**
   * Returns an array of permissions.
   *
   * @return array
   *   The dynamic permissions.
   */
  public function getPermissions() {
    $permissions = [];

    /** @var \Drupal\workflows\WorkflowInterface $workflow */
    foreach (Workflow::loadMultipleByType('workflows_field') as $id => $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(),
          ]),
        ];
      }
    }
    return $permissions;
  }

}

Classes

Namesort descending Description
Permissions Defines a class for dynamic permissions based on transitions.