Warning about foreach in facets_exposed_filters_search_api_query_alter

Created on 13 May 2025, 1 day ago

Problem/Motivation

An object attribute $view->filter is used as the array in a foreach without checking if it is set. This resulted in the warning:

Warning: foreach() argument must be of type array|object, null given in facets_exposed_filters_search_api_query_alter() (line 49 of modules/contrib/facets/modules/facets_exposed_filters/facets_exposed_filters.module).

On line 49 you find

foreach ($view->filter as $filter) {

Steps to reproduce

  1. Install facets and submodule facets_exposed_filters
  2. Install search api and index taxonomy reference fields
  3. Set facets as exposed filters on a view of display type block
  4. Configure the view block to use exposed filters
  5. Put an exposed filters block on a page

Proposed resolution

Add ?? operator to make sure the foreach has an array.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇧🇪Belgium stefdewa

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