function webform_update_8159 in Webform 6.x
Same name and namespace in other branches
- 8.5 includes/webform.install.update.inc \webform_update_8159()
Issue #3023223: Remove unused fields settings.
File
- includes/
webform.install.update.inc, line 3017 - Archived Webform update hooks.
Code
function webform_update_8159() {
/** @var \Drupal\field\FieldStorageConfigInterface[] $field_storage_configs */
$field_storage_configs = FieldStorageConfig::loadMultiple();
foreach ($field_storage_configs as $field_storage_config) {
if ($field_storage_config
->getType() !== 'webform') {
continue;
}
list($entity_type, $field_name) = explode('.', $field_storage_config
->getConfigTarget());
$bundles = $field_storage_config
->getBundles();
foreach ($bundles as $bundle) {
$config = \Drupal::configFactory()
->getEditable("field.field.{$entity_type}.{$bundle}.{$field_name}");
$data = $config
->getRawData();
if (isset($data['settings']['default_data'])) {
unset($data['settings']['default_data'], $data['settings']['status'], $data['settings']['open'], $data['settings']['close']);
$config
->setData($data)
->save();
}
}
}
}