function webform_update_8198 in Webform 6.x
Same name and namespace in other branches
- 8.5 includes/webform.install.update.inc \webform_update_8198()
Issue #3156982: Fix empty '#option_all_value' and '#option_all_text'.
1 call to webform_update_8198()
- webform_update_8607 in includes/
webform.install.update.inc - Issue #3156982: Fix empty '#option_all_value' and '#option_all_text'.
File
- includes/
webform.install.update.inc, line 3769 - Archived Webform update hooks.
Code
function webform_update_8198() {
$options_properties = [
'#options_all_value',
'#options_all_text',
'#options_none_value',
'#options_none_text',
];
$config_factory = \Drupal::configFactory();
foreach ($config_factory
->listAll('webform.webform.') as $webform_config_name) {
$webform_config = $config_factory
->getEditable($webform_config_name);
$elements = $webform_config
->get('elements');
// Try to decode elements.
try {
$elements = WebformYaml::decode($elements);
} catch (\Exception $exception) {
continue;
}
// Make sure elements is an array.
if (!is_array($elements)) {
continue;
}
$has_options_property = FALSE;
$flattened_elements =& WebformFormHelper::flattenElements($elements);
foreach ($flattened_elements as &$element) {
foreach ($options_properties as $options_property) {
if (isset($element[$options_property]) && $element[$options_property] === '') {
unset($element[$options_property]);
$has_options_property = TRUE;
}
}
}
if ($has_options_property) {
$webform_config
->set('elements', WebformYaml::encode($elements));
$webform_config
->save(TRUE);
}
}
}