White-Screen of Death when facet has no items

Created on 17 September 2024, 2 months ago
Updated 20 September 2024, 2 months ago

Problem/Motivation

When making a search where the number of facet results has a count less the the minimum it crashes with the watchdog error message: TypeError: array_merge(): Argument #1 must be of type array, null given in array_merge() (line 43 of /var/www/html/drupal/web/modules/contrib/facets_range_nouislider/src/Plugin/facets/widget/NoUiSliderWidget.php).

For example, I have a nouislider facet configured for year an item is created that has a count minimum of 2. If I provide a search with only a single result then this error is thrown. If I change the count minimum to 1 then the error disappears (but then the range slider is pointless, because there is only one possible value).

This is because the slider configuration has a null value due to the parent class returning an empty build when no results are available.

Proposed resolution

The following patch resolves the issue in my case (see also attached patch):

diff --git a/src/Plugin/facets/widget/NoUiSliderWidget.php b/src/Plugin/facets/widget/NoUiSliderWidget.php
index d237ddb..4691cb7 100644
--- a/src/Plugin/facets/widget/NoUiSliderWidget.php
+++ b/src/Plugin/facets/widget/NoUiSliderWidget.php
@@ -39,6 +39,9 @@ class NoUiSliderWidget extends SliderWidget {
     $build = parent::build($facet);
 
     $facet_settings = &$build['#attached']['drupalSettings']['facets']['sliders'][$facet->id()];
+    if (is_null($facet_settings)) {
+      return $build;
+    }
 
     $facet_settings = array_merge($facet_settings, $this->getConfiguration());
 
πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States seth.e.shaw

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

Comments & Activities

Production build 0.71.5 2024