I have several custom content entity types that have relationships to one another. The fields used are defined as base fields and I am using
$fields['FIELD_NAME'] = BaseFieldDefinition::create('entity_reference')
Views doesn't currently implement reverse relationships for base fields, it is a feature request https://www.drupal.org/node/2706431
So you need to define the relationship in your module with the
getViewsData() method of the
EntityViewData class https://api.drupal.org/api/drupal/core%21modules%21views%21src%21EntityViewsData.php/class/EntityViewsData/8.2.x or
Using the examples provided, I was able to define a reverse relationship for an entity_reference field with cardinality of 1 (where the field is created in the entity's base_table). But I can't figure out how to do it with a cardinality > 1 or unlimited (where the field is created in a separate table).
None of the examples on those pages above (or that I have been able to find with the google) defines a relationship between 2 entities that requires an intermediary table.
Views defines an
EntityReverse class https://api.drupal.org/api/drupal/core%21modules%21views%21src%21Plugin%21views%21relationship%21EntityReverse.php/8.2.x that I have looked at for ideas. It has a
$first_join and a
$second_join. I can confirm that if the field is added to the entity using the normal UI, then views provides both relationships: to the related entity and the reverse relationship from the related entity.
I am not sure at all how to translate the
EntityReverse class into a definition that views would expect
And How to do a Reverse Entity Reference? is not the answer.
Anyone know a solution? or a place to point me for more research?