Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294303

Continuation Add Views EntityReference filter to be available for all entity reference fields

$
0
0

Continuation of #2429699: Add Views EntityReference filter to be available for all entity reference fields since there were so many comments the page was struggling to load.

Slack thread

https://drupal.slack.com/archives/C6SQM2J94/p1706633005193429

Problem/Motivation

One major piece of functionality from the D7 Entity Reference module was left out entirely in #1801304: Add Entity reference field: the ability to render exposed views filters as a select list or autocomplete of available entities.

Proposed resolution

Create a new Views Entity Reference filter plugin to be available for all entity reference fields but do not activate it at this stage. Make it available as an opt-in via views data alter.

How to use

  1. Add on an entity type / bundle an entity reference field, ex field_test_reference.
  2. Use views data alter to allow your field to make use of the reference (see code snippet below)
  3. Create a view displaying this entity type.
  4. Add a filter on the view for field_test_reference.
  5. Configure the entity selection mode and the widget display mode.
  6. Configure the filter behavior (ex: required, multiple, etc.)
  7. Finally use the filter field for filtering the results based on the selected entity from the autocomplete or select list.

Code snippet to use this filter:

/**
 * Implements hook_views_data_alter().
 */
function MODULE_NAME_views_data_alter(&$data) {
  // Use entity reference for the field 'field_test_target'.
  $field_name = 'field_test_field';
  $data['node__' . $field_name][$field_name . '_target_id]['filter']['id'] = 'entity_reference';
}

Remaining tasks

  • ☑ support for content entity reference
  • ☑ support for configuration entity reference
  • ☑ support for content with and without bundles
  • ☑ taxonomy filter rebased on generic entity reference
  • ☑ settings forms to configure the filter
  • ☑ display widget in select or autocomplete
  • ☑ filter values based on reference view
  • ☑ filter values based on bundles
  • ☑ maximum filter values in select list for performance concerns
  • ☑ sort for filter values when in bundle selection handler mode
  • ☑ argument support for when view selection handler is used
  • ☑ views configuration schema update
  • ☐ existing configuration migration (no longer needed if we create a new filter only)
  • ☐ fix select option (#208, #215)
  • ☑ tests for general functionality
  • ☐ Address points in comment #49 (comment 534 from original ticket)
    • ☑ add test coverage for calculate dependencies
    • ☐ sort by empty on initial load (needs more info), see comment #49
    • ☐ prevent circular reference: validate no selection of an entity reference that uses itself as the filter, see comment #49
    • ☐ node titles in the select options when configuring the filter are double escaped (e.g. " shows as "), see comment #49
    • ☐ exposed filters on the chosen entity reference view are also shown on the view, see comment #49
  • ☑ write change record
  • ☐ get framework manager approval
  • ☐ update change record screenshots once green light has been given for this updated direction and considered ready to merge

Post tasks

User interface

UI
UI

UIUI

Known issues

  • CANNOT REPRODUCE ATM sometimes when switching between widget it gets stuck on the previous selected one
  • FIXED when switching between the widget types the previous value is left in the exposed form and it's incompatible with the other widget type
  • FIXED triggering ajax requests on the extra options form right after adding the filter brings you back to the add handler form fixed

API changes

None.

For 10.2

See hidden branches and comment #143


Viewing all articles
Browse latest Browse all 294303

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>