Skip to content

Commit

Permalink
SearchControls: Add available $preserveParams as default to `(Searc…
Browse files Browse the repository at this point in the history
…hBar/SearchEditor)suggestionUrl`

This way we no longer have to set the suggestionUrl manually, as in (Host/Service)groupController
  • Loading branch information
sukhwinder33445 committed Oct 21, 2024
1 parent e0918eb commit 8371773
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Compat/SearchControls.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ public function createSearchBar(Query $query, ...$params): SearchBar
$preserveParams = array_pop($params) ?? [];
$redirectUrl = array_pop($params);

$paramsToAdd = $requestUrl->onlyWith($preserveParams)->getParams()->toArray(false);

if ($redirectUrl !== null) {
$redirectUrl->addParams($requestUrl->onlyWith($preserveParams)->getParams()->toArray(false));
$redirectUrl->addParams($paramsToAdd);
} else {
$redirectUrl = $requestUrl->onlyWith($preserveParams);
$redirectUrl = clone $requestUrl;
$redirectUrl->setParams($paramsToAdd);
}

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

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

if ($redirectUrl !== null) {
$redirectUrl->addParams($requestUrl->onlyWith($preserveParams)->getParams()->toArray(false));
$redirectUrl->addParams($paramsToAdd);
} else {
$redirectUrl = Url::fromPath("$moduleName/$controllerName");
if (! empty($preserveParams)) {
$redirectUrl->setParams($requestUrl->onlyWith($preserveParams)->getParams());
if (! empty($paramsToAdd)) {
$redirectUrl->setParams($paramsToAdd);
}
}

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

Expand Down

0 comments on commit 8371773

Please sign in to comment.