-
Notifications
You must be signed in to change notification settings - Fork 3
/
os2forms.install
224 lines (198 loc) · 6.35 KB
/
os2forms.install
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
<?php
/**
* @file
* Install file for OS2Forms module.
*/
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\taxonomy\Entity\Term;
use Symfony\Component\Yaml\Yaml;
/**
* Reads in new configuration.
*
* @param string $config_name
* Configuration name.
*/
function os2forms_read_in_new_config($config_name, $moduleName = '') {
$path = \Drupal::service('extension.list.module')->getPath($moduleName ?: 'os2forms');
/** @var \Drupal\Core\Config\StorageInterface $active_storage */
$active_storage = \Drupal::service('config.storage');
$active_storage->write($config_name, Yaml::parse(file_get_contents($path . '/config/optional/' . $config_name . '.yml')));
}
/**
* Implements hook_requirements().
*/
function os2forms_requirements($phase) {
$requirements = [];
if ($phase !== 'runtime') {
return $requirements;
}
$config = \Drupal::service('config.factory')->get('entity_print.settings');
$severity = REQUIREMENT_OK;
if (!empty($config) && \Drupal::moduleHandler()->moduleExists('webform_entity_print_attachment')) {
$messages = [
'#prefix' => t('Entity print configuration'),
'#theme' => 'item_list',
'#items' => [],
];
foreach (['pdf', 'word_docx'] as $type) {
$library = $config->get('print_engines.' . $type . '_engine');
if (empty($library)) {
$severity = REQUIREMENT_WARNING;
$library = t('<strong>EMPTY</strong>');
}
$messages['#items'][] = $library_status = t('Engine @type: @value', [
'@type' => $type,
'@value' => $library,
]);
}
$messages = \Drupal::service('renderer')->renderPlain($messages);
}
else {
$messages = t('Webform Entity Print Attachment module is not enabled');
$severity = REQUIREMENT_WARNING;
}
$requirements['os2forms'] = [
'title' => t('os2forms'),
'severity' => $severity,
'value' => $messages,
];
$commit_sha = exec('git rev-parse HEAD');
$tag = exec("git describe --tags --abbrev=0");
$remote = exec('git config --get remote.origin.url');
$version_messages = [
'#prefix' => t('OS2Forms version'),
'#theme' => 'item_list',
'#items' => [
0 => t('tag <strong>@tag</strong> (commit: <strong>@commit</strong>)', [
'@tag' => $tag,
'@commit' => $commit_sha,
]),
1 => t('remote: <strong>@remote</strong>', [
'@remote' => $remote,
]),
],
];
$requirements['os2forms_version'] = [
'title' => t('OS2Forms Version'),
'severity' => REQUIREMENT_INFO,
'value' => \Drupal::service('renderer')->renderPlain($version_messages),
];
return $requirements;
}
/**
* Implements hook_install().
*/
function os2forms_install() {
// Add Application terms.
_os2form_install_init_application_terms();
// Add Area terms.
_os2form_install_init_area_terms();
}
/**
* Implements hook_update_N().
*
* Enable webform_entity_print_attachment module.
*/
function os2forms_update_8901() {
\Drupal::service('module_installer')->install(['webform_entity_print_attachment']);
}
/**
* Implements hook_update_N().
*
* Enable os2forms_webform_texts and webform_composite module.
*/
function os2forms_update_8903() {
\Drupal::service('module_installer')->install(['os2forms_webform_texts']);
\Drupal::service('module_installer')->install(['webform_composite']);
}
/**
* Implements hook_update_N().
*
* Create fields Application and Area as taxonomy.
*/
function os2forms_update_8904() {
// Create Application taxonomy.
os2forms_read_in_new_config('taxonomy.vocabulary.os2forms_tax_application');
// Add Application terms.
_os2form_install_init_application_terms();
// Create Area taxonomy.
os2forms_read_in_new_config('taxonomy.vocabulary.os2forms_tax_area');
// Add Area terms.
_os2form_install_init_area_terms();
// Add field field.field.node.webform.field_os2forms_wff_area.
// Field storage.
$path = \Drupal::service('extension.list.module')->getPath('os2forms');
$field_storage_yml = Yaml::parse(file_get_contents("$path/config/optional/field.storage.node.field_os2forms_wff_area.yml"));
if (!FieldStorageConfig::loadByName('node', 'field_os2forms_wff_area')) {
FieldStorageConfig::create($field_storage_yml)->save();
}
// Field instance.
$field_yml = Yaml::parse(file_get_contents("$path/config/optional/field.field.node.webform.field_os2forms_wff_area.yml"));
if (!FieldConfig::loadByName('node', 'webform', 'field_os2forms_wff_area')) {
FieldConfig::create($field_yml)->save();
}
// Add field field.field.node.webform.field_os2forms_wff_application.
// Field storage.
$field_storage_yml = Yaml::parse(file_get_contents("$path/config/optional/field.storage.node.field_os2forms_wff_application.yml"));
if (!FieldStorageConfig::loadByName('node', 'field_os2forms_wff_application')) {
FieldStorageConfig::create($field_storage_yml)->save();
}
// Field instance.
$field_yml = Yaml::parse(file_get_contents("$path/config/optional/field.field.node.webform.field_os2forms_wff_application.yml"));
if (!FieldConfig::loadByName('node', 'webform', 'field_os2forms_wff_application')) {
FieldConfig::create($field_yml)->save();
}
// Update form display.
os2forms_read_in_new_config('core.entity_form_display.node.webform.default');
// Apply URL generation.
os2forms_read_in_new_config('pathauto.pattern.os2forms_wf_webforms');
}
/**
* Implements hook_update_N().
*
* Uninstalling webform_embed module.
*/
function os2forms_update_8905() {
\Drupal::service('module_installer')->uninstall(['webform_embed']);
}
/**
* Creates a list of predefined terms for Application vocabulary.
*/
function _os2form_install_init_application_terms() {
$term_names = ['Intern', 'Ekstern', 'Test/Udvikling', 'Parkeret', 'Ingen'];
foreach ($term_names as $name) {
Term::create([
'vid' => 'os2forms_tax_application',
'name' => $name,
])->save();
}
}
/**
* Creates a list of predefined terms for Ara vocabulary.
*/
function _os2form_install_init_area_terms() {
$term_names = [
'Borgerservice',
'Kommunikation',
'Digitalisering',
'Teknik og Miljø',
'Børn og Familie',
'Social',
'Sundhed',
'Beskæftigelse',
'Kultur',
'IT',
'Byplan',
'Dagtilbud',
'Skole',
'Økonomi',
'Andet',
];
foreach ($term_names as $name) {
Term::create([
'vid' => 'os2forms_tax_area',
'name' => $name,
])->save();
}
}