Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By AndyLicht on
Hi Forum,
i need some help with my two custom entities.
My first entity has the field title and is called openlayers_source, my second entity is called openlayers_layer and has one field as a reference to the first field. I can add content to both, but if i fill the reference field add any time i get
"There are no entities matching"
Maybe some of you can find my mistake, the code shows the field implementation of the reference field:
$fields['layer_source_ref'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Source of the layer'))
->setDescription(t('Reference to the source of the layer'))
->setSetting('target_type','entity')
->setSettings('handler','default')
->setSettings('handler_settings',['target_bundles' =>['openlayers_source' => 'openlayers_source']])
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'string',
'weight' => -6,
))
->setDisplayOptions('form', array(
'type' => 'entity_reference_autocomplete',
'settings' => array(
'match_operator' => 'CONTAINS',
'size' => 60,
'placeholder' => 'Name of the source'
),
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
Thanks for helping me!
Comments
Solution
I have to define a label in the entity definition
FIRST:
CORRECT: