Multi-selected grouped view filters use AND instead of OR.

Created on 3 April 2025, 4 days ago

Problem/Motivation

Grouped filters are not behaving correctly when multiple groups are selected in an exposed filter. The expectation for multiselect view filters, is that they combine selections using OR, not AND.

Steps to reproduce

My view was very complex and depended on multiple modules. But I followed these steps with a blank view and the problem still occurred.

  1. Create a view (based on any fieldable entity)
  2. Add an exposed dropdown filter (I recommend a List (text) field)
  3. Select Grouped filters and create some groupings
  4. Allow multiple selections
  5. Add a view page for easy testing and save your view
  6. Visit your view and select multiple groups on your exposed filter

Example: Selecting Group 1 and Group 2

Selecting multiple groups should show all the items that match any of the group values (Group 1 OR Group 2)

Selecting multiple groups shows all the items that match both of the group values (Group 1 AND Group 2)

Proposed resolution

The issue is linked to ViewExecutable::_build() and FilterPluginBase::convertExposedInput().
_build() loops through the different selected groups and gets the group values and saves them in the exposed_data property. It then adds them to the query within the loop, creating a different WHERE condition for each selected group, which is why it follows AND instead of OR.

I have created a patch that only adds the query once it has looped through each selected group. However, each loop overrides the previously set values, so only the final group would be added to the query. In my patch, after the first loop, the code starts combining the values of each group. This way it creates only 1 WHERE condition with all the values for that filter to apply.

πŸ› Bug report
Status

Active

Version

10.4 ✨

Component

views.module

Created by

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