Problem/Motivation

There is currently no support for the RSS enclosure element for content types in Drupal 8 core. Enclosures were supported in Drupal 4.6 through D6.

In RSS, the <enclosure> element allows a media file to be included with an item:

<enclosure url="http://dev.willskills.com/drupal/sites/default/files/woof.txt" length="20" type="text/plain" />

To reproduce:

  1. Install Drupal 8 with the standard profile.
  2. Add a file field to the article content type.
  3. Create an article with a file in the file field.
  4. Visit rss.xml. The file is displayed as a plain link.
  5. Go to "Manage display" for the article content type, enable custom display settings for the RSS view mode (collapsed fieldset), and then try to customize the display of the file field. There's no way to render it as an enclosure.

Proposed resolution

Add file field formatter that generates RSS enclosure elements. Sample output:

<item>
 <title>Test Test</title>
 <link>http://dev.willskills.com/drupal/node/1</link>
 <description>&lt;div  class=&quot;field field-name-body field-type-text-with-summary field-label-hidden&quot;&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot; property=&quot;content:encoded&quot;&gt;&lt;p&gt;Teeeeeeeeeeeeeeeeeest&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
 <pubDate>Wed, 10 Oct 2012 16:48:31 +0000</pubDate>
 <dc:creator>willwh</dc:creator>
 <guid isPermaLink="false">1 at http://dev.willskills.com/drupal</guid>
 <enclosure url="http://dev.willskills.com/drupal/sites/default/files/woof.txt" length="20" type="text/plain" />
 <comments>http://dev.willskills.com/drupal/node/1#comments</comments>
</item>

RSS feed

Remaining tasks

None

User interface changes

'RSS enclosure' added to Display Format of File Types

Enclosure option

Original report by mfb

Core has supported the RSS enclosure element since Drupal 4.6 via Upload module hook_nodeapi() implementation. This has allowed Drupal sites to syndicate media to various apps and sites (iTunes, Miro, Odeo, etc.) out of the box. Now that Upload module has been axed we should try to restore this feature to core, for example, via a file field formatter that generates RSS enclosure elements.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mfb’s picture

Status: Active » Needs review
FileSize
1.41 KB

Ideally this field formatter would only apply to RSS build mode(s). And ideally this would be the default format for RSS build mode. But I'm not yet sure how to do this...

mfb’s picture

That is to say, RSS view mode :)

ao2’s picture

subscribing

retester2010’s picture

#1: enclosure.patch queued for re-testing.

bjaspan’s picture

subscribe

Anonymous’s picture

Nobody referenced #872488: Regression: no way to get taxonomy tags into RSS feeds here yet. Hopefully these issues have a common solution. (subscribe)

mfb’s picture

My thought is that contrib modules could define additional view modes that output RSS, in addition to the built-in rss view mode. So, we'd want to have each view mode indicate its output format -- HTML, RSS, plain text, etc., -- and each field formatter indicate which ouput format it supports. This would allow us to add a field formatter that can only be selected for RSS view modes. Also, modules should be able to define a default_formatter for each output format, so in this case the RSS enclosure formatter would be enabled by default for any RSS view modes.

andypost’s picture

Suppose view-mode should be inherited from entity to field. What rss-formatter means while entity viewed in search-resulot mode?

Anonymous’s picture

I've been looking at format_xml_elements() today, and I glanced over node_feed(), format_rss_channel(), and format_rss_item(). What stands out is that format_xml_elements() renders an array, but it's not a drupal_render-able array.

The structure of this array when dealing with a large document is hard to grok and falls when handling XML nodes that are not XML elements (nodes such as comments, CDATA, etc.).

If format_xml_elements() were refactored to handle renderable arrays, field formatters and alter hooks could be used to intervene in the rendering of RSS XML.

Forgive me if this is naïve. I admit it doesn't look like a simple fix.

pwolanin’s picture

Title: Restore RSS feed enclosure support in core » Regression: RSS feed enclosure support lost from core
Category: task » bug

Seems like a bug (regression) to me.

Anonymous’s picture

Sheesh. I'm sorry. I was looking at node_feed in Drupal 6 again. Drupal 7 is already doing something quite along the lines of what I was imagining.

David_Rothstein’s picture

Priority: Normal » Major

Fixing the priority.

mfb’s picture

#1: enclosure.patch queued for re-testing.

mfb’s picture

I made a tiny module, which is more-or-less just this patch, to restore this functionality for a site. I could add it to d.o. if there's no movement on this issue.

mfb’s picture

ok here's a contrib module to restore this feature: http://drupal.org/project/rss_field_formatters

sun’s picture

Version: 7.x-dev » 8.x-dev
Priority: Major » Normal
Issue tags: +Regression, +Needs backport to D7

Since there's a contrib workaround, demoting to normal.

acouch’s picture

Assigned: Unassigned » acouch

Working on a reroll and test for this.

xjm’s picture

Component: file.module » search.module
Assigned: acouch » Unassigned
xjm’s picture

Issue tags: +Needs tests

Component change is due to a d.o bug; we can change it back once file.module exists again. :)

tayzlor’s picture

Re-rolled patch for git against d8, which probably wont work as $object doenst exist? investigating..

tayzlor’s picture

New patch attached which uses $entity, which now formats the RSS properly. working on tests...

tayzlor’s picture

Uploading new patch, which includes a test, to test that the RSS enclosure is displayed properly inside the RSS feed.

tayzlor’s picture

Uploading separate patch file, with just the test in it.

aspilicious’s picture

The test is green. Does this mean that the test is incorrect or that the bug is gone in d8?

disasm’s picture

Status: Needs review » Needs work

Thanks for the reroll and the tests tayzlor. I haven't looked at why the test without the patch is green, as aspilicious alluded to in #25, but in the mean time, here's some minor cleanups:

+++ b/core/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php
@@ -0,0 +1,78 @@
+    ¶

remove trailing whitespace.

+++ b/core/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php
@@ -0,0 +1,78 @@
+    ¶

remove trailing whitespace.

+++ b/core/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php
@@ -0,0 +1,78 @@
+    ¶

remove trailing whitespace.

xjm’s picture

Component: search.module » file.module
Issue tags: +Needs issue summary update, +Needs manual testing, +Needs steps to reproduce

Thanks @tayzlor and @disasm.

Here's a couple other code style cleanups for the patch:

+++ b/core/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.phpundefined
@@ -0,0 +1,78 @@
+    // Create a new node with a file field set. Promote to frontpage needs to be set
+    // so this node will appear in the RSS feed.

This comment also needs to wrap sooner; it's over 80 characters.

+++ b/core/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.phpundefined
@@ -0,0 +1,78 @@
+    $this->assertRaw(format_xml_elements(array($test_element)), 'File field RSS enclosure is displayed when viewing the rss feed.');

RSS should also be capitalized both places here.

Next we need to figure out why the test isn't failing. Tagging for manual testing to determine how the existing patch affects the feed. Let's also clearly document the steps to reproduce this issue, including samples of the before-and-after markup for the feed, and add this information to an issue summary.

Also correcting the component now that the list is fixed.

jaffaralia’s picture

Status: Needs work » Needs review
FileSize
4.2 KB

Here i correct code style cleanups for the patch #23

Thanks,
Jaffar

jaffaralia’s picture

Here i corrected code style cleanups for the patch #26 and #27

Thanks,
Jaffar

iflista’s picture

Reapplied patch #28 and made a test only version it. As 29 is broken.
Also included in post original patch from #28.

disasm’s picture

Assigned: iflista » Unassigned
Status: Needs review » Needs work

Thanks iflista for getting these patches organized. I think we can finally say with certainty that the problem exists, the test detects it, and the patch fixes it. One minor word change in a doc string and I'll RTBC this.

+++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php
@@ -0,0 +1,78 @@
+   * Tests RSS encloser formatter display for RSS feeds.

enclosure, not encloser

xjm’s picture

Issue tags: -Needs tests
+++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.phpundefined
@@ -0,0 +1,78 @@
+    // Check that the rss enclosure appears in the RSS feed.

Let's also clean this up so that RSS is uppercase both times.

Nice work!

iflista’s picture

Assigned: Unassigned » iflista
Status: Needs work » Needs review
FileSize
3.13 KB
3 KB
1.17 KB
4.2 KB

Cleaned up things due to comments.
New patches with interdiffs are attached below.

Status: Needs review » Needs work

The last submitted patch, rss-feed-enclosure-test-only-666412-33.patch, failed testing.

disasm’s picture

Status: Needs work » Needs review
willwh’s picture

Issue summary: View changes

Following Issue Summary Template standards http://drupal.org/node/1155816

willwh’s picture

Tested on a fresh drupal 8 install, without patch - no way to add enclosure element.

Patched applied and tested manually - works as the steps in the Issue Description

Here's a dump from RSS.xml :)

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://dev.willskills.com/drupal"  xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>d8</title>
 <link>http://dev.willskills.com/drupal</link>
 <description>dev.drupal8</description>
 <language>en</language>
<item>
 <title>Test Test</title>
 <link>http://dev.willskills.com/drupal/node/1</link>
 <description>&lt;div  class=&quot;field field-name-body field-type-text-with-summary field-label-hidden&quot;&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot; property=&quot;content:encoded&quot;&gt;&lt;p&gt;Teeeeeeeeeeeeeeeeeest&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
 <pubDate>Wed, 10 Oct 2012 16:48:31 +0000</pubDate>
 <dc:creator>willwh</dc:creator>
 <guid isPermaLink="false">1 at http://dev.willskills.com/drupal</guid>
 <enclosure url="http://dev.willskills.com/drupal/sites/default/files/woof.txt" length="20" type="text/plain" />
 <comments>http://dev.willskills.com/drupal/node/1#comments</comments>
</item>
</channel>
</rss>
willwh’s picture

Issue summary: View changes

Issue Summary Template standards

willwh’s picture

Issue summary: View changes

http://drupal.org/node/1155816 - Issue Summary Template standards

willwh’s picture

Status: Needs review » Reviewed & tested by the community
xjm’s picture

Thanks @willwh!

xjm’s picture

Issue summary: View changes

One last update per disasm / zendoodles

xjm’s picture

FileSize
6.46 KB
11.47 KB
5.54 KB

The STR in the summary didn't quite tell me the whole story, so here's what I did to test this:

  1. Install Drupal 8 with the standard profile.
  2. At admin/structure/types/manage/article, add a file field.
  3. Create a new article at node/add/article and upload a file in the file field.
  4. Visit rss.xml. A plain link to the file is present.
    plain_link.png
  5. At admin/structure/types/manage/article/display, under Custom display settings, check the box for "RSS" to try to customize the display and save.
  6. Go to admin/structure/types/manage/article/display/rss and attempt to customize the display of the file field for the RSS view mode. There is no way to customize the output to use an enclosure.
  7. Apply the patch from #33.
  8. Clear the site cache at admin/config/development/performance. There's now an RSS enclosure option. Select that and save.
    enclosure_option.png
  9. Visit rss.xml again. The file now is rendered in an enclosure.
    enclosure.png
xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Updated the summary with some more complete STR and the sample output from @willwh.

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Issue summary: View changes

Updated issue summary.

Dries’s picture

This looks good to me.

webchick’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Regression

Me too! Thanks for the fix, and the tests. :)

Committed and pushed to 8.x.

webchick’s picture

Version: 8.x-dev » 7.x-dev
Status: Fixed » Patch (to be ported)

Oopsie.

And no idea why that tag got removed. d.o has been a bit funky lately.

mfb’s picture

By the way, RSS field formatters contrib module also allows image fields to render as <enclosure> tags. But probably fine for this functionality to be provided by contrib.. :)

xjm’s picture

I think a followup feature request to extend the formatter to image fields would be worthwhile.

Pere Orga’s picture

The same fix applies to Drupal 7 as well, I'm attaching the patch.
I'll try to backport the tests.

Pere Orga’s picture

Status: Patch (to be ported) » Needs review
FileSize
4.12 KB

I'm attaching the patch, and now tests are included.

Status: Needs review » Needs work

The last submitted patch, rss-feed-enclosure-backport-test-666412-47.patch, failed testing.

Pere Orga’s picture

Status: Needs work » Needs review

I think tests are OK, failed in #35 too.

Status: Needs review » Needs work

The last submitted patch, rss-feed-enclosure-backport-test-666412-47.patch, failed testing.

xjm’s picture

The failure in #35 was from the test-only patch that does not include the bugfix, so it was expected that it would fail. #47 is supposed to be a complete patch including the fix, so the fact that the test is failing is a problem. I'd suggest testing the patch manually and also running the test locally to determine why it is failing.

Pere Orga’s picture

Status: Needs work » Needs review

#33: rss-feed-enclosure-666412-33.patch queued for re-testing.

Pere Orga’s picture

Status: Needs review » Needs work
xjm’s picture

@netol, if you click the "view details" link next to the patch, it shows that the failure is:
File field RSS enclosure is displayed when viewing the RSS feed.

This isn't a random failure that will go away with a retest; it's a part of this issue. So either the patch does not actually work, or the code of the test is bugged. So, some local testing and debugging should be done to determine which it is. Thanks everyone!

Pere Orga’s picture

Yes, I'm looking at it right now. Thanks.

Pere Orga’s picture

Status: Needs work » Needs review

The test passed in my machine (the day that uploaded the patch, and today). I've also checked the output of the test manually, and:

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://localhost/git/drupal"  xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>Drupal</title>
 <link>http://localhost/git/drupal</link>
 <description></description>
 <language>en</language>
<item>
 <title>wVxZTRlX</title>
 <link>http://localhost/git/drupal/node/1</link>
 <description>&lt;div class=&quot;field field-name-body field-type-text-with-summary field-label-hidden&quot;&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot; property=&quot;content:encoded&quot;&gt;&lt;p&gt;tAPewfvhIkj6qmtzxU4CDsRwAIEFoK7q&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
 <pubDate>Fri, 02 Nov 2012 22:25:11 +0000</pubDate>
 <dc:creator>kKo8G61i</dc:creator>
 <guid isPermaLink="false">1 at http://localhost/git/drupal</guid>
 <enclosure url="http://localhost/git/drupal/sites/default/files/simpletest/523225/text-0_0.txt" length="1024" type="text/plain" />
 <comments>http://localhost/git/drupal/node/1#comments</comments>
</item>
</channel>
</rss>

includes:

<enclosure url="http://localhost/git/drupal/sites/default/files/simpletest/523225/text-0_0.txt" length="1024" type="text/plain" />

So I don't see why assertRaw() fails in http://qa.drupal.org/
How can I run exactly the same tests that qa.drupal.org is running?

xjm’s picture

@netol, the tests that qa.drupal.org is running are the tests included in Drupal core, and the one that is failing is the one included in the patch you created. To run them locally, enable the testing module and go to admin/config/development/testing. All the tests in the test suite are listed there. See http://drupal.org/node/519364 for more information.

Pere Orga’s picture

Thanks for your support, but I've run the same test multiple times. I did it before uploading the patch. I'm attaching screenshots...

My question is, why the same test passes successfully in my machine and not in qa.drupal.org ?

It's obvious that I'm doing something wrong, but I can't see what.

Pere Orga’s picture

Status: Needs review » Needs work
Pere Orga’s picture

Issue summary: View changes

Updated issue summary.

  • webchick committed 8dc0f01 on 8.3.x
    Issue #666412 by tayzlor, jaffaralia, iflista, mfb, xjm: Fixed...

  • webchick committed 8dc0f01 on 8.3.x
    Issue #666412 by tayzlor, jaffaralia, iflista, mfb, xjm: Fixed...
Wim Leers’s picture

Status: Needs work » Fixed
Issue tags: -

This was committed back in #42. In #43, it was moved to patch to be ported. It was not ported in the past 4 years.

Also, since then, we've changed the policy for this: if this should be backported to Drupal 7, it'll need a separate issue.

So, moving back to #42's issue state.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

idebr’s picture

Version: 7.x-dev » 8.3.x-dev
james.williams’s picture

Way back in comment 45, xjm said

I think a followup feature request to extend the formatter to image fields would be worthwhile.

I don't see any follow-up, and the functionality is still missing, so I've raised #3150318: Support image fields in RSS enclosure formatter :-) Sorry to update such an old issue but I figure anyone investigating this might find themselves here, just as I did.