Skip to content

Commit

Permalink
Improve query params handling to support search and other extensions (#…
Browse files Browse the repository at this point in the history
…32)

* Improve query params handling to support search and other extensions

* Apply fixes from StyleCI

Co-authored-by: StyleCI Bot <bot@styleci.io>
  • Loading branch information
clarkwinkelmann and StyleCIBot committed Oct 25, 2022
1 parent 5dadbf8 commit d1f57fd
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Middleware/AddLanguageFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,15 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
*/
private function addQueryParams(ServerRequestInterface $request, array $params, string $language): ServerRequestInterface
{
return $request->withQueryParams(
array_merge($params, ['filter' => ['language' => $language]]),
);
// use recursive merge to preserve filters added by other extensions
$newParams = array_merge_recursive($params, ['filter' => ['language' => $language]]);

// If a search is in progress, add the search gambit
if (Arr::get($params, 'q')) {
$newParams['q'] = Arr::get($params, 'q').' language:'.$language;
}

return $request->withQueryParams($newParams);
}

private function isDiscussionListPath($request)
Expand Down

0 comments on commit d1f57fd

Please sign in to comment.