toString() method is not handling query params for Url::createFromRequest

Created on 30 October 2025, 10 days ago

Problem/Motivation

toString() method is not handling query params for Url::createFromRequest()

my_module.custom_route:
  path: 'my_path'
  defaults:
    _controller: \Drupal\my_module\Controller\MyController::build
  requirements:
    _permission: 'access content'
public function build(Request $request) {
   // Display '/my-path';
  dump(Url::createFromRequest($request)->toString());
  $newRequest = clone($request);
  $newRequest->set('query_arg', 'test');
  // Display '/my-path' instead of '/my-path?query_arg=test';
  dump(Url::createFromRequest($newRequest)->toString());
  // Display '/my-path?query_arg=test';
  dump(Url::fromRoute('my_module.custom_route', [], ['query' => ['query_arg' => 'test']])->toString());
}

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

11.0 🔥

Component

base system

Created by

🇫🇷France MacSim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024