Problem/Motivation
template_preprocess_views_view_rss() has the following line:
$variables['channel_elements'] = \Drupal::service('renderer')->render($style->channel_elements);
The channel elements are then printed in views-view-rss.html.twig:
<rss version="2.0" xml:base="{{ link }}"{{ namespaces }}>
<channel>
<title>{{ title }}</title>
<link>{{ link }}</link>
<description>{{ description }}</description>
<language>{{ langcode }}</language>
{{ channel_elements }}
{{ items }}
</channel>
</rss>
By forcing the {{ channel_elements }} to render early, its contents can no longer be changed by other modules. The Views RSS module for example extends the channel elements with more elements from the RSS spec: http://www.rssboard.org/rss-profile
This module now has to re-render the channel elements with the updated channel elements.
Proposed resolution
Remove early rendering of RSS channel elements in template_preprocess_views_view_rss() so other modules can add channel elements without having to re-render.
Remaining tasks
- Write a patch
- Review
- Commit
User interface changes
None.
API changes
{{ channel_elements }} in views-view-rss.html.twig now is a renderable array instead of rendered markup.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | 3070978-14.patch | 3.12 KB | idebr |
Comments
Comment #2
idebr commentedComment #3
idebr commentedAttached patch removes early rendering of RSS channel elements in template_preprocess_views_view_rss() so other modules can add channel elements without having to re-render. It also provides a new views_test_rss module that provides hooks to test Views RSS output and adds test coverage for the
{{ channel_elements }}.Comment #5
lendudeThis change makes sense and nice to see test coverage added for this.
Dug a little into the 'why' of this, because the added early rendering makes little sense to me, so this may have been done for a reason. But the only explanation I could find was 'legacy code'. This is old code that hasn't been touched since Views was added to core other then updating some function calls to service calls.
Comment #6
idebr commentedReroll after #3070620: RSS <channel><link> element must refer to the website URL instead of the request URL was committed.
Comment #8
lendudeReroll looks good, back to RTBC
Comment #14
idebr commentedReupload of #6 in an effort to reduce testbot noise.
Comment #15
wim leersNice simplification :) And one fewer call to
\Drupal::service('renderer')->render()too! 🥳Comment #16
larowlanAdded a change record for those who're doing something like str_replace or re-rendering https://www.drupal.org/node/3074409
Comment #17
larowlanCommitted 5938132 and pushed to 8.8.x. Thanks!
Published the change record