function name_post_update_formatter_settings in Name Field 8
Corrects the field formatter settings for new name list type settings.
File
- ./
name.post_update.php, line 48 - Post update functions for Name.
Code
function name_post_update_formatter_settings() {
$field_storage_configs = \Drupal::entityTypeManager()
->getStorage('field_storage_config')
->loadByProperties([
'type' => 'name',
]);
$default_settings = [
"format" => "default",
"markup" => FALSE,
"output" => "default",
"list_format" => "default",
];
foreach ($field_storage_configs as $field_storage) {
$field_name = $field_storage
->getName();
$fields = \Drupal::entityTypeManager()
->getStorage('field_config')
->loadByProperties([
'field_name' => $field_name,
]);
foreach ($fields as $field) {
$properties = [
'targetEntityType' => $field
->getTargetEntityTypeId(),
'bundle' => $field
->getTargetBundle(),
];
$view_displays = \Drupal::entityTypeManager()
->getStorage('entity_view_display')
->loadByProperties($properties);
foreach ($view_displays as $view_display) {
if ($component = $view_display
->getComponent($field_name)) {
$settings = (array) $component->settings;
$settings['list_format'] = isset($settings['multiple']) && $settings['multiple'] == 'default' ? '' : 'default';
$settings = array_intersect_key($settings, $default_settings);
$settings += $default_settings;
$view_display
->setComponent($field_name, [
'type' => 'name_default',
'settings' => $settings,
] + $component)
->save();
}
}
}
}
return t('New name list formatter settings are implemented. Please review any name display settings that used inline lists.');
}