Problem/Motivation
When creating a view with the page-type of Feeds, RSS Feed, and fields (vs content), the date field adds a <time> tag:
<pubDate><time datetime="2023-08-10T13:43:13-07:00" class="datetime">Thu, 10 Aug 2023 13:43:13 -0700</time></pubDate>
I've chosen "major" as this broke a bunch of our feeds, and I'd imagine it does the same for many other folks.
This also causes Planet Drupal to sometimes be flooded with a lot of old items from a feed, after the site got updated to Drupal 10, see #3399284: Prevent flooding of feeds such as Drupal Planet with old blog posts. From release Drupal 10.2.1 this should be fixed.
Steps to reproduce
- Create a view
- Create a Feed
- Add the appropriate fields (I chose Title, Body, Authored By, Authored On, Link to Content, and UUID)
- Set the format to RSS Feed
- Set Show to Fields
- Map the Field Settings to point to the appropriate fields
- The feed will have an added
<time>as illustrated above.
Thanks!
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | Screenshot 2023-10-25 at 11.43.23 AM.png | 275.46 KB | danstorm |
Issue fork drupal-3383219
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3383219-views-rss-feed
compare
- 3383219-11.x
changes, plain diff MR !5763
Comments
Comment #2
greatmatter commentedIn case anyone lands on this, our workaround is to enable "rewrite results" for the field, and use twig:
{{ created__value|date('D, d M Y H:i:s O') }}This "fixes" it.
Comment #3
lendudeThanks for posting your issue and workaround, I have some questions that might help get some work done on this.
When did this break a bunch of feeds, was this after an update? If so, which one? It might help track down what changed this. Or is this just an issue when creating any new Feed that doesn't align with how the feed should be formatted?
Also, I'm wondering, is this just using core/modules/system/templates/time.html.twig for rendering? And if so, is this a problem in Views or somewhere else?
Comment #4
greatmatter commented@lendude - It's hard to say, because I was notified by a volunteer. If I had to guess, it was around the time we updated the site to Drupal 10, but I can't be sure.
Comment #5
powysm commentedI am seeing this on my REST Export feeds after updating Drupal from 9.5.11 to 10.1.4.
I am surprised this is not better documented somewhere, if it is I haven't found it.
I worked around this by checking "Strip HTML tags" and "Remove whitespace" under "rewrite results".
Comment #6
pminfWe updated Drupal from 9.5.10 to 10.1.4 and didn't had this issue before.
@lendude The template doesn't seem to matter. The markup of all our field based feeds changed from
to
As you can see we are using a theme based on contrib stable. But the issue is also present when using the current stark theme with core/modules/system/templates/time.html.twig:
I can confirm the workaround from #5:
(Ignore the whitespaces. They are not present if theme debug is disabled.)
Comment #7
danstorm commentedWe are currently experiencing this in all of our Views Rest Exports (the ones with time fields, anyway) after upgrading from Drupal 9.5.11 to Drupal 10.1.5 and running `drush updb`. Looks like there is an update in the list that is likely the cause (highlighted text in attached screenshot).
#5 solves the issue, but since we are running headless, this affects a lot of our endpoints and is unfortunately causing a heck of a lift between identifying and manually editing all of the affected views
Comment #8
papagrandeSame problem for me--updated to D10 and RSS feeds break. And the workaround in #5 fixes it.
Based on
git blameit looks like the change was introduced in https://www.drupal.org/project/drupal/issues/2921810. Perhaps the Views RSS row formatter needs tweaking to exclude the<time>element.Comment #9
lendude#8 seems to point to the right issue, looking at the MR, this change was needed there:
to
Which would indicate that new things got added to the output there.
Comment #10
heikkiy commentedWe encountered the same issue in two projects that updated from core 9.5.11 to 10.x. We were able to hotfix this by enabling the Strip HTML tags (strip_tags) and Trim whitespace (trim_whitespace) options in the view for example for the Created field.
Comment #11
ressa@Dave Reid pointed me to this issue, which explains the occasional flooding of old blog posts on Drupal Planet. It seems to happen after an upgrade from Drupal 9 to Drupal 10.
Comment #12
ressaMarking up
<time>as code, since it is invisible otherwise :)Comment #13
hansfn commentedI guess we could apply the "fix" in comment #5 in RssFields::render. The date field doesn't have a formatter without the time element so we need to strip to get pubDate as plain text.
Comment #14
drummComment #16
lendudeStripping tags on the pubDate sounds logical, that shouldn't contain HTML
Added that as a fix and added test coverage
Comment #17
heikkiy commentedI tested the fix from #16. It seems to fix the problem and I didn't see any extra empty space either in my testing.
Probably makes sense to have a second review also and check the tests attached.
Comment #18
lendudeThe test was showing the reported whitespace, so lets trim that too
Comment #19
lendudeAdded a comment explaining why we are doing this
Comment #20
heikkiy commentedGreat! I tested it myself the following way:
1. Removed the Strip tags and trim settings mentioned #10.
2. Verified that the time tag was in back in the feed.
3. Applied the patch.
4. Verified that time tag was removed.
I didn't encounter the whitespace issue when checking the actual feed so great that it was catched by the tests. Might have been a browser feature when checking the feed.
I vote this could be marked as RTBC.
Comment #21
papagrandeLooks great! Thanks @Lendude and @HeikkiY.
Comment #23
catchCommitted/pushed to 11.x and cherry-picked to 10.2.x, thanks!
Comment #25
ressaThanks everyone! There was another surge of old posts on Drupal Planet today, but from Drupal 10.2.1 it looks like this should be fixed.