From 38dc12ef0d83eb8f036f18412dad61f49a6c3730 Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Fri, 12 Mar 2021 15:30:14 -0500 Subject: [PATCH] Provide active filters to filter state --- .../core/src/Filter/AbstractFilterer.php | 1 + framework/core/src/Filter/FilterState.php | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/framework/core/src/Filter/AbstractFilterer.php b/framework/core/src/Filter/AbstractFilterer.php index 736568901..5f07fdbbb 100644 --- a/framework/core/src/Filter/AbstractFilterer.php +++ b/framework/core/src/Filter/AbstractFilterer.php @@ -62,6 +62,7 @@ abstract class AbstractFilterer $filterKey = substr($filterKey, 1); } foreach (Arr::get($this->filters, $filterKey, []) as $filter) { + $filterState->addActiveFilter($filter); $filter->filter($filterState, $filterValue, $negate); } } diff --git a/framework/core/src/Filter/FilterState.php b/framework/core/src/Filter/FilterState.php index b9e22611e..5597964da 100644 --- a/framework/core/src/Filter/FilterState.php +++ b/framework/core/src/Filter/FilterState.php @@ -13,4 +13,29 @@ use Flarum\Query\AbstractQueryState; class FilterState extends AbstractQueryState { + /** + * @var FilterInterface[] + */ + protected $activeFilters = []; + + /** + * Get a list of the filters that are active. + * + * @return FilterInterface[] + */ + public function getActiveFilters() + { + return $this->activeFilters; + } + + /** + * Add a filter as being active. + * + * @param FilterInterface $filter + * @return void + */ + public function addActiveFilter(FilterInterface $filter) + { + $this->activeFilters[] = $filter; + } }