Provide active filters to filter state

This commit is contained in:
Alexander Skvortsov 2021-03-12 15:30:14 -05:00
parent 99311188a2
commit 38dc12ef0d
2 changed files with 26 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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;
}
}