Symfony’s getQueryString method doesn’t return modified query parameters. So how should someone go about getting a modified query parameter string?
Example code:
$request = Drupal::request(); $parameter_bag = $request->query; $parameter_bag->remove('destination'); $query = Drupal::request()->getQueryString(); $query_array_modified = $parameter_bag->all();
$query
in this instance will return the destination
query parameter even though it was removed from the ParameterBag. $query_array_modified
in this instance will not return the destination query parameter … as expected.
PS – Feel free to replace Drupal::request();
with Symfony’s request object in example code below if you are using Symfony.