@@ -57,14 +57,12 @@ public function createSearchBar(Query $query, ...$params): SearchBar
57
57
$ requestUrl = Url::fromRequest ();
58
58
$ preserveParams = array_pop ($ params ) ?? [];
59
59
$ redirectUrl = array_pop ($ params );
60
-
61
- $ requestUrlClone = $ requestUrl ->onlyWith ($ preserveParams );
62
- $ paramsToAdd = $ requestUrlClone ->getParams ()->toArray (false );
60
+ $ paramsToAdd = $ this ->decodedParamValues ($ preserveParams , $ requestUrl );
63
61
64
62
if ($ redirectUrl !== null ) {
65
63
$ redirectUrl ->addParams ($ paramsToAdd );
66
64
} else {
67
- $ redirectUrl = $ requestUrlClone ;
65
+ $ redirectUrl = $ requestUrl -> onlyWith ( $ preserveParams ) ;
68
66
}
69
67
70
68
$ filter = QueryString::fromString ((string ) $ this ->params )
@@ -159,7 +157,7 @@ public function createSearchEditor(Query $query, ...$params): SearchEditor
159
157
$ redirectUrl = array_pop ($ params );
160
158
$ moduleName = $ this ->getRequest ()->getModuleName ();
161
159
$ controllerName = $ this ->getRequest ()->getControllerName ();
162
- $ paramsToAdd = $ requestUrl -> onlyWith ($ preserveParams)-> getParams ()-> toArray ( false );
160
+ $ paramsToAdd = $ this -> decodedParamValues ($ preserveParams, $ requestUrl );
163
161
164
162
if ($ redirectUrl !== null ) {
165
163
$ redirectUrl ->addParams ($ paramsToAdd );
@@ -259,4 +257,27 @@ protected function enrichFilterCondition(Filter\Condition $condition, Query $que
259
257
$ condition ->metaData ()->set ('columnLabel ' , $ label );
260
258
}
261
259
}
260
+
261
+ /**
262
+ * Decode the given param names from the given Url
263
+ *
264
+ * @internal This is only a helping method to prevent params being encoded multiple times in
265
+ * {@see SearchControls::createSearchBar()} and {@see SearchControls::createSearchEditor()}
266
+ * and therefore should not be used anywhere else.
267
+ *
268
+ * @return array<string, mixed> decoded key => value pairs
269
+ */
270
+ private function decodedParamValues (array $ paramNames , Url $ url ): array
271
+ {
272
+ $ params = [];
273
+ foreach ($ paramNames as $ param ) {
274
+ $ val = $ url ->getParam ($ param );
275
+
276
+ if ($ val !== null ) {
277
+ $ params [$ param ] = $ val ;
278
+ }
279
+ }
280
+
281
+ return $ params ;
282
+ }
262
283
}
0 commit comments