Use the new 'entity_reference' Views filter in EntityViewsData::processViewsDataForEntityReference()

Created on 4 April 2025, 25 days ago

Problem/Motivation

Whoops! This was a big oversight at ✨ Continuation Add Views EntityReference filter to be available for all entity reference fields Active . Although we got it right at πŸ› Label token replacement for views entity reference arguments not working Needs work when we added the new argument handler for entity_reference fields, and updated EntityViewsData::processViewsDataForEntityReference() to provide that automatically, we forgot this important step in #3347343.

So, even if you're on a modern version of Drupal that supports the better filter for entity reference fields, you have to do wonky crap like hook_views_data_alter() to turn it on for every single field where you need it.

Steps to reproduce

  1. Install Drupal 10.4.5.
  2. Add some entity reference fields to a custom entity type.
  3. Create a view of those entities, and try to filter by the entity reference field.
  4. You get a sad, numeric-only filter, not the happy new thing with autocomplete vs. select.

Proposed resolution

1 line change to EntityViewsData::processViewsDataForEntityReference():

        $views_field['filter']['id'] = 'entity_reference';

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component

views.module

Created by

πŸ‡ΊπŸ‡ΈUnited States dww

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024