Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SearchControls: Add available $preserveParams as default to (SearchBar/SearchEditor)suggestionUrl #233

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 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);

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

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

$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]
$paramsToAdd + ['_disableLayout' => true, 'showCompact' => true]
));
}

Expand Down Expand Up @@ -156,14 +159,13 @@ 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());
}
$redirectUrl = Url::fromPath("$moduleName/$controllerName")
->setParams($paramsToAdd);
}

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

Expand Down
Loading