This repository has been archived by the owner on Jul 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcamp.profile
148 lines (128 loc) · 3.9 KB
/
camp.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
<?php
/**
* @file
* Enables modules and site configuration for a Camp Distro site installation.
*/
use Drupal\Core\Form\FormStateInterface;
use Drupal\camp\Form\AssemblerForm;
use Drupal\camp\Form\FeatureForm;
/**
* Implements hook_form_FORM_ID_alter() for install_configure_form().
*
* Allows the profile to alter the site configuration form.
*/
function camp_form_install_configure_form_alter(&$form, FormStateInterface $form_state) {
// Add a placeholder as example that one can choose an arbitrary site name.
$form['site_information']['site_name']['#attributes']['placeholder'] = t('Camp Name');
$form['site_information']['site_name']['#title'] = t('Camp Name');
$form['#title'] = t('Configure Camp');
}
/**
* Implements hook_install_tasks().
*/
function camp_install_tasks(&$install_state) {
return array(
'camp_features' => array(
'display_name' => t('Camp Features'),
'display' => TRUE,
'type' => 'form',
'function' => FeatureForm::class,
),
'camp_features_install' => array(
'display_name' => t('Install Features'),
'display' => FALSE,
'type' => 'batch',
),
'camp_assemble_extra_components' => array(
'display_name' => t('Configure Features'),
'display' => TRUE,
'type' => 'form',
'function' => AssemblerForm::class,
),
);
}
/**
* Implements hook_install_tasks_alter().
*/
function camp_install_tasks_alter(&$tasks, $install_state) {
$tasks['install_finished']['function'] = 'camp_after_install_finished';
}
/**
* Batch job to assemble Camp extra components.
*
* @param array $install_state
* The current install state.
*
* @return array
* The batch job definition.
*/
function camp_features_install(array &$install_state) {
$batch = [
'title' => t('Installing additional features'),
'init_message' => t('Starting to build camp features.'),
'progress_message' => t('Installed Feature @current step of @total.'),
'error_message' => t('The installation has encountered an error.'),
'operations' => []
];
array_walk($install_state['camp_features'], function($module) use (&$batch){
$batch['operations'][] = ['camp_assemble_extra_component_then_install', (array) $module];
});
return $batch;
}
/**
* Camp Distro after install finished.
*
* Lanuch auto Camp Tour auto launch after install.
*
* @param array $install_state
* The current install state.
*
* @return array
* A renderable array with a redirect header.
*/
function camp_after_install_finished(array &$install_state) {
global $base_url;
// After install direction.
$after_install_direction = $base_url . '/?welcome';
install_finished($install_state);
$output = [];
// Clear all messages.
drupal_get_messages();
$output = [
'#title' => t('Camp Distro'),
'info' => [
'#markup' => t('<p>Congratulations, you have installed Camp Distro!</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 insalled site.</p>', [
'@url' => $after_install_direction,
]),
],
'#attached' => [
'http_header' => [
['Cache-Control', 'no-cache'],
],
],
];
$meta_redirect = [
'#tag' => 'meta',
'#attributes' => [
'http-equiv' => 'refresh',
'content' => '0;url=' . $after_install_direction,
],
];
$output['#attached']['html_head'][] = [$meta_redirect, 'meta_redirect'];
return $output;
}
/**
* Batch function to assemble and install needed extra components.
*
* @param string|array $extra_component
* Name of the extra component.
*/
function camp_assemble_extra_component_then_install($extra_component, &$context) {
try {
\Drupal::service('module_installer')->install((array) $extra_component, TRUE);
}
catch (\Exception $e) {
}
$context['results'][] = $extra_component;
$context['message'] = t('Installed Feature: %module_name', ['%module_name' => $extra_component]);
}