Incorporate Drupal core Views entity reference filter plugin

Created on 7 April 2022, over 2 years ago
Updated 30 October 2023, about 1 year ago

Problem/Motivation

In #3185188: Views exposed filters for Entity References β†’ we decided to adopt a patch to Drupal core to support autocomplete entity reference exposed filters in Views, from this core issue: πŸ“Œ Add Views EntityReference filter to be available for all entity reference fields Closed: duplicate

That core issue has been slowly but surely moving forward, and it sounds like they will be changing the solution slightly to avoid a BC break. See this comment (which also includes an example update hook: https://www.drupal.org/project/drupal/issues/2429699#comment-14472189 πŸ“Œ Add Views EntityReference filter to be available for all entity reference fields Closed: duplicate )

This means we will need to update our code to reflect the changes when it gets merged. Opening this issue as a place to track that for future reference. I will start it with a status of "Postponed" and we can make it "Active" when that core issue gets merged.

Proposed resolution

TBD

Remaining tasks

TBD

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ“Œ Task
Status

Postponed

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States m.stenta

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States m.stenta
  • πŸ‡ΊπŸ‡ΈUnited States m.stenta

    Update: Drupal core has merged an official fix for this in 11.x. We are using that now in farmOS, as of our upgrade to Drupal 10.3. See: Update Drupal core to 10.3 #872

    Relevant notes from the PR:

    Views Entity Reference filters patch

    Drupal core has merged Issue #3347343: Add Views EntityReference filter to support better UX for exposed filters into Drupal 11 upstream, and they are working on a backport to Drupal 10.4. The merged changes differ slightly from the earlier patch we were using, but the end result is the same. The core maintainers decided that it would be a breaking change if they took the approach from the patch(es) we were previously using. The existing (and still default) Views entity reference filter only works with entity IDs (not selects or autocompletes), and the previous patches replaced this with select/autocomplete. This means that any existing sites that depended on entity ID filtering would break. So, the core maintainers decided to add the select/autocomplete filter as an optional plugin, which will be selectable in the Views UI once some other core issues are merged (specifically #3458099: Views handler loading should respect configuration and #3438054: Configurable views filters to allow for different widgets). In the meantime, a contrib module has been published which provides the ability for site administrators to opt-in to using the new filter (Views Core Entity Reference). The alternative to using this module is to perform the same logic it does manually via hook_views_data_alter(). This is the approach that this PR takes via our existing hook_views_data_alter() implementation in the farm_ui_views module. Once the remaining two core issues are merged, we will be able to remove that and configure the filter directly in individual Views configuration YML.

    Notably, the patch we are applying for 10.3 is being included directly in the farmOS codebase (in a new patches directory), because there isn't one available in the issue itself, and I didn't want to add more noise to an already very long core issue. I produced the patch by saving the diff of the 3347343-10-3-x--comment-214-onwards--do-not-merge MR branch: https://git.drupalcode.org/project/drupal/-/merge_requests/9036.diff

    So the remaining task here is just to remove the remaining logic from farm_ui_views_views_data_alter() and configure it in our Views YML directly.

    Here is the code that will be removed: https://github.com/farmOS/farmOS/blob/a18dff81390b82b8665cb25a86267bc368...

    Leaving this as postponed, and linking to the relevant upstream issues we're waiting on. I also updated the issue description.

  • πŸ‡ΊπŸ‡ΈUnited States m.stenta
Production build 0.71.5 2024