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

AndyLicht’s picture

I have to define a label in the entity definition
FIRST:

*   entity_keys = {
 *     "id" = "id",
 *     "uuid" = "uuid",
 *     "user_id" = "user_id",
 *     "source_name" = "source_name",
 *     "source_type" = "source_type",
 *     "source_url" = "source_url"
 *   },

CORRECT:

*   entity_keys = {
 *     "id" = "id",
 *     "uuid" = "uuid",
 *     "user_id" = "user_id",
 *     "label" = "source_name",   /*IMPORTANT*/
 *     "source_type" = "source_type",
 *     "source_url" = "source_url"
 *   },