0

I have created a custom Entity using drupal generate:entity:content. This works great overal: I can use it in my code like I want.

One of the table columns of the entity is a node-reference. This works as well. However I have created an (admin) view in which I list the entities and want to create an exposed filter to filter by the titles (in a selectbox) of the referenced nodes. I can't find out how to do that.

When I create a view of nodes in which I reference to other nodes I can easily create such an exposed filter by choosing "Referenced .. something". With my custom entity I don't get such a choice. I think I must do something in my EntityListBuilder or my Entity class itself.

Currently the only reference in code to the NodeReference is the field definition in my Entity which looks like this:

$fields['competitor'] = BaseFieldDefinition::create('entity_reference')
  ->setLabel(t('Competitor'))
  ->setDescription(t('Competitor'))
  ->setSetting('target_type', 'node')
  ->setReadOnly(TRUE);

I mentioned nothing else about this field in either my entity-class, nor in my EntityListBuilder class. So anything missing there?

Can someone help me out?

2
  • I noticed the field is read-only. Wouldn't that prevent you from being able to assign values?
    – Beau
    Commented Mar 18, 2020 at 0:33
  • Nope, it only (probably) prevents from editing it (which is what I want). Saving values works like a charm.
    – vrijdenker
    Commented Mar 19, 2020 at 15:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.