From e265ad7290f85c7bec1e7578f1a37e6b53dba859 Mon Sep 17 00:00:00 2001 From: Rico van de Vin <rico@finlet.eu> Date: Mon, 6 Nov 2023 21:20:47 +0100 Subject: [PATCH] Issue #3268337 by nickvanboven, jonathan_hunt, ricovandevin: Dropdown Range value reset after one value selected --- .../facets/processor/RangeProcessor.php | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Plugin/facets/processor/RangeProcessor.php b/src/Plugin/facets/processor/RangeProcessor.php index f71834a..d6be462 100644 --- a/src/Plugin/facets/processor/RangeProcessor.php +++ b/src/Plugin/facets/processor/RangeProcessor.php @@ -101,7 +101,11 @@ class RangeProcessor extends ProcessorPluginBase implements PreQueryProcessorInt } // Determine min and max. - list($min, $max) = $this->getMinMax($facet, $this->getSortedResults($results)); + [$min, $max] = $this->getMinMax($facet, $this->getSortedResults($results)); + + // Active items set via preQuery(). + $activeMin = $facet->getActiveItems()[0][0] ?? NULL; + $activeMax = $facet->getActiveItems()[0][1] ?? NULL; /** @var \Drupal\facets\Result\ResultInterface[] $results */ foreach ($results as &$result) { @@ -115,15 +119,29 @@ class RangeProcessor extends ProcessorPluginBase implements PreQueryProcessorInt if ($result instanceof BoundResultInterface) { switch ($result->getBound()) { case 'lower': - // For a result intended for the lower bound the min is the actual + // For a result intended for lower bound, the minimum is the actual // value. $minValue = $result->getRawValue(); + if (isset($activeMin) && $minValue == $activeMin) { + $result->setActiveState(TRUE); + } + // Preserve current active max. + if (isset($activeMax)) { + $maxValue = $activeMax; + } break; case 'upper': - // For a result intended for the upper bound the max is the actual + // For a result intended for upper bound, the maximum is the actual // value. $maxValue = $result->getRawValue(); + if (isset($activeMax) && $maxValue == $activeMax) { + $result->setActiveState(TRUE); + } + // Preserve current active min. + if (isset($activeMin)) { + $minValue = $activeMin; + } break; default: @@ -193,7 +211,7 @@ class RangeProcessor extends ProcessorPluginBase implements PreQueryProcessorInt else { $min = reset($results)['value'] ?? 0; $max = end($results)['value'] ?? 0; - // If max is not divisible by step we should add the remainder to max to + // If max is not divisible by step, we should add the remainder to max to // make sure that we do not lose any possible values. if ($max % $step !== 0) { $max = $max + ($step - $max % $step); -- GitLab