I'm on Drupal 8 and I created a custom entity custom_entity_one
following the Drupal 8 examples, the content_entity_example
module.
Now, in another custom entity, custom_entity_two
I'm trying to create a BaseFieldDefinition
like so:
$fields['cid'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('custom_entity_one ID'))
->setSettings(array(
'target_type' => 'custom_entity_one',
'multiple' => TRUE,
'handler' => 'default'
))
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'id',
'weight' => -1,
))
->setDisplayOptions('form', array(
'type' => 'entity_reference_autocomplete',
'settings' => array(
'match_operator' => 'CONTAINS',
'size' => 60,
'placeholder' => '',
),
'weight' => -1,
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
In the add form of the custom_entity_two
, the reference field appears, however, it doesn't find any value, even though I have multiple entities of type custom_entity_one
.
I thought that it will look for the label
propriety of the entity, but it doesn't seem so. What I am missing ? Should I create a custom handler ? I'm not very sure how.