Problem/Motivation

Base fields of type primary_entity_reference are missing views support for views relationships and boolean handlers.

This is the underlying cause of CRM's issue #3566240: Views relationship plugin to relate a Contact to its Relationships.

Steps to reproduce

  1. Add a base field definition for a Primary Entity Reference field for an entity type
  2. Create a view of entities of that type
  3. Attempt to add a views relationship to the view for the field added earlier
  4. Observe that no relevant relationships are offered as options

Proposed resolution

Add views relationships and boolean handlers for base fields of type primary_entity_reference.

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jdleonard created an issue. See original summary.

jdleonard’s picture

Assigned: jdleonard » Unassigned
Status: Active » Needs review

Added the needed Views support and performed basic manual testing via Views UI.

jdleonard’s picture

Status: Needs review » Needs work

Needs a few phpDoc comments and to investigate one test failure for phpunit (next minor):

Drupal\Tests\primary_entity_reference\Unit\Plugin\Field\FieldType\PrimaryEntityReferenceItemTest::testSchema
Expectation failed for method name is "getBaseFieldDefinitions" when invoked 1 time.
Method was expected to be called 1 time, actually called 0 times.

I won't have time to look into this further for a while.

jdleonard’s picture

Assigned: Unassigned » jdleonard
jdleonard’s picture

Assigned: jdleonard » Unassigned
Status: Needs work » Needs review
Related issues: +#3585085: Drupal 12 support

Tests are now passing.

Note: had to remove "next major" from CI and opened #3585085: Drupal 12 support

I intend to review this further, but in the meantime it could do with some additional review.

sikofitt’s picture

@jdleonard Just ran through the steps and if I am understanding correctly the views integration is working for me. I am able to add relationships and filter by them.

jdleonard’s picture

@sikofitt Did you definitely add a base field definition (as opposed to a configurable field definition)? E.g. using baseFieldDefinitions()?

You might also double check #3566240: Views relationship plugin to relate a Contact to its Relationships.

sikofitt’s picture

@jdleonard, I didn't do anything programmatically. I just added a plain text field and then created the view. Does this need to be tested by creating a test baseFieldDefinitions() in code?

jdleonard’s picture

@sikofitt exactly!

jdleonard’s picture

You could also test by creating a view of CRM contacts and attempting to add a views relationship to contacts' contact methods (emails, telephones, addresses) as those fields are defined in Contact::baseFieldDefinitions().