BEF Collapsible Filter Not Automatically Opening For First Option

Created on 30 January 2025, 23 days ago

Problem/Motivation

The facets exposed filter should be expanded if you have any elements selected while using your search filter with BEF and having the option "Make filter options collapsible". However, the first element does not trigger this and the filter will always be collapsed. This is because BEF checks for a default value and if none is found, it sets it to be the first element in the options array.

Steps to reproduce

  1. Setup search API server and index
  2. Add a field to your search index for Content Type
  3. Create a search view using the Facets Exposed Filters with the Content Type field created before
    1. Ensure AJAX is turned off
    2. Change your Exposed form style to Better Exposed Filters
    3. Change the Exposed Filter "CONTENT_TYPE" to be "Checkboxes/Radio Buttons".
    4. Under the Advanced Filter Option for the Exposed Filter, select "Make filter options collapsible"
    5. Save your view
  4. Create a couple of content types and nodes for each of them
  5. Ensure all nodes have been indexed
  6. Go to your search view and make as search
  7. Select the first element in your exposed form for content types

Proposed resolution

It's actually a quite simple solution. The FacetsFilter.php file needs to return a empty array as the #default_value when building the exposed element.

Additionally, this fixes a warning from BEF of undefined array key "#default_value".
Warning: Undefined array key "#default_value" in Drupal\better_exposed_filters\Plugin\BetterExposedFiltersWidgetBase->addElementToGroup() (line 155 of /var/www/html/web/modules/contrib/better_exposed_filters/src/Plugin/BetterExposedFiltersWidgetBase.php)

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mitchel432

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

Comments & Activities

Production build 0.71.5 2024