Views EntityReference filter: Add functionality to switch from select to autocomplete widget when a max number of options reached

Created on 18 October 2024, about 1 month ago

Problem/Motivation

An old patch associated with issue ✨ Continuation Add Views EntityReference filter to be available for all entity reference fields Needs work included the functionality to switch from a select widget to an autocomplete widget for an Views EntityReference filter when the number of select list options hit a predefined value. This functionality was removed in part 1 of this issue πŸ“Œ Add Views EntityReference filter to be available for all entity reference fields Closed: duplicate in an attempt to simplify the patch and improve its chances of getting committed. Current functionality of this filter in 11.x limits the select widget to 100 options and there is no way to change this limit. Also the type of widget is fixed, there is no automatic switching to an autocomplete widget when that limit is exceeded.

We found the original patch functionality very useful on a site where different groups with their own content use the same view. Some groups only have a few referenced nodes, so a select widget is more user-friendly, and other groups have hundreds of references node so an autocomplete widget is preferred.

Now that ✨ Continuation Add Views EntityReference filter to be available for all entity reference fields Needs work is in 11.x (YAY!), I am hoping this functionality can be re-added in this issue.

Steps to reproduce

  1. Set up an exposed EntityReference filter on a View as per the instructions in ✨ Continuation Add Views EntityReference filter to be available for all entity reference fields Needs work
  2. In the extra settings form in the Views Admin UI, note that only a select or autocomplete widget can be selected. Choose select.
  3. Create more than 100 referenced nodes (Devel module & drush will help here)
  4. Visit the view page and note that the filter is a select widget and only 100 options are listed.

Proposed resolution

  • Add a list_max Views EntityReference filter exposed form configuration option.
  • This configuration option is only visible when the select widget is selected.
  • If list_max is set to 0 (meaning unlimited), the filter will will always be a select widget.
  • If list_max is set to a number greater than 0, when the number of options hits or exceeds this limit, the widget will automatically switch from a select widget to an autocomplete widget.

Remaining tasks

  1. Create MR containing new config, \Drupal\views\Plugin\views\filter\EntityReference changes and new tests.
  2. Review and feedback from the community.

User interface changes

  • Addition of a "Maximum entities in select list" (list_max) field to the Views EntityReference filter extra settings form in the Views admin UI.
  • Views EntityReference filter exposed form will automatically switch from a select widget to an autocomplete widget, if the select widget is chosen and the number of options equals or exceeds the list_max value.

Introduced terminology

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component

views.module

Created by

πŸ‡¨πŸ‡¦Canada tame4tex

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