-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlocalgov_subsites.module
184 lines (171 loc) · 6.45 KB
/
localgov_subsites.module
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
/**
* @file
* LocalGov Subsites module file.
*/
use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
use Drupal\localgov_roles\RolesHelper;
use Drupal\localgov_subsites\Subsite;
use Drupal\node\NodeInterface;
/**
* Implements hook_theme().
*/
function localgov_subsites_theme($existing, $type, $theme, $path) {
return [
'subsite_navigation' => [
'variables' => [
'menu_name' => '',
'items' => [],
'current_entity' => NULL,
'overview_entity' => NULL,
],
],
'subsite_banner' => [
'variables' => [
'tag' => '',
'heading' => '',
'image' => '',
],
],
'node__localgov_subsites_page__full' => [
'template' => 'node--localgov-subsites-page--full',
'base hook' => 'node',
],
];
}
/**
* Implements hook_localgov_role_default().
*/
function localgov_subsites_localgov_roles_default() {
// Content editing permissions.
$perms = [
RolesHelper::EDITOR_ROLE => [
'create localgov_subsites_overview content',
'create localgov_subsites_page content',
'delete any localgov_subsites_overview content',
'delete any localgov_subsites_page content',
'delete localgov_subsites_overview revisions',
'delete localgov_subsites_page revisions',
'delete own localgov_subsites_overview content',
'delete own localgov_subsites_page content',
'edit any localgov_subsites_overview content',
'edit any localgov_subsites_page content',
'edit own localgov_subsites_overview content',
'edit own localgov_subsites_page content',
'revert localgov_subsites_overview revisions',
'revert localgov_subsites_page revisions',
'view localgov_subsites_overview revisions',
'view localgov_subsites_page revisions',
],
RolesHelper::AUTHOR_ROLE => [
'create localgov_subsites_overview content',
'create localgov_subsites_page content',
'delete own localgov_subsites_overview content',
'delete own localgov_subsites_page content',
'edit own localgov_subsites_overview content',
'edit own localgov_subsites_page content',
'revert localgov_subsites_overview revisions',
'revert localgov_subsites_page revisions',
'view localgov_subsites_overview revisions',
'view localgov_subsites_page revisions',
],
RolesHelper::CONTRIBUTOR_ROLE => [
'create localgov_subsites_overview content',
'create localgov_subsites_page content',
'delete own localgov_subsites_overview content',
'delete own localgov_subsites_page content',
'edit own localgov_subsites_overview content',
'edit own localgov_subsites_page content',
'view localgov_subsites_overview revisions',
'view localgov_subsites_page revisions',
],
];
// Content scheduling permissions required by localgov_workflows.
if (\Drupal::moduleHandler()->moduleExists('localgov_workflows')) {
$perms[RolesHelper::EDITOR_ROLE] = array_merge($perms[RolesHelper::EDITOR_ROLE], [
'add scheduled transitions node localgov_subsites_overview',
'add scheduled transitions node localgov_subsites_page',
'reschedule scheduled transitions node localgov_subsites_overview',
'reschedule scheduled transitions node localgov_subsites_page',
'view scheduled transitions node localgov_subsites_overview',
'view scheduled transitions node localgov_subsites_page',
]);
$perms[RolesHelper::AUTHOR_ROLE] = array_merge($perms[RolesHelper::AUTHOR_ROLE], [
'add scheduled transitions node localgov_subsites_overview',
'add scheduled transitions node localgov_subsites_page',
'reschedule scheduled transitions node localgov_subsites_overview',
'reschedule scheduled transitions node localgov_subsites_page',
'view scheduled transitions node localgov_subsites_overview',
'view scheduled transitions node localgov_subsites_page',
]);
$perms[RolesHelper::CONTRIBUTOR_ROLE] = array_merge($perms[RolesHelper::CONTRIBUTOR_ROLE], [
'add scheduled transitions node localgov_subsites_overview',
'add scheduled transitions node localgov_subsites_page',
'reschedule scheduled transitions node localgov_subsites_overview',
'reschedule scheduled transitions node localgov_subsites_page',
'view scheduled transitions node localgov_subsites_overview',
'view scheduled transitions node localgov_subsites_page',
]);
}
return $perms;
}
/**
* Implements hook_preprocess_page().
*
* Adds a class to the page wrapper with the name of the theme
* if the current node is within a subsite.
*/
function localgov_subsites_preprocess_page(&$variables) {
$node = \Drupal::routeMatch()->getParameter('node');
if (!$node instanceof NodeInterface) {
return;
}
if (in_array($node->bundle(), [
'localgov_subsites_overview',
'localgov_subsites_page',
], TRUE)) {
$subsite = \Drupal::service('class_resolver')
->getInstanceFromDefinition(Subsite::class)
->getSubsite($node);
if ($subsite instanceof NodeInterface && isset($subsite->localgov_subsites_theme->value) && $theme = $subsite->localgov_subsites_theme->value) {
$variables['attributes']['class'][] = str_replace('_', '--', $theme);
}
}
}
/**
* Set form settings for optional services fields on installation.
*/
function localgov_subsites_optional_fields_settings() {
$form_displays = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->loadByProperties([
'targetEntityType' => 'node',
'bundle' => 'localgov_subsites_overview',
]);
if ($form_displays) {
foreach ($form_displays as $form_display) {
assert($form_display instanceof EntityFormDisplayInterface);
if (!$form_display->getComponent('localgov_services_parent')) {
$form_display->setComponent('localgov_services_parent', [
'type' => 'entity_reference_autocomplete',
'region' => 'content',
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'placeholder' => '',
'match_limit' => 10,
],
'weight' => -1,
])->save();
if (
($field_groups = $form_display->getThirdPartySettings('field_group')) &&
($group = $field_groups['group_description'] ?? FALSE)
) {
$group['children'][] = 'localgov_services_parent';
$form_display->setThirdPartySetting('field_group', 'group_description', $group)
->save();
}
}
}
}
}