- Issue created by @acbramley
- 🇦🇺Australia acbramley
Currently it's possible to achieve this with some somewhat hacky alter code
function my_module_field_widget_single_element_dynamic_entity_reference_default_form_alter(array &$element, FormStateInterface $formState, array $context): void { $items = $context['items'] ?? NULL; if (!$items instanceof DynamicEntityReferenceFieldItemList) { return; } // If the element already has an entity, bail. if (!empty($element['target_id']['#default_value'])) { return; } // Default to node. $targetType = 'node'; $fieldSettings = $items->getFieldDefinition()->getSettings(); $element['target_type']['#default_value'] = $targetType; $element['target_id']['#target_type'] = $targetType; $element['target_id']['#selection_handler'] = $fieldSettings[$targetType]['handler']; }