Noticed this will creating a Url with a query string for a view using Url::fromRoute(). In short, following the documentation results in a query string prepended with the word "query", like this:

https://example.com/search?query%5Bkeywords%5D=washington

According to the documentation for Url::fromRoute(), the function's $options parameter should be the same as for Url::fromUri():

See \Drupal\Core\Url::fromUri() for details.

The documentation for Url::fromUri() specifies that $options should be an associative array with a query element (when adding a query string of course).

The following (simplified) code produces the buggy url above:

$route = 'view.search_view.page_1';
$options = [
  $query => ['keywords' => 'washington'],
];
$url = Url::fromRoute($route, $options)

The following code (also simplified) works:

$route = 'view.search_view.page_1';
$options = [
  ['keywords' => 'washington],
];
$url = Url::fromRoute($route, $options)

I'll try to debug this and create a working demo, perhaps next week.

Comments

bedlam created an issue. See original summary.

bedlam’s picture

Issue summary: View changes
bedlam’s picture

Issue summary: View changes
bedlam’s picture

Status: Active » Closed (works as designed)

I think I got this wrong (hurrah!)

Closing for now.