function RssResponseRelativeUrlFilter::transformRootRelativeUrlsToAbsolute
Same name in other branches
- 9 core/lib/Drupal/Core/EventSubscriber/RssResponseRelativeUrlFilter.php \Drupal\Core\EventSubscriber\RssResponseRelativeUrlFilter::transformRootRelativeUrlsToAbsolute()
- 8.9.x core/lib/Drupal/Core/EventSubscriber/RssResponseRelativeUrlFilter.php \Drupal\Core\EventSubscriber\RssResponseRelativeUrlFilter::transformRootRelativeUrlsToAbsolute()
- 10 core/lib/Drupal/Core/EventSubscriber/RssResponseRelativeUrlFilter.php \Drupal\Core\EventSubscriber\RssResponseRelativeUrlFilter::transformRootRelativeUrlsToAbsolute()
Converts all root-relative URLs to absolute URLs in RSS markup.
Does not change any existing protocol-relative or absolute URLs.
Parameters
string $rss_markup: The RSS markup to update.
\Symfony\Component\HttpFoundation\Request $request: The current request.
Return value
string The updated RSS markup.
1 call to RssResponseRelativeUrlFilter::transformRootRelativeUrlsToAbsolute()
- RssResponseRelativeUrlFilter::onResponse in core/
lib/ Drupal/ Core/ EventSubscriber/ RssResponseRelativeUrlFilter.php - Converts relative URLs to absolute URLs.
File
-
core/
lib/ Drupal/ Core/ EventSubscriber/ RssResponseRelativeUrlFilter.php, line 45
Class
- RssResponseRelativeUrlFilter
- Subscribes to filter RSS responses, to make relative URIs absolute.
Namespace
Drupal\Core\EventSubscriberCode
protected function transformRootRelativeUrlsToAbsolute($rss_markup, Request $request) {
$rss_dom = new \DOMDocument();
// Load the RSS, if there are parsing errors, abort and return the unchanged
// markup.
$previous_value = libxml_use_internal_errors(TRUE);
$rss_dom->loadXML($rss_markup);
$errors = libxml_get_errors();
libxml_use_internal_errors($previous_value);
if ($errors) {
return $rss_markup;
}
// Invoke Html::transformRootRelativeUrlsToAbsolute() on all HTML content
// embedded in this RSS feed.
foreach ($rss_dom->getElementsByTagName('item') as $item) {
foreach ($item->getElementsByTagName('description') as $node) {
$html_markup = $node->nodeValue;
if (!empty($html_markup)) {
$node->replaceChild($rss_dom->createTextNode(Html::transformRootRelativeUrlsToAbsolute($html_markup, $request->getSchemeAndHttpHost())), $node->firstChild);
}
}
}
return $rss_dom->saveXML();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.