The "Office Hours current open/closed status" views filter is not working properly

Created on 7 November 2024, 2 months ago

This issue is not happening if you're using the filter as a dropdown that allows multiple selection.

Problem

I added the "Office Hours current open/closed status" views filter and it is not filtering by open or closed. The View always brings all results.

The filter method of the OfficeHoursStatusFilter class is using the array_key_exists function to search for the status constant value in the $filterValue array keys .

$is_open = $items->isOpen();
if ($is_open && array_key_exists((int) static::OPEN, $filterValue)) {
  continue;
}
if ((!$is_open) && array_key_exists((int) static::CLOSED, $filterValue)) {
  continue;
}

The problem is: I'm using the "Better Exposed Filters" to display this field as checkboxes.
If the filter is configured to not allow multiples values, the $filterValue brings the filter value not as a key, but as a value.

e.g.: User selects "Open now" option:
$filterValue[0] = 1

e.g.: User selects "Temporarily closed" option:
$filterValue[0] = 0

If the filter is configured to allow multiples values, then $filterValue will have the following structure:
(e.g.: user selects "Open now" option)

$filterValue = [
  1 => "1",
  all => 0,
  0 => 0,
  2 => 0,
];

In this scenario, the array key will always exists.

Proposed resolution

Replacing array_key_exists for in_array and filtering the $filterValue array to remove the "0 integer" values seems to fix the issue.

🐛 Bug report
Status

Needs work

Version

1.19

Component

Integrating Views

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