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')
  ->setSetting('target_type', 'node')

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?

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.