Skip to content
Snippets Groups Projects
Commit 19abaf50 authored by Damien McKenna's avatar Damien McKenna Committed by Damien McKenna
Browse files

Issue #3303538 by DamienMcKenna: Channel image link is empty.

parent 1cd569b1
Branches
Tags
No related merge requests found
......@@ -4,6 +4,7 @@ Advanced Views RSS Feed 8.x-2.x, 2023-xx-xx
available on the filesystem.
#3383734 by DamienMcKenna, idebr: Warning: filesize(): stat failed for [image
url] when using a static image as the feed thumbnail.
#3303538 by DamienMcKenna: Channel image link is empty.
Advanced Views RSS Feed 8.x-2.1, 2023-07-11
......
......
......@@ -33,6 +33,26 @@ feeds.
* Review the output and continue making changes as necessary.
## Troubleshooting
### The channel image link tag is incorrect
If the channel->image->link tag outputs as `imagelink` instead of just `link`,
the problem is that the module's custom `views-view-rss.html.twig` file is not
being used. To fix this, either copy that file to the theme's "templates"
directory, or update the theme's twig file to match the following:
{{ channel_elements|render|replace({"imagelink": "link"})|raw }}
This is safe to do as the content passes through Drupal's render system first,
which will filter out any security concerns.
### RSS validators complain of an invalid "imagelink" tag
See "The channel image link tag is incorrect" above.
## Support
Please post questions, bug reports and feature reports to the [project's issue
......
......
......@@ -118,10 +118,19 @@ function views_rss_core_preprocess_channel_image(&$variables) {
}
// The image's link element identifies the URL of the web site represented by
// the image, not the feed URL.
// the image, not the feed URL. The first problem is that Drupal's normal Twig
// filtering strips out LINK tag values as it is supposed to be a self-closing
// tag, e.g. "<link src="something" />" and not "<link>something</link>". The
// second problem is that LINK tags are also normally filtered out entirely
// because a LINK tag is normally considered a security problem. Therefore,
// output the tag with a custom tag name that is then adjusted in the template
// file. Yes, this is super hacky, but there aren't too many ways around it.
// @see \Drupal\Core\Render\Element\HtmlTag::$voidElements
// @see \Drupal\Core\Render\Renderer::xssFilterAdminIfUnsafe()
// @see views-view-rss.html.twig
$variables['elements'][0]['value']['link'] = [
'#type' => 'html_tag',
'#tag' => 'link',
'#tag' => 'imagelink',
'#value' => views_rss_link_to_front_page(),
];
......
......
{#
/**
* @file
* Default template for feed displays that use the RSS style.
*
* Available variables:
* - link: The link to the feed (the view path).
* - namespaces: The XML namespaces (added automatically).
* - title: The title of the feed (as set in the view).
* - description: The feed description (from feed settings).
* - langcode: The language encoding.
* - channel_elements: The formatted channel elements.
* - items: The feed items themselves.
*
* @see template_preprocess_views_view_rss()
*
* @ingroup themeable
*/
#}
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="{{ link }}"{{ namespaces }}>
<channel>
<title>{{ title }}</title>
<link>{{ link }}</link>
<description>{{ description }}</description>
<language>{{ langcode }}</language>
{##
# Output the channel elements as a raw tag so that the included HTML tags
# are not converted to HTML entities. Also rename the "imagelink" tag to
# just "link" to avoid it being filtered out by Drupal's normal rendering
# system. This is safe to do as any security concerns are taken care of
# by the render function.
#}
{{ channel_elements|render|replace({"imagelink": "link"})|raw }}
{{ items }}
</channel>
</rss>
......@@ -189,8 +189,7 @@ class DisplayFeedTest extends BrowserTestBase {
// $this->assertEquals($site_image_url, $driver->getText('//rss/channel/image/url'));
$this->assertEquals('https://www.drupal.org/misc/druplicon.png', $driver->getText('//rss/channel/image/url'));
$this->assertEquals('Test feed', $driver->getText('//rss/channel/image/title'));
// @todo This should be the main site URL.
// $this->assertEquals('', $driver->getText('//rss/channel/image/link'));
$this->assertEquals($front_page, $driver->getText('//rss/channel/image/link'));
// @todo Work out a better approach for this.
// $this->assertEquals('', $driver->getText('//rss/channel/image/width'));
// $this->assertEquals('', $driver->getText('//rss/channel/image/height'));
......
......
......@@ -169,10 +169,15 @@ function views_rss_map_assoc($array) {
* Implemenents hook_theme_registry_alter().
*/
function views_rss_theme_registry_alter(array &$registry) {
$module_dir = \Drupal::service('extension.list.module')->getPath('views_rss');
// Use the twig file that comes with this module so that the CDATA wrapper can
// be added.
$module_dir = \Drupal::service('extension.list.module')->getPath('views_rss');
$registry['views_view_row_rss']['path'] = $module_dir . '/templates';
// Use the custom twig file for the main RSS output to work around problems
// outputting a LINK tag in Twig.
$registry['views_view_rss']['path'] = $module_dir . '/templates';
}
/**
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment