function UiHelperTrait::buildUrl
Same name in other branches
- 9 core/tests/Drupal/Tests/UiHelperTrait.php \Drupal\Tests\UiHelperTrait::buildUrl()
- 10 core/tests/Drupal/Tests/UiHelperTrait.php \Drupal\Tests\UiHelperTrait::buildUrl()
- 11.x core/tests/Drupal/Tests/UiHelperTrait.php \Drupal\Tests\UiHelperTrait::buildUrl()
Builds an a absolute URL from a system path or a URL object.
Parameters
string|\Drupal\Core\Url $path: A system path or a URL.
array $options: Options to be passed to Url::fromUri().
Return value
string An absolute URL string.
22 calls to UiHelperTrait::buildUrl()
- BrowserTestBaseUserAgentTest::testUserAgentValidation in core/
tests/ Drupal/ FunctionalTests/ BrowserTestBaseUserAgentTest.php - Test 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 364
Class
- UiHelperTrait
- Provides UI helper methods.
Namespace
Drupal\TestsCode
protected function buildUrl($path, array $options = []) {
if ($path instanceof Url) {
$url_options = $path->getOptions();
$options = $url_options + $options;
$path->setOptions($options);
return $path->setAbsolute()
->toString();
}
elseif (\Drupal::hasService('url_generator')) {
$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.