View source
<?php
namespace Drupal\workflow;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\workflow\Entity\Workflow;
class WorkflowPermissions {
use StringTranslationTrait;
public function workflowTypePermissions() {
$perms = [];
foreach (Workflow::loadMultiple() as $type) {
$perms += $this
->buildPermissions($type);
}
return $perms;
}
protected function buildPermissions(Workflow $type) {
$type_id = $type
->id();
$type_params = [
'%type_name' => $type
->label(),
];
return [
"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,
],
"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.)"),
],
"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.'),
],
"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.'),
],
"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.'),
],
"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,
],
"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,
],
];
}
}