WorkflowPermissions.php
3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* @file
* Contains \Drupal\workflow\WorkflowPermissions.
*/
namespace Drupal\workflow;
use Drupal\Core\Routing\UrlGeneratorTrait;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\workflow\Entity\Workflow;
/**
* Provides dynamic permissions for workflows of different types.
*/
class WorkflowPermissions {
use StringTranslationTrait;
use UrlGeneratorTrait;
/**
* Returns an array of workflow type permissions.
*
* @return array
* The workflow type permissions.
* @see \Drupal\user\PermissionHandlerInterface::getPermissions()
*/
public function workflowTypePermissions() {
$perms = array();
// 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\WorkflowType $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 = array('%type_name' => $type->label());
return array(
// D7->D8-Conversion of the 'User 1 is special' permission (@see NodePermissions::bypass node access).
"bypass $type_id workflow_transition access" => array(
'title' => $this->t('%type_name: Bypass transition access control', $type_params),
'description' => 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" => array(
'title' => $this->t('%type_name: Participate in workflow', $type_params),
'description' => t('Role is enabled to create state transitions. (Determine 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" => array(
'title' => $this->t('%type_name: Schedule state transition', $type_params),
'description' => 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" => array(
'title' => $this->t('%type_name: Access Workflow history tab of own content', $type_params),
'description' => t('Role is enabled to view the "Workflow state transition history" tab on own entity.'),
),
"access any $type_id workflow_transion overview" => array(
'title' => $this->t('%type_name: Access Workflow history tab of any content', $type_params),
'description' => 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" => array(
'title' => $this->t('%type_name: Access the Workflow state transition form on entity view page', $type_params),
'description' => t('Role is enabled to view a "Workflow state transition" block/widget and add a state transition on the entity page.'),
),
);
}
}