Repository navigation
Expand file tree
/
Copy pathtide_core.install
More file actions
194 lines (161 loc) · 5.28 KB
/
Copy pathtide_core.install
File metadata and controls
194 lines (161 loc) · 5.28 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
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
185
186
187
188
189
190
191
192
193
194
<?php
/**
* @file
* Installation functions for Tide Core.
*/
use Drupal\filter\FilterFormatInterface;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\tide_core\TideCoreOperation;
use Drupal\user\Entity\User;
use Drupal\user\UserInterface;
/**
* Implements hook_install().
*/
function tide_core_install() {
// Don't do anything else during config sync.
if (\Drupal::isConfigSyncing()) {
return;
}
// Assign user 1 the "administrator" role.
$user = User::load(1);
$user->roles[] = 'administrator';
$user->save();
// Restrict user registration to admin role creation.
\Drupal::configFactory()
->getEditable('user.settings')
->set('register', UserInterface::REGISTER_ADMINISTRATORS_ONLY)
->save(TRUE);
$tideCoreOperation = new TideCoreOperation();
// Creates terms for Topic vocabulary.
$tideCoreOperation->createTopicTermsVocabulary();
// Creates terms for content_category vocabulary.
$tideCoreOperation->addContentCategoryVocabulary();
// Update default Editorial workflow of Content Moderation.
$tideCoreOperation->updateEditorialWorkflow();
// Update authenticated user permission.
$tideCoreOperation->updateAuthenticatedUserPermission();
// Deletes unsupported actions from /admin/contents view.
$tideCoreOperation->deleteUnsupportedActions();
// Add business contact fields to user account form display.
$tideCoreOperation->addBusinessFieldsToUserAccountForm();
// Use custom files view and disable the default one.
$tideCoreOperation->useCustomFilesView();
// Changes the diff modules general_settings.revision_pager_limit to 16.
$tideCoreOperation->changeDiffSettings();
// Enable Tide TFA.
$tideCoreOperation->enabledTideTfa();
// Assign permissions for CKEditor template usage.
$tideCoreOperation->assignCkeditorTemplatesPermission();
// Enable the JSON-LD engine schema defaults (WebPage + BreadcrumbList) on the
// node metatag default.
$tideCoreOperation->enableJsonLdSchemaDefaults();
}
/**
* Add CDN sources required by JavaScript components to the SecKit CSP.
*/
function tide_core_update_11002() {
$config = \Drupal::configFactory()->getEditable('seckit.settings');
if ($config->isNew()) {
return;
}
$sources = [
'seckit_xss.csp.script-src' => [
'cdnjs.cloudflare.com',
'unpkg.com',
],
'seckit_xss.csp.style-src' => [
'cdnjs.cloudflare.com',
'unpkg.com',
],
'seckit_xss.csp.img-src' => [
'cdn.jsdelivr.net',
],
];
$changed = FALSE;
foreach ($sources as $key => $required_sources) {
$current_sources = preg_split('/\s+/', trim((string) $config->get($key)), -1, PREG_SPLIT_NO_EMPTY);
foreach ($required_sources as $required_source) {
if (!in_array($required_source, $current_sources, TRUE)) {
$current_sources[] = $required_source;
$changed = TRUE;
}
}
$config->set($key, implode(' ', $current_sources));
}
if ($changed) {
$config->save(TRUE);
}
}
/**
* Ensure the JSON-LD schema modules and defaults are installed.
*/
function tide_core_update_11003() {
(new TideCoreOperation())->enableJsonLdSchemaDefaults();
}
/**
* Run HTML filtering before caption processing in Rich Text.
*/
function tide_core_update_11004() {
$format = \Drupal::entityTypeManager()
->getStorage('filter_format')
->load('rich_text');
if (!$format instanceof FilterFormatInterface) {
return;
}
$filters = $format->toArray()['filters'] ?? [];
if (!isset($filters['filter_html'])) {
return;
}
$configuration = $filters['filter_html'];
$configuration['weight'] = -51;
$format
->setFilterConfig('filter_html', $configuration)
->save();
}
/**
* Enable the iframe permissions filter for existing text formats.
*/
function tide_core_update_11005() {
$configuration = [
'id' => 'tide_ckeditor_iframe_permissions',
'provider' => 'tide_core',
'status' => TRUE,
'weight' => 101,
'settings' => [],
];
$storage = \Drupal::entityTypeManager()->getStorage('filter_format');
foreach (['rich_text', 'admin_text', 'summary_text'] as $format_id) {
$format = $storage->load($format_id);
if ($format instanceof FilterFormatInterface) {
$format
->setFilterConfig('tide_ckeditor_iframe_permissions', $configuration)
->save();
}
}
}
/**
* Clean up Paragraph fields without handler settings from form displays.
*/
function tide_core_update_11006() {
/** @var \Drupal\field\Entity\FieldConfig[] $field_configs */
$field_configs = FieldConfig::loadMultiple();
foreach ($field_configs as $field_config) {
$handler = $field_config->getSetting('handler');
$handler_settings = $field_config->getSetting('handler_settings');
if ($handler === 'default:paragraph' && empty($handler_settings)) {
$entity_type = $field_config->getTargetEntityTypeId();
$bundle = $field_config->getTargetBundle();
$field_name = $field_config->getName();
$form_display_id = $entity_type . '.' . $bundle . '.default';
$form_display = EntityFormDisplay::load($form_display_id);
if ($form_display) {
$component = $form_display->getComponent($field_name);
if ($component !== NULL) {
$form_display->removeComponent($field_name);
$form_display->save();
}
}
}
}
}