-
Notifications
You must be signed in to change notification settings - Fork 6
/
webform_strawberryfield.install
57 lines (54 loc) · 1.88 KB
/
webform_strawberryfield.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
<?php
/**
* Implements hook_uninstall().
*/
function webform_strawberryfield_uninstall() {
//@TODO do we need to remove our settings?
}
/**
* Change Handler with space to new one
*/
function webform_strawberryfield_update_8001() {
// Change Handler ID
$config_factory = \Drupal::configFactory();
foreach ($config_factory->listAll('webform.webform.') as $webform_config_name) {
$webform_config = $config_factory->getEditable($webform_config_name);
$data = $webform_config->getRawData();
$has_sbf_oldhandler = FALSE;
$has_sbf_newhandler = FALSE;
$handlers_to_remove = [];
$update_webforms = [];
foreach ($data['handlers'] as $key => &$handler) {
// Notice the space before strawberry...
// We can only have the handler once.
// So we need to also check for in case
if ($handler['id'] === 'strawberryField_webform_handler') {
$has_sbf_newhandler = TRUE;
// Mark the fact we already have one so we can remove the old ones
}
if ($handler['id'] === ' strawberryField_webform_handler') {
$update_webforms[] = $webform_config_name;
$has_sbf_oldhandler = TRUE;
if (!$has_sbf_newhandler) {
// Only rename if this was not corrected manually
$handler['id'] = 'strawberryField_webform_handler';
} else {
// mark this or any other (we can have only one)
// For removal.
$handlers_to_remove[] = $key;
}
}
}
if ($has_sbf_oldhandler) {
foreach($handlers_to_remove as $keys) {
unset($data['handlers'][$keys]);
}
$webform_config->setData($data);
$webform_config->save();
}
}
if ($has_sbf_oldhandler) {
$message = \Drupal::translation()->translate('Updated Webform Strawberryfield handlers in webform configs: @ids', ['@ids' => implode(', ', array_unique($update_webforms))]);
return $message;
}
}