-
Notifications
You must be signed in to change notification settings - Fork 4
/
vardoc.profile
executable file
·316 lines (261 loc) · 11.4 KB
/
vardoc.profile
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<?php
/**
* @file
* Enables modules and site configuration for a Vardoc site installation.
*/
use Drupal\Core\Form\FormStateInterface;
use Drupal\varbase\Config\ConfigBit;
use Vardot\Entity\EntityDefinitionUpdateManager;
use Drupal\path_alias\Entity\PathAlias;
use Drupal\vardoc\Form\VardocAssemblerForm;
/**
* Implements hook_form_FORM_ID_alter() for install_configure_form().
*
* Allows the profile to alter the site configuration form.
*/
function vardoc_form_install_configure_form_alter(&$form, FormStateInterface $form_state) {
include_once \Drupal::service('extension.path.resolver')->getPath('profile', 'varbase') . '/varbase.profile';
varbase_form_install_configure_form_alter($form, $form_state);
}
/**
* Implements hook_install_tasks().
*/
function vardoc_install_tasks(&$install_state) {
include_once \Drupal::service('extension.path.resolver')->getPath('profile', 'varbase') . '/varbase.profile';
$varbase_install_tasks = varbase_install_tasks($install_state);
return [
'vardoc_extra_components' => [
'display_name' => t('Extra components'),
'display' => TRUE,
'type' => 'form',
'function' => VardocAssemblerForm::class,
],
'vardoc_assemble_extra_components' => [
'display_name' => t('Assemble extra components'),
'display' => TRUE,
'type' => 'batch',
],
'varbase_development_tools' => $varbase_install_tasks['varbase_development_tools'],
'varbase_assemble_development_tools' => $varbase_install_tasks['varbase_assemble_development_tools'],
];
}
/**
* Implements hook_install_tasks_alter().
*/
function vardoc_install_tasks_alter(array &$tasks, array $install_state) {
include_once \Drupal::service('extension.path.resolver')->getPath('profile', 'varbase') . '/varbase.profile';
// Skip select language step to install it in English as default language.
unset($tasks['install_select_language']);
unset($tasks['install_download_translation']);
$tasks['install_finished']['function'] = 'vardoc_after_install_finished';
}
/**
* Batch job to assemble Varbase extra components.
*
* @param array $install_state
* The current install state.
*
* @return array
* The batch job definition.
*/
function vardoc_assemble_extra_components(array &$install_state) {
include_once \Drupal::service('extension.path.resolver')->getPath('profile', 'varbase') . '/varbase.profile';
// Default Vardoc components, which must be installed.
$default_components = ConfigBit::getList('configbit/default.components.vardoc.bit.yml', 'install_default_components', TRUE, 'dependencies', 'profile', 'vardoc');
$batch = [];
// Install default components first.
foreach ($default_components as $default_component) {
$batch['operations'][] = ['varbase_assemble_extra_component_then_install', (array) $default_component];
}
// Install selected extra features.
$selected_extra_features = [];
$selected_extra_features_configs = [];
if (isset($install_state['varbase']['extra_features_values'])) {
$selected_extra_features = $install_state['varbase']['extra_features_values'];
}
if (isset($install_state['varbase']['extra_features_configs'])) {
$selected_extra_features_configs = $install_state['varbase']['extra_features_configs'];
}
// Get the list of extra features config bits.
$extraFeatures = ConfigBit::getList('configbit/extra.components.vardoc.bit.yml', 'show_extra_components', TRUE, 'dependencies', 'profile', 'vardoc');
// If we do have selected extra features.
if (count($selected_extra_features) && count($extraFeatures)) {
// Have batch processes for each selected extra features.
foreach ($selected_extra_features as $extra_feature_key => $extra_feature_checked) {
if ($extra_feature_checked) {
// If the extra feature was a module and not enabled, then enable it.
if (!\Drupal::moduleHandler()->moduleExists($extra_feature_key)) {
// Add the checked extra feature to the batch process to be enabled.
$batch['operations'][] = ['varbase_assemble_extra_component_then_install', (array) $extra_feature_key];
}
if (count($selected_extra_features_configs) &&
isset($extraFeatures[$extra_feature_key]['config_form']) &&
$extraFeatures[$extra_feature_key]['config_form'] == TRUE &&
isset($extraFeatures[$extra_feature_key]['formbit'])) {
$formbit_file_name = \Drupal::service('extension.path.resolver')->getPath('profile', 'vardoc') . '/' . $extraFeatures[$extra_feature_key]['formbit'];
if (file_exists($formbit_file_name)) {
// Added the selected extra feature configs to the batch process
// with the same function name in the formbit.
$batch['operations'][] = ['varbase_save_editable_config_values', (array) [$extra_feature_key, $formbit_file_name, $selected_extra_features_configs]];
}
}
}
}
// Hide Wornings and status messages.
$batch['operations'][] = ['varbase_hide_warning_and_status_messages', (array) TRUE];
// Fix entity updates to clear up any mismatched entity.
$batch['operations'][] = ['varbase_fix_entity_update', (array) TRUE];
// Rebuilds all permissions on site content, and may be a lengthy process.
$batch['operations'][] = ['vardoc_node_access_rebuild', (array) TRUE];
}
// Install selected Demo content.
$selected_demo_content = [];
$selected_demo_content_configs = [];
if (isset($install_state['varbase']['demo_content_values'])) {
$selected_demo_content = $install_state['varbase']['demo_content_values'];
}
if (isset($install_state['varbase']['demo_content_configs'])) {
$selected_demo_content_configs = $install_state['varbase']['demo_content_configs'];
}
// Get the list of demo content config bits.
$demoContent = ConfigBit::getList('configbit/demo.content.vardoc.bit.yml', 'show_demo', TRUE, 'dependencies', 'profile', 'vardoc');
// If we do have demo_content and we have selected demo_content.
if (count($selected_demo_content) && count($demoContent)) {
// Have batch processes for each selected demo content.
foreach ($selected_demo_content as $demo_content_key => $demo_content_checked) {
if ($demo_content_checked) {
// If the demo content was a module and not enabled, then enable it.
if (!\Drupal::moduleHandler()->moduleExists($demo_content_key)) {
// Add the checked demo content to the batch process to be enabled.
$batch['operations'][] = ['varbase_assemble_extra_component_then_install', (array) $demo_content_key];
}
if (count($selected_demo_content_configs) &&
isset($demoContent[$demo_content_key]['config_form']) &&
$demoContent[$demo_content_key]['config_form'] == TRUE &&
isset($demoContent[$demo_content_key]['formbit'])) {
$formbit_file_name = \Drupal::service('extension.path.resolver')->getPath('profile', 'varbase') . '/' . $demoContent[$demo_content_key]['formbit'];
if (file_exists($formbit_file_name)) {
// Added the selected development configs to the batch process
// with the same function name in the formbit.
$batch['operations'][] = [
'varbase_save_editable_config_values',
[
$demo_content_key,
$formbit_file_name,
$selected_demo_content_configs,
],
];
}
}
}
}
// Hide Wornings and status messages.
$batch['operations'][] = ['varbase_hide_warning_and_status_messages', (array) TRUE];
// Fix entity updates to clear up any mismatched entity.
$batch['operations'][] = ['varbase_fix_entity_update', (array) TRUE];
// Rebuilds all permissions on site content, and may be a lengthy process.
$batch['operations'][] = ['vardoc_node_access_rebuild', (array) TRUE];
}
return $batch;
}
/**
* Vardoc after install finished.
*
* @param array $install_state
* The current install state.
*
* @return array
* A renderable array with a redirect header.
*/
function vardoc_after_install_finished(array &$install_state) {
// Mark all updates by the update helper checklist as successful on install.
if (\Drupal::moduleHandler()->moduleExists('update_helper_checklist')) {
$checkList = \Drupal::service('update_helper_checklist.update_checklist');
$checkList->markAllUpdates();
}
// Entity updates to clear up any mismatched entity and/or field definitions
// And Fix changes were detected in the entity type and field definitions.
\Drupal::classResolver()
->getInstanceFromDefinition(EntityDefinitionUpdateManager::class)
->applyUpdates();
// Full flash and clear cash and rebuilding newly created routes.
// After install of extra modules by install: in the .info.yml files.
// In Varbase profile and all Varbase components.
// ---------------------------------------------------------------------------
// * Necessary inlitilization for the entire system.
// * Account for changed config by the end install.
// * Flush all persistent caches.
// * Flush asset file caches.
// * Wipe the Twig PHP Storage cache.
// * Rebuild module and theme data.
// * Clear all plugin caches.
// * Rebuild the menu router based on all rebuilt data.
drupal_flush_all_caches();
// Set front page to "/node".
// Issue #3188641: Change the set front page to "/node" process from
// using static node id to front page path by the alias.
// https://www.drupal.org/project/varbase_core/issues/3188641
try {
$path_alias_query = \Drupal::entityQuery('path_alias');
$path_alias_query->condition('alias', '/node', '=');
$alias_ids = $path_alias_query->execute();
if (count($alias_ids) > 0) {
foreach ($alias_ids as $alias_id) {
if (!(end($alias_ids))) {
$path_alias = PathAlias::load($alias_id);
$path_alias->delete();
}
else {
$page_front_path = PathAlias::load($alias_id)->getPath();
\Drupal::configFactory()->getEditable('system.site')
->set('page.front', $page_front_path)
->save();
}
}
}
}
catch (\Exception $e) {
\Drupal::messenger()->addError($e->getMessage());
}
global $base_url;
// After install direction.
$after_install_direction = $base_url . '/';
install_finished($install_state);
$output = [];
// Clear all messages.
\Drupal::service('messenger')->deleteAll();
$output = [
'#title' => t('Vardoc'),
'info' => [
'#markup' => t('<p>Congratulations, you have installed Vardoc!</p><p>If you are not redirected to the front page in 5 seconds, Please <a href="@url">click here</a> to proceed to your installed site.</p>', [
'@url' => $after_install_direction,
]),
],
'#attached' => [
'http_header' => [
['Cache-Control', 'no-cache'],
],
],
];
$output['#attached']['library'][] = 'vardoc/install_page';
$meta_redirect = [
'#tag' => 'meta',
'#attributes' => [
'http-equiv' => 'refresh',
'content' => '0;url=' . $after_install_direction,
],
];
$output['#attached']['html_head'][] = [$meta_redirect, 'meta_redirect'];
return $output;
}
/**
* Rebuilds all permissions on site content, and may be a lengthy process.
*
* @param string|array $rebuild_permissions
* To rebuilds permissions or not.
*/
function vardoc_node_access_rebuild($rebuild_permissions) {
if ($rebuild_permissions) {
node_access_rebuild(TRUE);
}
}