Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. RssFields.php

function 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
Renders a row object.

File

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

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 (str_starts_with($url_string, '/')) {
        $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();
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal