-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathwxt.profile
114 lines (101 loc) · 2.6 KB
/
wxt.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
<?php
/**
* @file
* Contains wxt.profile.
*/
use Drupal\Core\Session\AccountInterface;
use Drupal\wxt\Installer\Form\ExtensionConfigureForm;
/**
* Implements hook_install_tasks().
*/
function wxt_install_tasks() {
return [
'wxt_install_extensions' => [
'display_name' => t('Install extensions'),
'display' => TRUE,
'type' => 'batch',
],
];
}
/**
* Implements hook_install_tasks_alter().
*/
function wxt_install_tasks_alter(array &$tasks, array $install_state) {
$task = $tasks['wxt_install_extensions'];
unset($tasks['wxt_install_extensions']);
$tasks = array_merge($tasks, ['wxt_install_extensions' => $task]);
array_insert(
$tasks,
"wxt_install_extensions",
[
'wxt_extension_configure_form' => [
'display_name' => t('Select extensions to enable'),
'type' => 'form',
'function' => ExtensionConfigureForm::class,
],
]
);
}
/**
* Install task callback prepares a batch job to install WxT extensions.
*
* @param array $install_state
* The current install state.
*
* @return array
* The batch job definition.
*/
function wxt_install_extensions(array &$install_state) {
$batch = [];
$modules = \Drupal::state()->get('wxt_install_extensions', []);
$install_core_search = TRUE;
foreach ($modules as $module) {
$batch['operations'][] = ['wxt_install_module', (array) $module];
if ($module == 'wxt_ext_search_db') {
$install_core_search = FALSE;
}
}
if ($install_core_search) {
$batch['operations'][] = ['wxt_install_module', (array) 'search'];
}
return $batch;
}
/**
* Batch API callback. Installs a module.
*
* @param string|array $module
* The name(s) of the module(s) to install.
*/
function wxt_install_module($module) {
\Drupal::service('module_installer')->install((array) $module);
if ($module == 'search') {
\Drupal::service('router.builder')->rebuild();
// Enable default permissions for system roles.
user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, [
'search content',
]);
}
}
/**
* Insert new item in array on any position in PHP (Stack Overflow 3797239).
*
* @param array $array
* The original array.
* @param int|string $position
* The current position.
* @param mixed $insert
* The array to insert.
*/
function array_insert(array &$array, $position, $insert) {
if (is_int($position)) {
array_splice($array, $position, 0, $insert);
}
else {
$pos = array_search($position, array_keys($array));
$array = array_merge(
array_slice($array, 0, $pos),
$insert,
array_slice($array, $pos)
);
}
}