function RssFields::getAbsoluteUrl

Same name in other branches
  1. 9 core/modules/views/src/Plugin/views/row/RssFields.php \Drupal\views\Plugin\views\row\RssFields::getAbsoluteUrl()
  2. 10 core/modules/views/src/Plugin/views/row/RssFields.php \Drupal\views\Plugin\views\row\RssFields::getAbsoluteUrl()
  3. 11.x core/modules/views/src/Plugin/views/row/RssFields.php \Drupal\views\Plugin\views\row\RssFields::getAbsoluteUrl()

Convert a rendered URL string to an absolute URL.

Parameters

string $url_string: The rendered field value ready for display in a normal view.

Return value

string A string with an absolute URL.

1 call to RssFields::getAbsoluteUrl()
RssFields::render in core/modules/views/src/Plugin/views/row/RssFields.php
Render a row object. This usually passes through to a theme template of some form, but not always.

File

core/modules/views/src/Plugin/views/row/RssFields.php, line 215

Class

RssFields
Renders an RSS item based on fields.

Namespace

Drupal\views\Plugin\views\row

Code

protected function getAbsoluteUrl($url_string) {
    // If the given URL already starts with a leading slash, it's been processed
    // and we need to simply make it an absolute path by prepending the host.
    if (strpos($url_string, '/') === 0) {
        $host = \Drupal::request()->getSchemeAndHttpHost();
        // @todo Views should expect and store a leading /.
        // @see https://www.drupal.org/node/2423913
        return $host . $url_string;
    }
    else {
        return Url::fromUserInput('/' . $url_string)->setAbsolute()
            ->toString();
    }
}

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