@@ -58,10 +58,13 @@ public function createSearchBar(Query $query, ...$params): SearchBar
5858 $ preserveParams = array_pop ($ params ) ?? [];
5959 $ redirectUrl = array_pop ($ params );
6060
61+ $ requestUrlClone = $ requestUrl ->onlyWith ($ preserveParams );
62+ $ paramsToAdd = $ requestUrlClone ->getParams ();
63+
6164 if ($ redirectUrl !== null ) {
62- $ redirectUrl ->addParams ($ requestUrl -> onlyWith ( $ preserveParams )-> getParams () ->toArray (false ));
65+ $ redirectUrl ->addParams ($ paramsToAdd ->toArray (false ));
6366 } else {
64- $ redirectUrl = $ requestUrl -> onlyWith ( $ preserveParams ) ;
67+ $ redirectUrl = $ requestUrlClone ;
6568 }
6669
6770 $ filter = QueryString::fromString ((string ) $ this ->params )
@@ -83,7 +86,10 @@ 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+ $ paramsToAdd
90+ ->set ('_disableLayout ' , true )
91+ ->set ('showCompact ' , true )
92+ ->toArray (false )
8793 ));
8894 }
8995
@@ -156,14 +162,13 @@ public function createSearchEditor(Query $query, ...$params): SearchEditor
156162 $ redirectUrl = array_pop ($ params );
157163 $ moduleName = $ this ->getRequest ()->getModuleName ();
158164 $ controllerName = $ this ->getRequest ()->getControllerName ();
165+ $ paramsToAdd = $ requestUrl ->onlyWith ($ preserveParams )->getParams ();
159166
160167 if ($ redirectUrl !== null ) {
161- $ redirectUrl ->addParams ($ requestUrl -> onlyWith ( $ preserveParams )-> getParams () ->toArray (false ));
168+ $ redirectUrl ->addParams ($ paramsToAdd ->toArray (false ));
162169 } else {
163- $ redirectUrl = Url::fromPath ("$ moduleName/ $ controllerName " );
164- if (! empty ($ preserveParams )) {
165- $ redirectUrl ->setParams ($ requestUrl ->onlyWith ($ preserveParams )->getParams ());
166- }
170+ $ redirectUrl = Url::fromPath ("$ moduleName/ $ controllerName " )
171+ ->setParams ($ paramsToAdd );
167172 }
168173
169174 $ editor = new SearchEditor ();
@@ -174,7 +179,10 @@ public function createSearchEditor(Query $query, ...$params): SearchEditor
174179 if (method_exists ($ this , 'completeAction ' )) {
175180 $ editor ->setSuggestionUrl (Url::fromPath (
176181 "$ moduleName/ $ controllerName/complete " ,
177- ['_disableLayout ' => true , 'showCompact ' => true ]
182+ $ paramsToAdd
183+ ->set ('_disableLayout ' , true )
184+ ->set ('showCompact ' , true )
185+ ->toArray (false )
178186 ));
179187 }
180188
0 commit comments