Problem/Motivation
Whoops! This was a big oversight at #3347343: Add Views EntityReference filter to support better UX for exposed filters. Although we got it right at #2640994: Fix label token replacement for views entity reference arguments 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
- Install Drupal 10.4.5.
- Add some entity reference fields to a custom entity type.
- Create a view of those entities, and try to filter by the entity reference field.
- 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';