Skip to content
Snippets Groups Projects
Commit e265ad72 authored by Rico Van de Vin's avatar Rico Van de Vin
Browse files

Issue #3268337 by nickvanboven, jonathan_hunt, ricovandevin: Dropdown Range...

Issue #3268337 by nickvanboven, jonathan_hunt, ricovandevin: Dropdown Range value reset after one value selected
parent f004c9f1
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment