protected function UnroutedUrlAssembler::buildExternalUrl

protected UnroutedUrlAssembler::buildExternalUrl($uri, array $options = [], $collect_bubbleable_metadata = FALSE)

File

core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php, line 70

Class

UnroutedUrlAssembler
Provides a way to build external or non Drupal local domain URLs.

Namespace

Drupal\Core\Utility

Code

protected function buildExternalUrl($uri, array $options = [], $collect_bubbleable_metadata = FALSE) {
  $this->addOptionDefaults($options);
  // Split off the fragment.
  if (strpos($uri, '#') !== FALSE) {
    list($uri, $old_fragment) = explode('#', $uri, 2);
    // If $options contains no fragment, take it over from the path.
    if (isset($old_fragment) && !$options['fragment']) {
      $options['fragment'] = '#' . $old_fragment;
    }
  }

  if (isset($options['https'])) {
    if ($options['https'] === TRUE) {
      $uri = str_replace('http://', 'https://', $uri);
    }
    elseif ($options['https'] === FALSE) {
      $uri = str_replace('https://', 'http://', $uri);
    }
  }
  // Append the query.
  if ($options['query']) {
    $uri .= (strpos($uri, '?') !== FALSE ? '&' : '?') . UrlHelper::buildQuery($options['query']);
  }
  // Reassemble.
  $url = $uri . $options['fragment'];
  return $collect_bubbleable_metadata ? (new GeneratedUrl())->setGeneratedUrl($url) : $url;
}

© 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!Utility!UnroutedUrlAssembler.php/function/UnroutedUrlAssembler::buildExternalUrl/8.1.x