function name_post_update_field_settings_merge in Name Field 8
Merges the custom field and storage settings together.
File
- ./
name.post_update.php, line 146 - Post update functions for Name.
Code
function name_post_update_field_settings_merge() {
$merged_fields = [
'components',
'minimum_components',
'max_length',
'labels',
'allow_family_or_given',
'autocomplete_source',
'autocomplete_separator',
'title_options',
'generational_options',
'sort_options',
];
$merged_fields = array_combine($merged_fields, $merged_fields);
$field_storage_configs = \Drupal::entityTypeManager()
->getStorage('field_storage_config')
->loadByProperties([
'type' => 'name',
]);
foreach ($field_storage_configs as $field_storage) {
/* @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
$storage_settings = $field_storage
->getSettings();
$merged_settings = array_intersect_key($storage_settings, $merged_fields);
$field_name = $field_storage
->getName();
$fields = \Drupal::entityTypeManager()
->getStorage('field_config')
->loadByProperties([
'field_name' => $field_name,
]);
foreach ($fields as $field) {
/* @var \Drupal\field\Entity\FieldConfig $field */
$field_settings = $field
->getSettings();
$field_settings += $merged_settings;
$field
->setSettings($field_settings)
->save();
}
$storage_settings = array_diff_key($storage_settings, $merged_fields);
$field_storage
->setSettings($storage_settings)
->save();
}
}