protected function UnroutedUrlAssembler::buildExternalUrl in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php \Drupal\Core\Utility\UnroutedUrlAssembler::buildExternalUrl()
1 call to UnroutedUrlAssembler::buildExternalUrl()
- UnroutedUrlAssembler::assemble in core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php
- This is a helper function that calls buildExternalUrl() or buildLocalUrl()
based on a check of whether the path is a valid external URL.
File
- core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php, line 75
- Contains \Drupal\Core\Utility\UnroutedUrlAssembler.
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);
if (strpos($uri, '#') !== FALSE) {
list($uri, $old_fragment) = explode('#', $uri, 2);
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);
}
}
if ($options['query']) {
$uri .= (strpos($uri, '?') !== FALSE ? '&' : '?') . UrlHelper::buildQuery($options['query']);
}
$url = $uri . $options['fragment'];
return $collect_bubbleable_metadata ? (new GeneratedUrl())
->setGeneratedUrl($url) : $url;
}