You are here

protected function RssFields::getAbsoluteUrl in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/views/row/RssFields.php \Drupal\views\Plugin\views\row\RssFields::getAbsoluteUrl()
  2. 9 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

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();
  }
}