Skip to content
Snippets Groups Projects

Issue #2327883: Field [storage] config have incomplete settings until they are saved

1 file
+ 32
3
Compare changes
  • Side-by-side
  • Inline
@@ -386,6 +386,34 @@ function field_field_storage_config_update(FieldStorageConfigInterface $field_st
}
}
/**
* Implements hook_ENTITY_TYPE_create() for 'field_config'.
*
* Determine the selection handler plugin ID for an entity reference field.
*/
function field_field_config_create(FieldConfigInterface $field) {
// Act on all sub-types of the entity_reference field type.
/** @var \Drupal\Core\Field\FieldTypePluginManager $field_type_manager */
$field_type_manager = \Drupal::service('plugin.manager.field.field_type');
$item_class = 'Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem';
$class = $field_type_manager->getPluginClass($field->getType());
if ($class !== $item_class && !is_subclass_of($class, $item_class)) {
return;
}
// If we don't know the target type yet, there's nothing else we can do.
$target_type = $field->getFieldStorageDefinition()->getSetting('target_type');
if (empty($target_type)) {
return;
}
// Make sure the selection handler plugin is the correct derivative for the
// target entity type.
$selection_manager = \Drupal::service('plugin.manager.entity_reference_selection');
[$current_handler] = explode(':', $field->getSetting('handler'), 2);
$field->setSetting('handler', $selection_manager->getPluginId($target_type, $current_handler));
}
/**
* Implements hook_ENTITY_TYPE_presave() for 'field_config'.
*
@@ -406,13 +434,14 @@ function field_field_config_presave(FieldConfigInterface $field) {
return;
}
// Make sure the selection handler plugin is the correct derivative for the
// target entity type.
$target_type = $field->getFieldStorageDefinition()->getSetting('target_type');
// If we don't know the target type yet, there's nothing else we can do.
$target_type = $field->getFieldStorageDefinition()->getSetting('target_type');
if (empty($target_type)) {
return;
}
// Make sure the selection handler plugin is the correct derivative for the
// target entity type.
$selection_manager = \Drupal::service('plugin.manager.entity_reference_selection');
[$current_handler] = explode(':', $field->getSetting('handler'), 2);
$field->setSetting('handler', $selection_manager->getPluginId($target_type, $current_handler));
Loading