You are here

class WorkflowPermissions in Workflow 8

Provides dynamic permissions for workflows of different types.

Hierarchy

Expanded class hierarchy of WorkflowPermissions

File

src/WorkflowPermissions.php, line 11

Namespace

Drupal\workflow
View source
class WorkflowPermissions {
  use StringTranslationTrait;

  /**
   * Returns an array of workflow type permissions.
   *
   * @return array
   *   The workflow type permissions.
   *   @see \Drupal\user\PermissionHandlerInterface::getPermissions()
   */
  public function workflowTypePermissions() {
    $perms = [];

    // Generate workflow permissions for all workflow types.
    foreach (Workflow::loadMultiple() as $type) {
      $perms += $this
        ->buildPermissions($type);
    }
    return $perms;
  }

  /**
   * Returns a list of workflow permissions for a given workflow type.
   *
   * @param \Drupal\workflow\Entity\Workflow $type
   *   The workflow type.
   *
   * @return array
   *   An associative array of permission names and descriptions.
   */
  protected function buildPermissions(Workflow $type) {
    $type_id = $type
      ->id();
    $type_params = [
      '%type_name' => $type
        ->label(),
    ];
    return [
      // D7->D8-Conversion of the 'User 1 is special' permission (@see NodePermissions::bypass node access).
      "bypass {$type_id} workflow_transition access" => [
        'title' => $this
          ->t('%type_name: Bypass transition access control', $type_params),
        'description' => $this
          ->t('View, edit and delete all transitions regardless of permission restrictions.'),
        'restrict access' => TRUE,
      ],
      // D7->D8-Conversion of 'participate in workflow' permission to "create $type_id transition" (@see NodePermissions::create content).
      "create {$type_id} workflow_transition" => [
        'title' => $this
          ->t('%type_name: Participate in workflow', $type_params),
        'description' => $this
          ->t("<i>Warning: For better control, <b>uncheck\n          'Authenticated user', manage permissions per separate role,\n          and re-enable 'Authenticated user'.</b></i>\n          Role is enabled to create state transitions. (Determines\n          transition-specific permission on the workflow admin page.)"),
      ],
      // D7->D8-Conversion of 'schedule workflow transitions' permission to "schedule $type_id transition" (@see NodePermissions::create content).
      "schedule {$type_id} workflow_transition" => [
        'title' => $this
          ->t('%type_name: Schedule state transition', $type_params),
        'description' => $this
          ->t('Role is enabled to schedule state transitions.'),
      ],
      // D7->D8-Conversion of 'workflow history' permission on Workflow settings to "access $type_id overview" (@see NodePermissions::access content overview).
      "access own {$type_id} workflow_transion overview" => [
        'title' => $this
          ->t('%type_name: Access Workflow history tab of own content', $type_params),
        'description' => $this
          ->t('Role is enabled to view the "Workflow state transition history" tab on own entity.'),
      ],
      "access any {$type_id} workflow_transion overview" => [
        'title' => $this
          ->t('%type_name: Access Workflow history tab of any content', $type_params),
        'description' => $this
          ->t('Role is enabled to view the "Workflow state transition history" tab on any entity.'),
      ],
      // D7->D8-Conversion of 'show workflow transition form' permission. @see #1893724.
      "access {$type_id} workflow_transition form" => [
        'title' => $this
          ->t('%type_name: Access the Workflow state transition form on entity view page', $type_params),
        'description' => $this
          ->t('Role is enabled to view a "Workflow state transition" block/widget and add a state transition on the entity page.'),
      ],
      // D7->D8-Conversion of 'edit workflow comment' to "edit own/any $type_id transition"
      "edit own {$type_id} workflow_transition" => [
        'title' => $this
          ->t('%type_name: Edit own comments', $type_params),
        'description' => $this
          ->t('Edit the comment of own executed state transitions.'),
        'restrict access' => TRUE,
      ],
      "edit any {$type_id} workflow_transition" => [
        'title' => $this
          ->t('%type_name: Edit any comments', $type_params),
        'description' => $this
          ->t('Edit the comment of any executed state transitions.'),
        'restrict access' => TRUE,
      ],
      // Workflow module has no 'delete' permissions.

      /*
            "delete own $type_id workflow_transition" => [
       'title' => $this->t('%type_name: Delete own content', $type_params),
            ],
            "delete any $type_id workflow_transition" => [
       'title' => $this->t('%type_name: Delete any content', $type_params),
            ],
      */

      // D7->D8-Conversion of 'revert workflow' permission to "revert any/own $type_id transition".
      "revert own {$type_id} workflow_transition" => [
        'title' => $this
          ->t('%type_name: Revert own state transition', $type_params),
        'description' => $this
          ->t('Allow user to revert own last executed state transition on entity.'),
        'restrict access' => TRUE,
      ],
      "revert any {$type_id} workflow_transition" => [
        'title' => $this
          ->t('%type_name: Revert any state transition', $type_params),
        'description' => $this
          ->t('Allow user to revert any last executed state transition on entity.'),
        'restrict access' => TRUE,
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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.
WorkflowPermissions::buildPermissions protected function Returns a list of workflow permissions for a given workflow type.
WorkflowPermissions::workflowTypePermissions public function Returns an array of workflow type permissions.