-
Notifications
You must be signed in to change notification settings - Fork 21
/
az_quickstart.install
219 lines (198 loc) · 6.52 KB
/
az_quickstart.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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
/**
* @file
* Install, update and uninstall functions for az_quickstart install profile.
*/
use Drupal\Core\Extension\MissingDependencyException;
use Drupal\Core\Link;
use Drupal\Core\Render\Markup;
use Drupal\Core\Url;
use Drupal\shortcut\Entity\Shortcut;
/**
* Implements hook_install().
*
* Perform actions to set up the site for this profile.
*
* @see system_install()
*/
function az_quickstart_install() {
// Populate the default shortcut set.
$shortcut = Shortcut::create([
'shortcut_set' => 'default',
'title' => t('Add content'),
'weight' => -20,
'link' => ['uri' => 'internal:/node/add'],
]);
$shortcut->save();
$shortcut = Shortcut::create([
'shortcut_set' => 'default',
'title' => t('All content'),
'weight' => -19,
'link' => ['uri' => 'internal:/admin/content'],
]);
$shortcut->save();
// Install additional modules if site is running on Pantheon (or not).
if (defined('PANTHEON_ENVIRONMENT')) {
// Modules to install only on Pantheon.
$extra_modules = [
'pantheon_advanced_page_cache',
'environment_indicator',
];
}
else {
// Modules to install if not on Pantheon.
$extra_modules = [
'big_pipe',
];
}
foreach ($extra_modules as $module) {
try {
\Drupal::service('module_installer')->install([$module]);
}
catch (MissingDependencyException $e) {
\Drupal::logger('az_quickstart')->warning('@module module not available to install.', ['@module' => $module]);
}
}
}
/**
* Implements hook_requirements().
*/
function az_quickstart_requirements($phase) {
$requirements = [];
if ($phase === 'runtime') {
// Reset the extension lists.
/** @var \Drupal\Core\Extension\ModuleExtensionList $module_extension_list */
$module_extension_list = \Drupal::service('extension.list.module');
$module_extension_list->reset();
// Gather all deprecated modules that are enabled.
$azqs_deprecated_modules = [
'ctools',
'jquery_ui_slider',
'jquery_ui_touch_punch',
];
$enabled_deprecated_modules = [];
$enabled_modules = \Drupal::moduleHandler()->getModuleList();
foreach ($enabled_modules as $module => $data) {
if (in_array($module, $azqs_deprecated_modules)) {
$enabled_deprecated_modules[$module] = $module_extension_list->getExtensionInfo($module)['name'];
}
}
// Warn if any deprecated modules are installed.
if (!empty($enabled_deprecated_modules)) {
foreach ($enabled_deprecated_modules as $deprecated_module => $name) {
$deprecated_modules_link_list[] = (string) Link::fromTextAndUrl($name, Url::fromUri('https://www.drupal.org/project/' . $deprecated_module))->toString();
}
$requirements['azqs_deprecated_modules'] = [
'title' => t('Quickstart deprecated modules enabled'),
'description' => t('These modules are no longer used by Arizona Quickstart and will be removed in a future release. These modules should be uninstalled or should be added to a site-specific composer.json file if they are still needed, or your site will not be able to be updated via Composer. Some action is required prior to updating to the next minor version.'),
'value' => t('Enabled Quickstart deprecated modules found: %module_list.', [
'%module_list' => Markup::create(implode(', ', $deprecated_modules_link_list)),
]),
'severity' => REQUIREMENT_WARNING,
];
}
}
return $requirements;
}
/**
* Implements hook_update_last_removed().
*/
function az_quickstart_update_last_removed() {
// Remove updates added before 2.6.0.
return 920103;
}
/**
* Uninstall the deprecated media_library_theme_reset module.
*/
function az_quickstart_update_920601() {
\Drupal::service('module_installer')->uninstall(['media_library_theme_reset']);
}
/**
* Change Arizona Bootstrap CDN references.
*/
function az_quickstart_update_920602() {
$config = \Drupal::service('config.factory')->getEditable('az_barrio.settings');
if ($config->get('az_bootstrap_cdn_version') === 'main') {
$config->set('az_bootstrap_cdn_version', '2.x')->save(TRUE);
}
if ($config->get('az_bootstrap_cdn_version') === 'latest') {
$config->set('az_bootstrap_cdn_version', 'latest-2.x')->save(TRUE);
}
}
/**
* Uninstall deprecated Drupal core modules.
*/
function az_quickstart_update_920603() {
$deprecated_modules = [
'aggregator',
'color',
'hal',
'quickedit',
'rdf',
];
\Drupal::service('module_installer')->uninstall($deprecated_modules);
}
/**
* Ensure block_class module is installed.
*/
function az_quickstart_update_920604() {
\Drupal::service('module_installer')->install(['block_class']);
}
/**
* Ensure media_entity_file_replace module is installed.
*/
function az_quickstart_update_920701() {
\Drupal::service('module_installer')->install(['media_entity_file_replace']);
}
/**
* Enable az_paragraphs_splitscreen module by default.
*/
function az_quickstart_update_920702() {
\Drupal::service('module_installer')->install(['az_paragraphs_splitscreen']);
}
/**
* Ensure ckeditor5 module is installed.
*/
function az_quickstart_update_1020801() {
\Drupal::service('module_installer')->install(['ckeditor5']);
}
/**
* Enable extlink module by default.
*/
function az_quickstart_update_1020802() {
\Drupal::service('module_installer')->install(['extlink']);
}
/**
* Uninstall unsupported media_library_theme_reset module.
*/
function az_quickstart_update_1020803() {
\Drupal::service('module_installer')->uninstall(['media_library_theme_reset']);
}
/**
* Update langcode for migrated menu links to be the site's default language.
*/
function az_quickstart_update_1020901(&$sandbox) {
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['max'] = \Drupal::entityQuery('menu_link_content')
->accessCheck(FALSE)
->condition('langcode', 'und')
->count()
->execute();
}
$batch_size = 25;
$default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId();
$ids = \Drupal::entityQuery('menu_link_content')
->accessCheck(FALSE)
->condition('langcode', 'und')
->range(0, $batch_size)
->execute();
$menu_links = \Drupal::entityTypeManager()->getStorage('menu_link_content')->loadMultiple($ids);
foreach ($menu_links as $menu_link) {
$menu_link->langcode = $default_langcode;
$menu_link->save();
$sandbox['progress']++;
}
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
return t('Updated langcode on %count menu links.', ['%count' => $sandbox['progress']]);
}