function RedirectResponseSubscriber::getDestinationAsAbsoluteUrl
Same name in other branches
- 9 core/lib/Drupal/Core/EventSubscriber/RedirectResponseSubscriber.php \Drupal\Core\EventSubscriber\RedirectResponseSubscriber::getDestinationAsAbsoluteUrl()
- 8.9.x core/lib/Drupal/Core/EventSubscriber/RedirectResponseSubscriber.php \Drupal\Core\EventSubscriber\RedirectResponseSubscriber::getDestinationAsAbsoluteUrl()
- 11.x core/lib/Drupal/Core/EventSubscriber/RedirectResponseSubscriber.php \Drupal\Core\EventSubscriber\RedirectResponseSubscriber::getDestinationAsAbsoluteUrl()
Converts the passed in destination into an absolute URL.
Parameters
string $destination: The path for the destination. In case it starts with a slash it should have the base path included already.
string $scheme_and_host: The scheme and host string of the current request.
Return value
string The destination as absolute URL.
1 call to RedirectResponseSubscriber::getDestinationAsAbsoluteUrl()
- RedirectResponseSubscriber::checkRedirectUrl in core/
lib/ Drupal/ Core/ EventSubscriber/ RedirectResponseSubscriber.php - Allows manipulation of the response object when performing a redirect.
File
-
core/
lib/ Drupal/ Core/ EventSubscriber/ RedirectResponseSubscriber.php, line 111
Class
- RedirectResponseSubscriber
- Allows manipulation of the response object when performing a redirect.
Namespace
Drupal\Core\EventSubscriberCode
protected function getDestinationAsAbsoluteUrl($destination, $scheme_and_host) {
if (!UrlHelper::isExternal($destination)) {
// The destination query parameter can be a relative URL in the sense of
// not including the scheme and host, but its path is expected to be
// absolute (start with a '/'). For such a case, prepend the scheme and
// host, because the 'Location' header must be absolute.
if (str_starts_with($destination, '/')) {
$destination = $scheme_and_host . $destination;
}
else {
// Legacy destination query parameters can be internal paths that have
// not yet been converted to URLs.
$destination = UrlHelper::parse($destination);
$uri = 'base:' . $destination['path'];
$options = [
'query' => $destination['query'],
'fragment' => $destination['fragment'],
'absolute' => TRUE,
];
// Treat this as if it's user input of a path relative to the site's
// base URL.
$destination = $this->unroutedUrlAssembler
->assemble($uri, $options);
}
}
return $destination;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.