function webform_update_8046 in Webform 8.5
Same name and namespace in other branches
- 6.x includes/webform.install.update.inc \webform_update_8046()
Issue #2878193: Allow actions (aka submit buttons) to be placed anywhere on a webform.
File
- includes/
webform.install.update.inc, line 972 - Archived Webform update hooks.
Code
function webform_update_8046() {
// Change 'default_submit_button_label' to 'default_form_submit_label'.
$config = \Drupal::configFactory()
->getEditable('webform.settings');
$data = $config
->getRawData();
if (!isset($data['settings']['default_submit_button_label']) && isset($data['settings']['default_form_submit_label'])) {
$data['settings']['default_submit_button_label'] = $data['settings']['default_form_submit_label'];
unset($data['settings']['default_submit_button_label']);
}
$config
->setData($data);
$config
->save();
_webform_update_admin_settings();
// Update default (source) webform configuration.
$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();
$data = _webform_update_8046_convert_data($data);
$webform_config
->setData($data)
->save();
}
// Update translated webform configuration.
// ISSUE: Can't figure out the right way to update translated webform config.
// WORKAROUND: Directly update config data stored in the database.
$langcodes = array_keys(\Drupal::languageManager()
->getLanguages());
$collections = [];
foreach ($langcodes as $langcode) {
$collections[] = "language.{$langcode}";
}
foreach ([
'config',
'config_snapshot',
] as $table_name) {
if (!\Drupal::database()
->schema()
->tableExists($table_name)) {
continue;
}
$query = \Drupal::database()
->select($table_name, 'c')
->fields('c', [
'name',
'collection',
'data',
])
->orderBy('name')
->orderBy('collection')
->condition('name', 'webform.webform.%', 'LIKE')
->condition('collection', $collections, 'IN');
$result = $query
->execute();
while ($record = $result
->fetchAssoc()) {
$data = unserialize($record['data']);
$data = _webform_update_8046_convert_data($data);
\Drupal::database()
->update($table_name)
->fields([
'data' => serialize($data),
])
->condition('collection', $record['collection'])
->condition('name', $record['name'])
->execute();
}
}
}