function UiHelperTrait::getAbsoluteUrl

Same name in other branches
  1. 9 core/tests/Drupal/Tests/UiHelperTrait.php \Drupal\Tests\UiHelperTrait::getAbsoluteUrl()
  2. 8.9.x core/tests/Drupal/Tests/UiHelperTrait.php \Drupal\Tests\UiHelperTrait::getAbsoluteUrl()
  3. 10 core/tests/Drupal/Tests/UiHelperTrait.php \Drupal\Tests\UiHelperTrait::getAbsoluteUrl()

Takes a path and returns an absolute path.

Parameters

string $path: A path from the Mink controlled browser content.

Return value

string The $path with $base_url prepended, if necessary.

24 calls to UiHelperTrait::getAbsoluteUrl()
AssetOptimizationTest::assertAggregate in core/tests/Drupal/FunctionalTests/Asset/AssetOptimizationTest.php
Asserts the aggregate header.
AssetOptimizationTest::assertInvalidAggregates in core/tests/Drupal/FunctionalTests/Asset/AssetOptimizationTest.php
Asserts the aggregate when it is invalid.
AssetOptimizationTest::invalidExclude in core/tests/Drupal/FunctionalTests/Asset/AssetOptimizationTest.php
Adds an invalid 'exclude' query parameter with an invalid value.
AssetOptimizationTest::invalidInclude in core/tests/Drupal/FunctionalTests/Asset/AssetOptimizationTest.php
Replaces the 'include' query parameter with an invalid value.
AssetOptimizationTest::omitInclude in core/tests/Drupal/FunctionalTests/Asset/AssetOptimizationTest.php
Removes the 'include' query parameter from the given URL.

... See full list

File

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

Class

UiHelperTrait
Provides UI helper methods.

Namespace

Drupal\Tests

Code

protected function getAbsoluteUrl($path) {
    global $base_url, $base_path;
    $parts = parse_url($path);
    if (empty($parts['host'])) {
        // Ensure that we have a string (and no xpath object).
        $path = (string) $path;
        // Strip $base_path, if existent.
        $length = strlen($base_path);
        if (substr($path, 0, $length) === $base_path) {
            $path = substr($path, $length);
        }
        // Ensure that we have an absolute path.
        if (empty($path) || $path[0] !== '/') {
            $path = '/' . $path;
        }
        // Finally, prepend the $base_url.
        $path = $base_url . $path;
    }
    return $path;
}

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