diff --git a/src/Plugin/facets/processor/RangeProcessor.php b/src/Plugin/facets/processor/RangeProcessor.php index f71834a82b191b4037ca9303e72e5e36cd9698ed..d6be462354cef7a91d03cfb3cb0e3286797e808c 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);