function _yamlform_update_form_settings in YAML Form 8
Update form setting to reflect changes in the default settings.
This function can be used to apply new form settings to all existing forms.
See also
\Drupal\yamlform\Entity\YamlForm::setSettings
12 calls to _yamlform_update_form_settings()
- drush_yamlform_repair in drush/
yamlform.drush.inc - Implements drush_hook_COMMAND().
- yamlform_update_8038 in includes/
yamlform.update.inc - Issue #2783527: Order form settings when saved and apply defaults.
- yamlform_update_8039 in includes/
yamlform.update.inc - Issue #2783575: Add autofocus form setting.
- yamlform_update_8046 in includes/
yamlform.update.inc - Issue #2792681: Allow a YAML Form's source entity to be (optionally) populated using query string parameters.
- yamlform_update_8049 in includes/
yamlform.update.inc - Issue #2803139: Add details toggle support to form settings.
File
- ./
yamlform.install, line 145 - Install, update and uninstall functions for the YAML Form module.
Code
function _yamlform_update_form_settings() {
$default_properties = [
'langcode' => 'en',
'status' => TRUE,
'dependencies' => [],
'uid' => '',
'template' => FALSE,
'id' => '',
'title' => '',
'description' => '',
'elements' => '',
'css' => '',
'javascript' => '',
'settings' => [],
'access' => [],
'handlers' => [],
];
$default_settings = YamlForm::getDefaultSettings();
$config_factory = \Drupal::configFactory();
// Update 'yamlform.yamlform.*' configuration.
foreach ($config_factory
->listAll('yamlform.yamlform.') as $yamlform_config_name) {
$yamlform_config = $config_factory
->getEditable($yamlform_config_name);
// Get data.
$data = $yamlform_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;
// Always apply the default settings.
$settings = $default_settings;
// Now apply custom settings.
foreach ($data['settings'] as $name => $value) {
$settings[$name] = $value;
}
// Set settings.
$data['settings'] = $settings;
// Save data.
$yamlform_config
->setData($data)
->save();
}
}