diff --git a/src/Twig/FilterRuntime.php b/src/Twig/FilterRuntime.php index eda8cd0..c78a42f 100644 --- a/src/Twig/FilterRuntime.php +++ b/src/Twig/FilterRuntime.php @@ -31,6 +31,9 @@ public function isFilterActive(FilterValueInterface $filterValue, FilterInterfac } /** + * If the filter value is already applied, it will be removed from the active filters, so that it can be toggled. + * Otherwise, it will be added to the active filters. + * * @param array> $activeFilters */ public function mergeFilterValueWithCurrentActiveFilters( @@ -42,9 +45,11 @@ public function mergeFilterValueWithCurrentActiveFilters( if (!array_key_exists($filterType, $activeFilters)) { $activeFilters[$filterType] = []; } - foreach ($activeFilters[$filterType] as $appliedFilterValue) { + foreach ($activeFilters[$filterType] as $key => $appliedFilterValue) { if ($appliedFilterValue['code'] === $filter->getKeyCode() && $appliedFilterValue['value'] === $filterValue->getKey()) { + unset($activeFilters[$filterType][$key]); + return $activeFilters; } }