Skip to content

Commit

Permalink
Allow to unset filter value
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Apr 24, 2024
1 parent a5c39db commit 518c8c4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Twig/FilterRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, array<array-key, array{code: string, value: string}>> $activeFilters
*/
public function mergeFilterValueWithCurrentActiveFilters(
Expand All @@ -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;
}
}
Expand Down

0 comments on commit 518c8c4

Please sign in to comment.