I have a field definition set up like below. I want Drupal to do all the heavy lifting for me, so my definitions are minimal and rely on Drupal defaults:
$fields[$field] = BaseFieldDefinition::create('entity_reference')
->setSettings([
'target_type' => 'target_entity',
'handler' => 'default',
'handler_settings' => [
'auto_create' => true,
],
])
->setDisplayOptions('form', array(
'weight' => $weight,
));
;
target_entity
is just a simple bundleless entity.
This creates an entity reference auto-complete field in forms, but if I type something that doesn't match any existing entities, Drupal will say that no matching entities found and will refuse to create a new one.
How do I make the auto_create
setting work?