Skip to content

Commit 8371773

Browse files
SearchControls: Add available $preserveParams as default to (SearchBar/SearchEditor)suggestionUrl
This way we no longer have to set the suggestionUrl manually, as in (Host/Service)groupController
1 parent e0918eb commit 8371773

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/Compat/SearchControls.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,13 @@ public function createSearchBar(Query $query, ...$params): SearchBar
5858
$preserveParams = array_pop($params) ?? [];
5959
$redirectUrl = array_pop($params);
6060

61+
$paramsToAdd = $requestUrl->onlyWith($preserveParams)->getParams()->toArray(false);
62+
6163
if ($redirectUrl !== null) {
62-
$redirectUrl->addParams($requestUrl->onlyWith($preserveParams)->getParams()->toArray(false));
64+
$redirectUrl->addParams($paramsToAdd);
6365
} else {
64-
$redirectUrl = $requestUrl->onlyWith($preserveParams);
66+
$redirectUrl = clone $requestUrl;
67+
$redirectUrl->setParams($paramsToAdd);
6568
}
6669

6770
$filter = QueryString::fromString((string) $this->params)
@@ -83,7 +86,7 @@ public function createSearchBar(Query $query, ...$params): SearchBar
8386
if (method_exists($this, 'completeAction')) {
8487
$searchBar->setSuggestionUrl(Url::fromPath(
8588
"$moduleName/$controllerName/complete",
86-
['_disableLayout' => true, 'showCompact' => true]
89+
array_merge($paramsToAdd, ['_disableLayout' => true, 'showCompact' => true])
8790
));
8891
}
8992

@@ -156,13 +159,14 @@ public function createSearchEditor(Query $query, ...$params): SearchEditor
156159
$redirectUrl = array_pop($params);
157160
$moduleName = $this->getRequest()->getModuleName();
158161
$controllerName = $this->getRequest()->getControllerName();
162+
$paramsToAdd = $requestUrl->onlyWith($preserveParams)->getParams()->toArray(false);
159163

160164
if ($redirectUrl !== null) {
161-
$redirectUrl->addParams($requestUrl->onlyWith($preserveParams)->getParams()->toArray(false));
165+
$redirectUrl->addParams($paramsToAdd);
162166
} else {
163167
$redirectUrl = Url::fromPath("$moduleName/$controllerName");
164-
if (! empty($preserveParams)) {
165-
$redirectUrl->setParams($requestUrl->onlyWith($preserveParams)->getParams());
168+
if (! empty($paramsToAdd)) {
169+
$redirectUrl->setParams($paramsToAdd);
166170
}
167171
}
168172

@@ -174,7 +178,7 @@ public function createSearchEditor(Query $query, ...$params): SearchEditor
174178
if (method_exists($this, 'completeAction')) {
175179
$editor->setSuggestionUrl(Url::fromPath(
176180
"$moduleName/$controllerName/complete",
177-
['_disableLayout' => true, 'showCompact' => true]
181+
array_merge($paramsToAdd, ['_disableLayout' => true, 'showCompact' => true])
178182
));
179183
}
180184

0 commit comments

Comments
 (0)