Alphabetical sorting preserves first item incorrectly when no "- Any -" option exists (i.e., Allow multiple selections selected)

Created on 23 April 2025, 3 days ago

Problem/Motivation

When using alphabetical sorting for exposed filters with Better Exposed Filters, the first item in the options list is preserved and not sorted alphabetically, even when no "- Any -" option exists. This occurs particularly when "Allow multiple selections" is selected for the exposed filter and "- Any -" option is automatically removed.

Steps to reproduce

  1. Create a view with an exposed filter (e.g., taxonomy term reference):
  2. - Use "Select list" as the Selection type
    - "Is one of" as the operator
    - Don't select any items to show all items as exposed filter options
    - Select "Allow multiple selections"

  3. Configure Better Exposed Filters to:
  4. - Use "Checkboxes/Radio Buttons with Active Filters" widget
    - Enable "Sort filter options alphabetically"

  5. Observe that the first option is not sorted alphabetically (probably shows most recent content first)

Proposed resolution

Modify the processSortedOptions() method to only preserve the first option if it is actually "- Any -" (either untranslated or translated). The updated code should:

- Check if the first option is literally "- Any -" before preserving it

- Only remove and re-insert the option if it matches this specific value

- Allow all other options to be sorted normally

Remaining tasks

- Review and test the proposed code change

- Ensure backward compatibility with existing implementations

πŸ› Bug report
Status

Active

Version

6.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom andreastkdf

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

Comments & Activities

Production build 0.71.5 2024