W3cubDocs

/Drupal 8

protected function RedirectResponseSubscriber::getDestinationAsAbsoluteUrl

protected RedirectResponseSubscriber::getDestinationAsAbsoluteUrl($destination, $scheme_and_host)

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.

File

core/lib/Drupal/Core/EventSubscriber/RedirectResponseSubscriber.php, line 105

Class

RedirectResponseSubscriber
Allows manipulation of the response object when performing a redirect.

Namespace

Drupal\Core\EventSubscriber

Code

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 (strpos($destination, '/') === 0) {
      $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;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!EventSubscriber!RedirectResponseSubscriber.php/function/RedirectResponseSubscriber::getDestinationAsAbsoluteUrl/8.1.x