Skip to content

Commit 79e4b86

Browse files
authored
Merge pull request #3201 from Enelogic/2.5
fix #3189 - JSONAPI pagination ignored when using filter parameter
2 parents 07d13d9 + 732d442 commit 79e4b86

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

features/jsonapi/filtering.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ Feature: JSON API filter handling
2323
And the JSON should be valid according to the JSON API schema
2424
And the JSON node "data" should have 0 elements
2525

26+
Scenario: Apply filters and pagination at the same time
27+
When I send a "GET" request to "/dummies?filter[name]=foo&page[page]=2"
28+
Then the response status code should be 200
29+
And the response should be in JSON
30+
And the JSON should be valid according to the JSON API schema
31+
Then the JSON node "meta.currentPage" should be a number
32+
Then the JSON node "meta.currentPage" should be equal to "2"
33+
2634
Scenario: Apply property filter based on the 'fields'
2735
Given there are 2 dummy property objects
2836
When I send a "GET" request to "/dummy_properties?fields[DummyProperty]=id,foo,bar"

src/JsonApi/EventListener/TransformFilteringParametersListener.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ public function onKernelRequest(GetResponseEvent $event): void
2929
$request = $event->getRequest();
3030
if (
3131
'jsonapi' !== $request->getRequestFormat() ||
32-
null === ($filters = $request->query->get('filter')) ||
33-
!\is_array($filters)
32+
null === ($filterParameter = $request->query->get('filter')) ||
33+
!\is_array($filterParameter)
3434
) {
3535
return;
3636
}
37-
38-
$request->attributes->set('_api_filters', $filters);
37+
$filters = $request->attributes->get('_api_filters', []);
38+
$request->attributes->set('_api_filters', array_merge($filterParameter, $filters));
3939
}
4040
}

0 commit comments

Comments
 (0)