-
Notifications
You must be signed in to change notification settings - Fork 1
/
lightning_dxpr.profile
110 lines (95 loc) · 3.49 KB
/
lightning_dxpr.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
<?php
/**
* @file
* Enables modules and site configuration for the Lightning DXPR profile.
*/
/**
* Implements hook_install_tasks().
*/
function lightning_dxpr_install_tasks(&$install_state) {
$tasks = [
'lightning_dxpr_demo_select' => [
'display_name' => t('Select Demo'),
'type' => 'form',
'function' => 'Drupal\lightning_dxpr\Form\DemoSelectForm',
],
'lightning_dxpr_module_install' => [
'display_name' => t('Install additional modules'),
'type' => 'batch',
],
];
return $tasks;
}
/**
* Installs the CMS modules in a batch.
*
* @param array $install_state
* The install state.
*
* @return array
* A batch array to execute.
*/
function lightning_dxpr_module_install(array &$install_state) {
// Installed separately here so that it can detect and connect any pre-
// installed media browsers
Drupal::service('module_installer')->install(['dxpr_builder'], TRUE);
Drupal::service('module_installer')->install(['dxpr_builder_page'], TRUE);
Drupal::service('module_installer')->install(['dxpr_builder_block'], TRUE);
$batch = [];
if ($install_state['demo_select'] !== 'none') {
$operations = [];
$modules = ['default_content', $install_state['demo_select']];
foreach ($modules as $module) {
$operations[] = ['lightning_dxpr_install_module_batch', [$module]];
}
$operations[] = ['lightning_dxpr_cleanup_batch', [$install_state['demo_select']]];
$batch = [
'operations' => $operations,
'title' => t('Installing additional modules'),
'error_message' => t('The installation has encountered an error.'),
];
return $batch;
}
}
/**
* Implements callback_batch_operation().
*
* Performs batch installation of modules.
*/
function lightning_dxpr_install_module_batch($module, &$context) {
// CMS Modules are not available yet.
Drupal::service('module_installer')->install([$module], TRUE);
$context['results'][] = $module;
$context['message'] = t('Installed %module_name module.', ['%module_name' => $module]);
}
/**
* Implements callback_batch_operation().
*/
function lightning_dxpr_cleanup_batch($module, &$context) {
Drupal::service('module_installer')->uninstall(['default_content'], FALSE);
// Update url aliases with menu tokens (only needed for alises that reflect menu structure)
$result = \Drupal::entityQuery('node')->execute();
$entity_storage = \Drupal::entityTypeManager()->getStorage('node');
$entities = $entity_storage->loadMultiple($result);
foreach ($entities as $entity) {
\Drupal::service('pathauto.generator')->updateEntityAlias($entity, 'update');
}
// We're doing this here because during hook_install it fails due to demo content loading
// after installation (when default_content module steps in).
$module_path = drupal_get_path('module', $module);
if ($path = file_get_contents($module_path . '/front-path.txt')) {
if ($nid = Drupal::database()->query("SELECT nid FROM {node} WHERE uuid = '" . $path . "'")->fetchField()) {
Drupal::configFactory()->getEditable('system.site')->set('page.front', '/node/' . $nid)->save(TRUE);
}
else {
$front_page = Drupal::entityTypeManager()->getStorage('node')->loadByProperties(['uuid' => $path]);
if ($front_page) {
Drupal::configFactory()->getEditable('system.site')->set('page.front', $path)->save(TRUE);
}
else {
Drupal::configFactory()->getEditable('system.site')->set('page.front', '/')->save(TRUE);
}
}
}
$context['message'] = t('Cleanup.');
}