Needs work
Project:
Drupal core
Version:
main
Component:
views.module
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
25 Jun 2015 at 09:13 UTC
Updated:
10 Aug 2026 at 20:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
dawehnerInteresting, following the issue ...
Comment #6
grasmash commentedComment #7
ekes commentedSo the first thing I try is a related entity (because my immediate use case is a media entity referenced by an node).
In this case the code doesn't work as the entity is in the _relationship_objects rather than _entity.
So I'm wondering is it best to write a specific RSS Formatter for Files that could be selected so that getField could be used like the other rows?
Edit 1: There is one Drupal\file\Plugin\Field\FieldFormatter\RSSEnclosureFormatter admittedly it doesn't apply it images, but..
Edit 2: But it tucks its render away on the entity, which just might be used in rss row node magic, but nowhere else. I can't see how it'd be able to be accessed from the row plugin. I'm guessing it can't be passed through normal rendering. So that leaves? (i) working out if it is _entity or _relationship_objects here (ii) changing rendering so that it handle non-html (!?) (iii) getting access to the entity rendered rss element some other way?
Comment #10
drup16 commentedI tested the patch from #6 and it is working when adding an Image field.
Question remains:
Fields, we can set the Image Style. Is the purpose of this patch only to add the<enclosure>tag without considering theImage Style?Comment #12
quixxel commentedPatch #6 isn't working for me.
I want to attach an image.
In field settings I choose image ( and tried all of image styles)
The preview result shows no
<enclosure>Only:
<item><title><link><description><pubDate><dc:creator><guid isPermaLink="false">And all Feedreaders are showing an error (The website encountered an unexpected error....)
Dblog:
Error: Call to a member function getFileUri() on null in Drupal\views\Plugin\views\row\RssFields->render() (Zeile 180 in ...my-url/docroot/core/modules/views/src/Plugin/views/row/RssFields.php) #0 ...my-url/docroot/core/modules/views/src/Plugin/views/style/Rss.php(121): Drupal\views\Plugin\views\row\RssFields->render(Object(Drupal\views\ResultRow)) #1 ...my-url/docroot/core/modules/views/src/Plugin/views/display/Feed.php(106): Drupal\views\Plugin\views\style\Rss->render(Array) #2 ...my-url/docroot/core/modules/views/src/ViewExecutable.php(1533): Drupal\views\Plugin\views\display\Feed->render() #3 ...my-url/docroot/core/modules/views/src/Plugin/views/display/Feed.php(82): Drupal\views\ViewExecutable->render() #4 ...my-url/docroot/core/modules/views/src/ViewExecutable.php(1630): Drupal\views\Plugin\views\display\Feed->execute() #5 ...my-url/docroot/core/modules/views/src/Element/View.php(77): Drupal\views\ViewExecutable->executeDisplay('feed_1', Array) #6 [internal function]: Drupal\views\Element\View::preRenderViewElement(Array) #7 ...my-url/docroot/core/lib/Drupal/Core/Render/Renderer.php(378): call_user_func(Array, Array) #8 ...my-url/docroot/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, true) #9 ...my-url/docroot/core/lib/Drupal/Core/Render/Renderer.php(139): Drupal\Core\Render\Renderer->render(Array, true) #10 ...my-url/docroot/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() #11 ...my-url/docroot/core/lib/Drupal/Core/Render/Renderer.php(140): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #12 ...my-url/docroot/core/modules/views/src/Plugin/views/display/Feed.php(63): Drupal\Core\Render\Renderer->renderRoot(Array) #13 ...my-url/docroot/core/modules/views/src/Routing/ViewPageController.php(52): Drupal\views\Plugin\views\display\Feed::buildResponse('5c_3d_druck_pro...', 'feed_1', Array) #14 [internal function]: Drupal\views\Routing\ViewPageController->handle('5c_3d_druck_pro...', 'feed_1', Object(Drupal\Core\Routing\RouteMatch)) #15 ...my-url/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #16 ...my-url/docroot/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #17 ...my-url/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #18 ...my-url/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #19 ...my-url/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #20 ...my-url/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #21 ...my-url/docroot/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #22 ...my-url/docroot/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #23 ...my-url/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(184): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #24 ...my-url/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(121): Drupal\page_cache\StackMiddleware\PageCache->fetch(Object(Symfony\Component\HttpFoundation\Request), 1, true) #25 ...my-url/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(75): Drupal\page_cache\StackMiddleware\PageCache->lookup(Object(Symfony\Component\HttpFoundation\Request), 1, true) #26 ...my-url/docroot/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #27 ...my-url/docroot/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #28 ...my-url/docroot/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #29 ...my-url/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #30 ...my-url/docroot/core/lib/Drupal/Core/DrupalKernel.php(693): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #31 ...my-url/docroot/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #32 {main}.
Comment #13
drup16 commented@quixxel it could be that one of your nodes does not have the image field set. Look at your error message
Error: Call to a member function getFileUri() on null in, it alludes to needing a validation to make sure$fileis set.Comment #14
drup16 commentedComment #15
quixxel commentedThxx @drup16 !
Patch works for me.
Comment #16
BarisW commentedHi drup16,
This works for attachments, such as pdf's. However, when trying to attach a thumbnail image to an rss item, I found that the patch ignores the field settings (such as image style) and just outputs the url to the full file. This leads to attaching 20MB images to RSS items, and thus crashing RSS readers such as Outlook.
I've attached a patch that takes image style settings into account. Not sure if this is the best way to do it, but it seems to work.
Comment #17
BarisW commentedMy bad, I switched the filesize and mimetype attributes.
Comment #18
drup16 commentedHi @BarisW,
I am not sure where you got the
PDFsfrom, but this was for addingImagesto the feed. In my original comment in #10, I had asked the question if the purpose was to serve up the original image or the image url based on the image style, but i never got a response.I will see if I can test your patch soon and provide the feedback.
Comment #19
lendudeThanks for working on this.
This now only allows one 'enclosure' field per feed, does that make sense in RSS? (I'm asking, no idea really)
Wouldn't it be better if we can validate this somehow? Maybe limit the options to the allowed fields only and add validation?
Lets not use setters inside if(), also this needs a space after the if
We should inject this
comment > 80 characters
Also, this needs tests.
Comment #20
christian le fournis commentedCan we allow media field entity to be used as enclosure? Looks like this patch works great for file only.
Comment #21
attheshow commentedI was also trying to use the patch to allow enclosure of a media item and couldn't get it to work.
Comment #23
jacobbell84 commentedI had a need for media support as well, so I put some work into this patch. In my testing it now supports the media field type and, if you choose a formatter that supports image styles, it will honor those as well.
I've also addressed 3 & 4 of Lendude's feedback. Concerning #1, I think allowing only one option is OK. I checked the RSS Advisory Board and it states that the author of the enclosure tag intended it to only allow one image per item tag. Some aggregators support more then one, but some don't, so to get the widest compatibility we might as well stick with the specification. For #2, I agree some validation would be nice but I'm thinking that should be another ticket since none of the fields are currently validating anything. If we're going to address it for this one we might as well look at them all. For #5, I'm not seeing what you're referring to. In my editors the comments are showing as <= 80 characters for each line, which seems inline with the standards I've seen posted.
I went ahead and modified the original post to add unit tests to the remaining tasks. If anyone needs it, I also added an 8.7 backport of the patch.
Comment #24
lendudeJust some nits to pick:
Better to use the getEntity method here that also takes any relationships into account.:
And getEntity() can return NULL so that also has to be taken into account.
We have the entity type manager injected, why not use it instead of a direct call to File::load
sizeOf -> count
== can be ===
But yeah, this needs tests above all.
Comment #25
rapindrive commentedThe patch works correctly but I need to attach the file as media. The patch of @jacobbell84 #24 would be magnificent, the problem is that I am with version 8.6.x
Comment #26
jacobbell84 commentedHi @rapindrive, it doesn't look like the file we're patching changed at all between 8.6 and 8.7, so the 8.7 patch should still work for you.
Comment #27
swetaranjan commentedI have applied patch views-rss-fields-enclosure-2511878-23_87.patch. However While adding media field via media relationship to enclosure tag, tag disappears from the page source. Any help on it would be appreciated.
Comment #28
zyla commentedPatch #23 works fine for me with Drupal 8.8.1. Thank you !
Comment #30
adevms commentedI have applied patch 23, but because i have entity reference field to a paragraph which contains an image, it was not injecting the enclosure element in the feed.
I'm using D8.9.1.
I have made the changes from #24 and it's inserting the image in the enclosure element.
Below is the patch for it.
Comment #31
playful commentedPatch #30 working well for me on D8.9.7. Thanks!
Comment #33
jacobbell84 commentedComment #35
mschudders commentedPatch against D9.2
Works properly.
Only change vs patch #30 is that:
There is a check if the FileFieldItemList contains any value. Otherwise the code will throw a FATAL.
Comment #36
xamountPatch at #30 works for me on 8.9.16. Thanks very much!
Comment #41
karishmaamin commentedPatch #35 works in D9.2, here is the patch that removes custom code error in #35
Comment #42
karishmaamin commentedPatch #35 works in D9.2, here is the patch that removes custom code error in #35
Comment #44
mirondi commentedAdding patch with alt tag included.
Comment #45
mirondi commentedComment #46
askibinski commentedAccording to official RSS specs the enclosure tag does not support alt-tags:
https://validator.w3.org/feed/docs/rss2.html
Then there also is the `` tag which seems to be popular used to add an image to ``.
https://www.rssboard.org/media-rss#media-content
But that one also does not support alt-tags.
In fact, as far as I know, there is no way according to any spec to add an image to an item (not channel) with an alt-tag :(
Comment #47
mirondi commentedComment #48
jor_kai commentedGreat work on this. Using it in my view with no issues so far. I'm using media for my image and have the field configured like the following.
Formatter: Thumbnail
Image style: My image style
Link image to: Media item
Comment #49
liliplanet commentedOh thank you so much! Patch #42 works perfectly, most appreciated.
Comment #50
bartlangelaanThe patch from #42 is missing a config schema for the new configuration. This should be added, to make sure the config schema is correct.
Comment #52
bartlangelaanThis is the same patch as #42, but with the config schema extended to include the new option.
Comment #54
nsciaccaWorking for me on 9.4.8 with a media field configured to use a specific image style - thanks!
Comment #55
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #56
pooja saraah commentedFixed failed commands on #52
Attached patch against Drupal 10.1.x
Comment #57
kakoum commentedGot this error "Call to undefined function Drupal\views\Plugin\views\row\file_create_url()" :'( file_create_url depreciated in drupal 10.0
Comment #59
navneet0693 commentedComment #60
smustgrave commentedFor the CC failure.
Also with the schema change will need an upgrade path.
Thanks.
Comment #62
parisekSeems really hard to rebase MR for current branch so closed it.
Found one issue - enclosure field is not translated we just get default language, probably we should implement EntityTranslationRenderTrait (like web/core/modules/views/src/Plugin/views/row/EntityRow.php)
Comment #63
abhijeet.kumar2107 commentedIts seems to be validation issue This feed does not validate.
line 15, column 4: url must be a full URL: http://localhost:50654/sites/default/files/2023-10/point_3.png (5 occurrences) [help]
^
Comment #64
hebl commentedI've attached a patch modified from #56 which fixes the D10 deprecation errors when using the file_create_url() method.
Works with D10.1
Comment #65
ralphvdhoudt commentedImporved patch to have correct dependency injection and better support for getAbsoluteUrl
Comment #66
ralphvdhoudt commentedAdd missing param description
Comment #67
ralphvdhoudt commentedCorrect naming
Comment #68
xamountI've tested the patch at #67 and it's working for me on D10.1.6
Comment #69
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue.
While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)
Comment #70
stefan.kornwhile patch from #67 fixes the issue and enclosure tag with image can be provided, there are no such things possible for the enclosure field as rewriting results or no results behavior.
I was in need to provide a second field as a fallback for the enclosure in case the first field is empty.
I have therefore amended the patch to optionally configure a second enclosure field as fallback.
I do not want to endorse this as a clean solution, so I am hiding the patch, but provide it here in case someone might be in need of something similar and also to remind us, that maybe more flexibility with enclosure field would be great.
Comment #71
cedeweyThanks stefan for your latest patch and thoughts. It sounds like we need to make a decision on whether the current patch is acceptable or if an approach inspired by yours that is more flexible needs to be done.
Personally, I am ok with the simpler, existing approach but defer to the Views maintainers and broader community.
I've updated the remaining tasks section with my understanding of where to go from here.
Comment #72
cedeweyComment #75
kekkisComment #76
kekkisI have now created two new branches, one based on 11.x and another on 10.2.x. Attaching patch for 10.2.x too (applies cleanly to 10.1.x as well). Leaving as NW since I haven't (yet) had time to add tests.
I made the choice to continue work on the patch at #70 instead of #67 since it seemed to be the more complete solution.
Comment #82
gfbarbosa commentedI created a new updated branch for 10.3.x with previous commits from #76.
Comment #83
timohuismanAdded "Needs subsystem maintainer review" based on the summary and #70
Comment #84
lendudeIn my opinion we shouldn't provide a fallback field, it's not like we provide one for any of the other fields, right? So I would opt to keep this as simple as possible and just stick to one field
Just my opinion, so feel free to ignore, but consider this reviewed by a subsystem maintainer
Comment #85
timohuismanAlright, agreed.
I've removed the fallback alt option from #82 and created a new patch for 10.3. If this is the satisfied approach I can also updated the existing MR's or create new ones. Not sure whats where the right approach because if the existing MR's are updated the fallback functionality is removed and some people could depend on them.
Comment #86
timohuismanComment #87
matt b@timohuisman's page (#85) works for me. Thank you.
Comment #88
ckhaliloI get this error Warning: Undefined array key 0 in Drupal\\views\\Plugin\\views\\row\\RssFields->render() (line 264 of /var/www/docroot/core/modules/views/src/Plugin/views/row/RssFields.php)
May be we can add reset the array of $enclosure->referencedEntities() to get the first one
Comment #89
ckhalilohere the new patch
Comment #90
fox mulder commented[#89] causes "Only variables should be passed by reference" notice in function Drupal\views\Plugin\views\row\RssFields->render() (/.../web/core/modules/views/src/Plugin/views/row/RssFields.php line 248.)
Comment #91
rkelbel48 commentedPatch (#89) is working for me on Drupal 10.4.5.
Comment #92
mac501 commentedModified patch for D11.2
Comment #94
mmenavas commentedUpdating patch #89 with code changes suggested by Gemini, which I reviewed and tested on my Drupal 10.6.3 site.
Comment #95
jacobbell84 commentedJust a quick reroll for 11.4