function UiHelperTrait::buildUrl
Same name in other branches
- 9 core/tests/Drupal/Tests/UiHelperTrait.php \Drupal\Tests\UiHelperTrait::buildUrl()
- 8.9.x core/tests/Drupal/Tests/UiHelperTrait.php \Drupal\Tests\UiHelperTrait::buildUrl()
- 11.x core/tests/Drupal/Tests/UiHelperTrait.php \Drupal\Tests\UiHelperTrait::buildUrl()
Builds an absolute URL from a system path or a URL object.
Parameters
string|\Drupal\Core\Url $path: A system path or a URL object.
array $options: Options to be passed to Url::fromUri().
Return value
string An absolute URL string.
18 calls to UiHelperTrait::buildUrl()
- BrowserTestBaseUserAgentTest::testUserAgentValidation in core/
tests/ Drupal/ FunctionalTests/ BrowserTestBaseUserAgentTest.php - Tests validation of the User-Agent header we use to perform test requests.
- BrowserWithJavascriptTest::drupalGetWithAlert in core/
tests/ Drupal/ FunctionalJavascriptTests/ BrowserWithJavascriptTest.php - Retrieves a Drupal path or an absolute path.
- CommentNewIndicatorTest::renderNewCommentsNodeLinks in core/
modules/ comment/ tests/ src/ Functional/ CommentNewIndicatorTest.php - Get node "x new comments" metadata from the server for the current user.
- ContextualDynamicContextTest::renderContextualLinks in core/
modules/ contextual/ tests/ src/ Functional/ ContextualDynamicContextTest.php - Get server-rendered contextual links for the given contextual link ids.
- DestinationTest::testDestination in core/
modules/ system/ tests/ src/ Functional/ Routing/ DestinationTest.php - Tests that $_GET/$_REQUEST['destination'] only contain internal URLs.
File
-
core/
tests/ Drupal/ Tests/ UiHelperTrait.php, line 312
Class
- UiHelperTrait
- Provides UI helper methods.
Namespace
Drupal\TestsCode
protected function buildUrl($path, array $options = []) {
global $base_path;
if ($path instanceof Url) {
$url_options = $path->getOptions();
$options = $url_options + $options;
$path->setOptions($options);
return $path->setAbsolute()
->toString();
}
elseif (\Drupal::hasService('url_generator')) {
// Strip $base_path, if existent.
$length = strlen($base_path);
if (substr($path, 0, $length) === $base_path) {
$path = substr($path, $length);
}
// Additionally strip any forward slashes.
if (strlen($path) > 1) {
$path = ltrim($path, '/');
}
$force_internal = isset($options['external']) && $options['external'] == FALSE;
if (!$force_internal && UrlHelper::isExternal($path)) {
return Url::fromUri($path, $options)->toString();
}
else {
$uri = $path === '<front>' ? 'base:/' : 'base:/' . $path;
// Path processing is needed for language prefixing. Skip it when a
// path that may look like an external URL is being used as internal.
$options['path_processing'] = !$force_internal;
return Url::fromUri($uri, $options)->setAbsolute()
->toString();
}
}
else {
return $this->getAbsoluteUrl($path);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.