I have created very simple renderable link array that may or may not use the 'destination' query argument like so:
$link = array(
'#type' => 'link',
'#title' => 'sometext'
'#route_name' => 'someroute',
'#route_parameters' => array()
);
if ($something) {
$link['#options']['query']['destination'] = current_path();
}
Current path, like in most situations, contains backslash(my/path/whatever
). If I render this array the destination value will get urlencoded which will not break the link but it is inconsistent with using direct path(#href) instead of route.
I've been able to back-trace the origin of this behavior through \Drupal\Core\Url::toString()
, where route or path generator is selected, to the \Symfony\Component\Routing\Generator\UrlGenerator::doGenerate()
which uses http_build_query
for the query string.
So we either override the doGenerate()
method in \Drupal\Core\Routing\UrlGenerator
or process the string(path) returned by the doGenerate()
method in the \Drupal\Core\Routing\UrlGenerator::getInternalPathFromRoute()
where doGenerate()
is called from to provide unified behavior of link generation.
Comments
Comment #11
catchPretty sure this is by design - the destination URL is supposed to be URL encoded. I think this can be closed, but just in case moving to 'needs more info' and 'needs tests'.
Comment #14
quietone CreditAttribution: quietone at PreviousNext commentedThere has been no activity here for 8 years, except for 9 months about when more information was sought. There has been no further information.
Since we need more information and none has been supplied I am closing this as works as designed as suggested in #11.