-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlightning_workflow.install
162 lines (144 loc) · 4.56 KB
/
lightning_workflow.install
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/**
* @file
* Contains installation and update routines for Lightning Workflow.
*/
use Drupal\Core\Config\ImmutableConfig;
use Drupal\node\Entity\NodeType;
use Drupal\workflows\Entity\Workflow;
/**
* Implements hook_install().
*/
function lightning_workflow_install() {
if (\Drupal::moduleHandler()->moduleExists('lightning_roles')) {
lightning_workflow_modules_installed(['lightning_roles']);
}
// Stop here during a config sync.
if (\Drupal::isConfigSyncing()) {
return;
}
$workflow = Workflow::load('editorial');
$configuration = $workflow->get('type_settings');
$configuration['states']['review'] = [
'label' => 'In review',
'weight' => -1,
'published' => FALSE,
'default_revision' => FALSE,
];
// Anything in the review state can be sent back to draft, kept in review,
// or published.
$configuration['transitions']['review'] = [
'label' => 'Review',
'from' => [
'draft',
'review',
],
'to' => 'review',
'weight' => 0,
];
$configuration['transitions']['create_new_draft']['from'][] = 'review';
$configuration['transitions']['publish']['from'][] = 'review';
$workflow->set('type_settings', $configuration);
$workflow->save();
foreach (NodeType::loadMultiple() as $node_type) {
lightning_workflow_node_type_insert($node_type);
}
}
/**
* Removed in Lightning 8.x-2.17.
*
* Formerly applied workflow permissions to content management roles.
*
* @deprecated
*/
function lightning_workflow_update_8001() {
}
/**
* Clears the entity type definition cache.
*/
function lightning_workflow_update_8002() {
\Drupal::entityTypeManager()->clearCachedDefinitions();
}
/**
* Removed in Lightning Workflow 8.x-1.0.
*
* Formerly installed the Lightning Scheduled Updates sub-component.
*
* @deprecated
*/
function lightning_workflow_update_8003() {
}
/**
* Removes the latest_revision__node relationship from the content view.
*/
function lightning_workflow_update_8004() {
$config = \Drupal::configFactory()->getEditable('views.view.content');
if ($config->isNew()) {
return;
}
foreach (array_keys($config->get('display')) as $display_id) {
$config->clear("display.$display_id.display_options.relationships.latest_revision__node");
$config->clear("display.$display_id.display_options.fields.forward_revision_exists");
}
$config->save();
}
/**
* Updates the moderation_history view to work with Content Moderation.
*/
function lightning_workflow_update_8005() {
$config = \Drupal::configFactory()->getEditable('views.view.moderation_history');
if ($config->isNew()) {
return;
}
$entity_type_manager = \Drupal::entityTypeManager();
$display_options = 'display.default.display_options';
// Add a relationship to the moderation state.
$key = "$display_options.relationships.moderation_state";
$relationship = $config->get($key);
if (empty($relationship)) {
$config->set($key, [
'id' => 'moderation_state',
'table' => $entity_type_manager->getDefinition('node')->getRevisionDataTable(),
'field' => 'moderation_state',
'relationship' => 'none',
'group_type' => 'group',
'admin_label' => 'Moderation state',
'required' => TRUE,
'entity_type' => 'node',
'plugin_id' => 'standard',
]);
}
// Update the nid argument, if it exists.
$key = "$display_options.arguments.nid";
$argument = $config->get($key);
if ($argument) {
$argument['default_action'] = 'default';
$argument['default_argument_type'] = 'node';
$argument['default_argument_options'] = [];
$config->set($key, $argument);
}
// Update the moderation_state field, if it exists.
$key = "$display_options.fields.moderation_state";
$field = $config->get($key);
if ($field) {
$field['table'] = $entity_type_manager->hasDefinition('content_moderation_state')
? $entity_type_manager->getDefinition('content_moderation_state')->getRevisionDataTable()
: 'content_moderation_state_field_revision';
$field['relationship'] = 'moderation_state';
$field['admin_label'] = 'Moderation state';
$field['click_sort_column'] = 'value';
$field['type'] = 'content_moderation_state';
$field['settings'] = [];
$field['group_column'] = 'value';
$field['entity_type'] = 'content_moderation_state';
$config->set($key, $field);
}
// Update the path of the page display, if it exists.
$key = 'display.page.display_options';
$display = $config->get($key);
if ($display) {
$display['path'] = str_replace('node/%/', 'node/%node/', $display['path']);
$config->set($key, $display);
}
$config->save();
}