forked from ymcatwincities/openy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopeny.profile
185 lines (171 loc) · 4.26 KB
/
openy.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
<?php
/**
* @file
* Defines the OpenY Profile install screen by modifying the install form.
*/
use Drupal\openy\Form\ContentSelectForm;
use Drupal\openy\Form\ThirdPartyServicesForm;
/**
* Implements hook_install_tasks().
*/
function openy_install_tasks() {
return [
'openy_select_content' => [
'display_name' => t('Import demo content'),
'display' => TRUE,
'type' => 'form',
'function' => ContentSelectForm::class,
],
'openy_import_content' => [
'type' => 'batch',
],
'openy_third_party_services' => [
'display_name' => t('3rd party services'),
'display' => TRUE,
'type' => 'form',
'function' => ThirdPartyServicesForm::class,
],
];
}
/**
* Mapping for demo content configs.
*
* @param null|string $key
* Name of the section with demo content.
*
* @return array
* Mapping array.
*/
function openy_demo_content_configs_map($key = NULL) {
// Maps selection to migrations.
$map = [
'required' => [],
'optional' => [
'openy_demo_tcolor' => [
'openy_demo_taxonomy_term_color',
],
'openy_demo_tarea' => [
'openy_demo_taxonomy_term_area',
],
'openy_demo_tblog' => [
'openy_demo_taxonomy_term_blog_category',
],
'openy_demo_tfacility' => [
'openy_demo_taxonomy_term_facility_type',
],
'openy_demo_bfooter' => [
'openy_demo_block_content_footer',
],
],
'branches' => [
'openy_demo_nbranch' => [
'openy_demo_node_branch',
],
],
'camps' => [
'openy_demo_ncamp' => [
'openy_demo_node_camp',
],
],
'blog' => [
'openy_demo_nblog' => [
'openy_demo_node_blog',
],
],
'landing' => [
'openy_demo_nlanding' => [
'openy_demo_node_landing',
],
],
'programs' => [
'openy_demo_nprogram' => [
'openy_demo_node_program',
],
'openy_demo_ncategory' => [
'openy_demo_node_program_subcategory',
],
],
'home_alt' => [
'openy_demo_nhome_alt' => [
'openy_demo_node_home_alt_landing',
],
],
'menus' => [
'openy_demo_menu_main' => [
'openy_demo_menu_link_main',
],
'openy_demo_menu_footer' => [
'openy_demo_menu_link_footer',
],
],
];
return array_key_exists($key, $map) ? $map[$key] : [];
}
/**
* Create batch for content import.
*
* @param array $install_state
* Installation parameters.
*
* @return array
* Batch.
*/
function openy_import_content(array &$install_state) {
$batch = [];
// Run required migrations.
_openy_import_content_helper($batch, 'required');
// Run optional migrations only if at least one option has been selected.
if (!empty($install_state['openy']['content'])) {
_openy_import_content_helper($batch, 'optional');
}
// Add home_alt if landing is not included.
if (!in_array('landing', $install_state['openy']['content'])) {
$install_state['openy']['content'][] = 'home_alt';
}
// Run migrations for selected content.
foreach ($install_state['openy']['content'] as $content) {
_openy_import_content_helper($batch, $content);
}
return $batch;
}
/**
* Demo content import helper.
*
* @param array $batch
* List of batch operations.
* @param string $key
* Key of the section in the mapping.
*/
function _openy_import_content_helper(array &$batch, $key) {
$modules = openy_demo_content_configs_map($key);
if (empty($modules)) {
return;
}
foreach ($modules as $key => $migrations) {
$batch['operations'][] = ['openy_enable_module', (array) $key];
foreach ($migrations as $migration) {
$batch['operations'][] = ['openy_import_migration', (array) $migration];
}
}
}
/**
* Enable module with demo content.
*
* @param string $module_name
* Module name.
*/
function openy_enable_module($module_name) {
/** @var \Drupal\Core\Extension\ModuleInstaller $service */
$service = \Drupal::service('module_installer');
$service->install([$module_name]);
}
/**
* Import single migration (with dependencies).
*
* @param string $migration_id
* Migration ID.
*/
function openy_import_migration($migration_id) {
$importer = \Drupal::service('openy_migrate.importer');
$importer->import($migration_id);
}