function UiHelperTrait::buildUrl

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/UiHelperTrait.php \Drupal\Tests\UiHelperTrait::buildUrl()
  2. 10 core/tests/Drupal/Tests/UiHelperTrait.php \Drupal\Tests\UiHelperTrait::buildUrl()
  3. 8.9.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.

4 calls to UiHelperTrait::buildUrl()
BrowserWithJavascriptTest::drupalGetWithAlert in core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php
Retrieves a Drupal path or an absolute path.
FileFieldWidgetTest::testWidgetElement in core/modules/file/tests/src/Functional/FileFieldWidgetTest.php
Tests file widget element.
JsonApiFunctionalTest::testRead in core/modules/jsonapi/tests/src/Functional/JsonApiFunctionalTest.php
Tests the GET method.
PageCacheTest::testHead in core/modules/page_cache/tests/src/Functional/PageCacheTest.php
Tests that HEAD requests are treated the same as GET requests.

File

core/tests/Drupal/Tests/UiHelperTrait.php, line 371

Class

UiHelperTrait
Provides UI helper methods.

Namespace

Drupal\Tests

Code

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.