Skip to content

Commit

Permalink
Rebase list filter submitted refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
alterphp committed Dec 8, 2018
1 parent 5bfd818 commit 782b9a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 41 deletions.
13 changes: 12 additions & 1 deletion src/EventListener/AbstractPostQueryBuilderSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,20 @@ public function onPostListQueryBuilder(GenericEvent $event)
{
$queryBuilder = $event->getArgument('query_builder');

// Request filters
if ($event->hasArgument('request')) {
$this->applyRequestFilters($queryBuilder, $event->getArgument('request')->get('filters', array()));
$this->applyFormFilters($queryBuilder, $event->getArgument('request')->get('form_filters', array()));
}

// List form filters
if ($event->hasArgument('entity')) {
$entityConfig = $event->getArgument('entity');
if (isset($entityConfig['list']['form_filters'])) {
$listFormFiltersForm = $this->listFormFiltersHelper->getListFormFilters($entityConfig['list']['form_filters']);
if ($listFormFiltersForm->isSubmitted() && $listFormFiltersForm->isValid()) {
$this->applyFormFilters($queryBuilder, $listFormFiltersForm->getData());
}
}
}
}

Expand Down
40 changes: 0 additions & 40 deletions src/EventListener/PostQueryBuilderSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,46 +40,6 @@ public static function getSubscribedEvents()
);
}

/**
* Called on POST_LIST_QUERY_BUILDER event.
*
* @param GenericEvent $event
*/
public function onPostListQueryBuilder(GenericEvent $event)
{
$queryBuilder = $event->getArgument('query_builder');

// Request filters
if ($event->hasArgument('request')) {
$this->applyRequestFilters($queryBuilder, $event->getArgument('request')->get('filters', array()));
}

// List form filters
if ($event->hasArgument('entity')) {
$entityConfig = $event->getArgument('entity');
if (isset($entityConfig['list']['form_filters'])) {
$listFormFiltersForm = $this->listFormFiltersHelper->getListFormFilters($entityConfig['list']['form_filters']);
if ($listFormFiltersForm->isSubmitted() && $listFormFiltersForm->isValid()) {
$this->applyFormFilters($queryBuilder, $listFormFiltersForm->getData());
}
}
}
}

/**
* Called on POST_SEARCH_QUERY_BUILDER event.
*
* @param GenericEvent $event
*/
public function onPostSearchQueryBuilder(GenericEvent $event)
{
$queryBuilder = $event->getArgument('query_builder');

if ($event->hasArgument('request')) {
$this->applyRequestFilters($queryBuilder, $event->getArgument('request')->get('filters', array()));
}
}

/**
* Applies request filters on queryBuilder.
*
Expand Down

0 comments on commit 782b9a5

Please sign in to comment.