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:
- Install Drupal 8 with the standard profile.
- Add a file field to the article content type.
- Create an article with a file in the file field.
- Visit
rss.xml
. The file is displayed as a plain link. - 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><div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>Teeeeeeeeeeeeeeeeeest</p>
</div></div></div></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>
Remaining tasks
None
User interface changes
'RSS enclosure' added to Display Format of File Types
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.
Comment | File | Size | Author |
---|---|---|---|
#58 | screenshot.rss_.enclosure.test.1.png | 39.07 KB | Pere Orga |
#58 | screenshot.rss_.enclosure.test.2.png | 29.35 KB | Pere Orga |
#47 | rss-feed-enclosure-backport-test-666412-47.patch | 4.12 KB | Pere Orga |
#46 | rss-feed-enclosure-backport-666412-46.patch | 1.18 KB | Pere Orga |
#39 | plain_link.png | 5.54 KB | xjm |
Comments
Comment #1
mfbIdeally 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...
Comment #2
mfbThat is to say, RSS view mode :)
Comment #4
ao2 CreditAttribution: ao2 commentedsubscribing
Comment #5
retester2010 CreditAttribution: retester2010 commented#1: enclosure.patch queued for re-testing.
Comment #6
bjaspan CreditAttribution: bjaspan commentedsubscribe
Comment #7
Anonymous (not verified) CreditAttribution: Anonymous commentedNobody referenced #872488: Regression: no way to get taxonomy tags into RSS feeds here yet. Hopefully these issues have a common solution. (subscribe)
Comment #8
mfbMy 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.Comment #9
andypostSuppose view-mode should be inherited from entity to field. What rss-formatter means while entity viewed in search-resulot mode?
Comment #10
Anonymous (not verified) CreditAttribution: Anonymous commentedI'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.
Comment #11
pwolanin CreditAttribution: pwolanin commentedSeems like a bug (regression) to me.
Comment #12
Anonymous (not verified) CreditAttribution: Anonymous commentedSheesh. 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.
Comment #13
David_Rothstein CreditAttribution: David_Rothstein commentedFixing the priority.
Comment #14
mfb#1: enclosure.patch queued for re-testing.
Comment #15
mfbI 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.
Comment #16
mfbok here's a contrib module to restore this feature: http://drupal.org/project/rss_field_formatters
Comment #17
sunSince there's a contrib workaround, demoting to normal.
Comment #18
acouch CreditAttribution: acouch commentedWorking on a reroll and test for this.
Comment #19
xjmComment #20
xjmComponent change is due to a d.o bug; we can change it back once file.module exists again. :)
Comment #21
tayzlor CreditAttribution: tayzlor commentedRe-rolled patch for git against d8, which probably wont work as $object doenst exist? investigating..
Comment #22
tayzlor CreditAttribution: tayzlor commentedNew patch attached which uses $entity, which now formats the RSS properly. working on tests...
Comment #23
tayzlor CreditAttribution: tayzlor commentedUploading new patch, which includes a test, to test that the RSS enclosure is displayed properly inside the RSS feed.
Comment #24
tayzlor CreditAttribution: tayzlor commentedUploading separate patch file, with just the test in it.
Comment #25
aspilicious CreditAttribution: aspilicious commentedThe test is green. Does this mean that the test is incorrect or that the bug is gone in d8?
Comment #26
disasm CreditAttribution: disasm commentedThanks 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:
remove trailing whitespace.
remove trailing whitespace.
remove trailing whitespace.
Comment #27
xjmThanks @tayzlor and @disasm.
Here's a couple other code style cleanups for the patch:
This comment also needs to wrap sooner; it's over 80 characters.
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.
Comment #28
jaffaralia CreditAttribution: jaffaralia commentedHere i correct code style cleanups for the patch #23
Thanks,
Jaffar
Comment #29
jaffaralia CreditAttribution: jaffaralia commentedHere i corrected code style cleanups for the patch #26 and #27
Thanks,
Jaffar
Comment #30
iflista CreditAttribution: iflista commentedReapplied patch #28 and made a test only version it. As 29 is broken.
Also included in post original patch from #28.
Comment #31
disasm CreditAttribution: disasm commentedThanks 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.
enclosure, not encloser
Comment #32
xjmLet's also clean this up so that RSS is uppercase both times.
Nice work!
Comment #33
iflista CreditAttribution: iflista commentedCleaned up things due to comments.
New patches with interdiffs are attached below.
Comment #35
disasm CreditAttribution: disasm commentedComment #35.0
willwh CreditAttribution: willwh commentedFollowing Issue Summary Template standards http://drupal.org/node/1155816
Comment #36
willwh CreditAttribution: willwh commentedTested 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 :)
Comment #36.0
willwh CreditAttribution: willwh commentedIssue Summary Template standards
Comment #36.1
willwh CreditAttribution: willwh commentedhttp://drupal.org/node/1155816 - Issue Summary Template standards
Comment #37
willwh CreditAttribution: willwh commentedComment #38
xjmThanks @willwh!
Comment #38.0
xjmOne last update per disasm / zendoodles
Comment #39
xjmThe STR in the summary didn't quite tell me the whole story, so here's what I did to test this:
admin/structure/types/manage/article
, add a file field.node/add/article
and upload a file in the file field.rss.xml
. A plain link to the file is present.admin/structure/types/manage/article/display
, under Custom display settings, check the box for "RSS" to try to customize the display and save.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.admin/config/development/performance
. There's now an RSS enclosure option. Select that and save.rss.xml
again. The file now is rendered in an enclosure.Comment #39.0
xjmUpdated issue summary.
Comment #40
xjmUpdated the summary with some more complete STR and the sample output from @willwh.
Comment #40.0
xjmUpdated issue summary.
Comment #40.1
xjmUpdated issue summary.
Comment #40.2
xjmUpdated issue summary.
Comment #41
Dries CreditAttribution: Dries commentedThis looks good to me.
Comment #42
webchickMe too! Thanks for the fix, and the tests. :)
Committed and pushed to 8.x.
Comment #43
webchickOopsie.
And no idea why that tag got removed. d.o has been a bit funky lately.
Comment #44
mfbBy 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.. :)Comment #45
xjmI think a followup feature request to extend the formatter to image fields would be worthwhile.
Comment #46
Pere OrgaThe same fix applies to Drupal 7 as well, I'm attaching the patch.
I'll try to backport the tests.
Comment #47
Pere OrgaI'm attaching the patch, and now tests are included.
Comment #49
Pere OrgaI think tests are OK, failed in #35 too.
Comment #51
xjmThe 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.
Comment #52
Pere Orga#33: rss-feed-enclosure-666412-33.patch queued for re-testing.
Comment #53
Pere OrgaComment #54
xjm@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!
Comment #55
Pere OrgaYes, I'm looking at it right now. Thanks.
Comment #56
Pere OrgaThe test passed in my machine (the day that uploaded the patch, and today). I've also checked the output of the test manually, and:
includes:
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?
Comment #57
xjm@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.Comment #58
Pere OrgaThanks 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.
Comment #59
Pere OrgaComment #59.0
Pere OrgaUpdated issue summary.
Comment #62
Wim LeersThis was committed back in #42. In #43, it was moved to . 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.
Comment #64
idebr CreditAttribution: idebr at ezCompany commentedComment #65
james.williams CreditAttribution: james.williams at ComputerMinds commentedWay back in comment 45, xjm said
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.