function _webform_update_options_settings in Webform 6.x
Same name and namespace in other branches
- 8.5 includes/webform.install.inc \_webform_update_options_settings()
Update webform options setting to reflect changes in the default settings.
This function can be used to apply new webform options configuration to all existing webforms options.
See also
\Drupal\webform\Entity\WebformOptions
1 call to _webform_update_options_settings()
- webform_update_8021 in includes/
webform.install.update.inc - Issue #2858139: Add OptGroup support to WebformOption entity.
File
- includes/
webform.install.inc, line 259 - Webform install helper functions.
Code
function _webform_update_options_settings() {
$default_properties = [
'langcode' => 'en',
'status' => TRUE,
'dependencies' => [],
'id' => '',
'label' => '',
'category' => '',
'options' => '',
];
// Update 'webform.webform_options.*' configuration.
$config_factory = \Drupal::configFactory();
foreach ($config_factory
->listAll('webform.webform_options.') as $webform_config_name) {
$webform_options_config = $config_factory
->getEditable($webform_config_name);
// Get data.
$data = $webform_options_config
->getRawData();
// Always apply the default properties.
$properties = $default_properties;
// Now apply defined properties.
foreach ($data as $name => $value) {
$properties[$name] = $value;
}
// Set properties.
$data = $properties;
// Save data.
$webform_options_config
->setData($data)
->save();
}
}