function HttpKernelUiHelperTrait::buildUrl

Same name and namespace in other branches
  1. main core/tests/Drupal/Tests/HttpKernelUiHelperTrait.php \Drupal\Tests\HttpKernelUiHelperTrait::buildUrl()

Builds a 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(). If $path is a Url object, any options it has will take priority over this parameter.

Return value

string A URL string.

1 call to HttpKernelUiHelperTrait::buildUrl()
HttpKernelUiHelperTrait::drupalGet in core/tests/Drupal/Tests/HttpKernelUiHelperTrait.php
Retrieves a Drupal path.

File

core/tests/Drupal/Tests/HttpKernelUiHelperTrait.php, line 134

Class

HttpKernelUiHelperTrait
Provides UI helper methods using the HTTP kernel to make requests.

Namespace

Drupal\Tests

Code

protected function buildUrl(Url|string $path, array $options = []) : string {
  assert(empty($options['absolute']), 'Absolute URLs are not usable with drupalGet().');
  if ($path instanceof Url) {
    if ($options) {
      $url_options = $path->getOptions();
      $options = $url_options + $options;
      $path->setOptions($options);
    }
    return $path->toString();
  }
  $uri = $path === '<front>' ? 'base:/' : 'base:/' . $path;
  return Url::fromUri($uri, $options)->toString();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.