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;
}
doc_Drupal
2016-10-29 09:50:28
Comments
Leave a Comment

Please login to continue.