function _webform_update_admin_settings in Webform 6.x
Same name and namespace in other branches
- 8.5 includes/webform.install.inc \_webform_update_admin_settings()
Update admin settings to reflect changes in the default settings.
If you are moving or updating any admin settings this must be explicitly done via an update hook.
Parameters
bool $reset: If set TRUE old admin settings will be completely deleted.
See also
78 calls to _webform_update_admin_settings()
- WebformAdminConfigAdvancedForm::submitForm in src/
Form/ AdminConfig/ WebformAdminConfigAdvancedForm.php - Form submission handler.
- WebformCliService::drush_webform_repair in src/
Commands/ WebformCliService.php - webform_update_8007 in includes/
webform.install.update.inc - Issue #2840521: Add support for global CSS and JS.
- webform_update_8009 in includes/
webform.install.update.inc - Issue #2844020: Add admin and form specific setting to allow submit button to be clicked only once.
- webform_update_8010 in includes/
webform.install.update.inc - Issue #2843400: Automated purging of submissions.
File
- includes/
webform.install.inc, line 25 - Webform install helper functions.
Code
function _webform_update_admin_settings($reset = FALSE) {
// Make sure to purge the config cache before updating any config.
// This ensure that any config schema changes are loaded.
\Drupal::service('cache.config')
->deleteAll();
$admin_config = \Drupal::configFactory()
->getEditable('webform.settings');
$current_settings = $admin_config
->getRawData();
$admin_settings = Yaml::decode(file_get_contents(drupal_get_path('module', 'webform') . '/config/install/webform.settings.yml'));
// Note, admin settings are always grouped into associative array,
// except for the langcode.
foreach ($admin_settings as $group => $settings) {
// Handle the rare case the we are adding a new group the admin settings.
if (!isset($current_settings[$group])) {
continue;
}
// Completely copy the format, langcode, and third_party_settings.
if (in_array($group, [
'format',
'langcode',
'third_party_settings',
])) {
if (isset($current_settings[$group])) {
$admin_settings[$group] = $current_settings[$group];
}
}
elseif ($reset) {
// Copy only group's settings that are defined in admin settings.
// This will cause old settings to be completely deleted.
foreach ($settings as $name => $value) {
if (isset($current_settings[$group][$name])) {
$admin_settings[$group][$name] = $current_settings[$group][$name];
}
}
}
else {
// Loop through the group's settings and apply all existing settings to
// the default admin settings.
foreach ($current_settings[$group] as $name => $value) {
$admin_settings[$group][$name] = $value;
}
}
}
// If not reset, make sure all the current settings are preserved.
if (!$reset) {
$admin_settings += $current_settings;
}
$admin_config
->setData($admin_settings)
->save();
}