Problem/Motivation

The RSS format has the <enclosure> tag for "attaching" media to an item. It is typically used for the main image of an article or the audio file of a podcast issue.

Views has an RSS Enclosure formatter but it looks like it cannot really be used. Only the fields selected in the RssFields plugin settings form are rendered.

Proposed resolution

Add an optional "Enclosure field" option to RssFields.

Remaining tasks

  • ✅ Write patch as proof of concept for the proposed resolution
  • ✅ Get Views maintainer approval of proposed resolution (see comment #70 and review comment #84)
  • ❌ Create merge request satisfying the approved resolution
  • ❌ Community approval of merge request
  • ❌ Views maintainer approval of merge request
  • ❌ Write automated test coverage.
  • ❌ Merge the request into Drupal core
  • ❌ Celebrate the ability to properly include images in RSS feeds

User interface changes

Adds Image option in RSS fields list in Views.

API changes

Data model changes

CommentFileSizeAuthor
#95 drupal-core-2511878-95.patch8.71 KBjacobbell84
#94 interdiff_89-94.txt2.12 KBmmenavas
#94 drupal-core-2511878-94.patch8.78 KBmmenavas
#92 2511878-92-11.2.patch8.73 KBmac501
#90 2511878-90.patch9.24 KBfox mulder
#89 2511878-86-10.3.patch9.17 KBckhalilo
#85 2511878-85-10.3.patch9.11 KBtimohuisman
#82 2511878-add-support-for-enclosure-field-10.3.x.patch11.13 KBgfbarbosa
#76 2511878-add-support-for-enclosure-field-10.2.x--acdd23c.patch11.03 KBkekkis
#70 core-support-enclosure-field-rss-2511878-70_withfallback.patch10.64 KBstefan.korn
#67 core-support-enclosure-field-rss-2511878-67.patch8.62 KBralphvdhoudt
#66 core-support-enclosure-field-rss-2511878-66.patch8.61 KBralphvdhoudt
#65 core-support-enclosure-field-rss-2511878-65.patch8.51 KBralphvdhoudt
#64 core-support-enclosure-field-rss-2511878-64.patch7.65 KBhebl
#59 views-rss-fields-enclosure-2511878-59.patch9.02 KBnavneet0693
#59 interdiff--56-59.patch4.65 KBnavneet0693
#56 reroll_diff_52-56.txt1.42 KBpooja saraah
#56 2511878-56.patch7.57 KBpooja saraah
#55 2511878-nr-bot.txt2.19 KBneeds-review-queue-bot
#52 2511878-52.patch7.61 KBbartlangelaan
#45 views-rss-fields-enclosure-2511878-43.patch7.45 KBmirondi
#44 views-rss-fields-enclosure-2511878-43.patch7.46 KBmirondi
#42 interdiff_2511878_35-41.txt1.34 KBkarishmaamin
#42 2511878-41.patch7.03 KBkarishmaamin
#41 interdiff_2511878_35-41.txt1.34 KBkarishmaamin
#35 views-rss-fields-enclosure-2511878-35.patch7.23 KBmschudders
#30 views-rss-fields-enclosure-2511878-30.patch7.2 KBadevms
#23 views-rss-fields-enclosure-2511878-23_87.patch6.85 KBjacobbell84
#23 views-rss-fields-enclosure-2511878-23.patch6.85 KBjacobbell84
#17 views-rss-fields-enclosure-2511878-17.patch4.06 KBBarisW
#16 views-rss-fields-enclosure-2511878-16.patch4.06 KBBarisW
#13 views-rss-fields-enclosure-2511878-13.patch2.81 KBdrup16
#6 views-rss-fields-enclosure-2511878.patch3.13 KBgrasmash

Issue fork drupal-2511878

Command icon 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:

Comments

dawehner’s picture

Interesting, following the issue ...

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

grasmash’s picture

Status: Active » Needs review
StatusFileSize
new3.13 KB
ekes’s picture

Status: Needs review » Needs work

So the first thing I try is a related entity (because my immediate use case is a media entity referenced by an node).

+++ b/core/modules/views/src/Plugin/views/row/RssFields.php
@@ -154,6 +164,27 @@ public function render($row) {
+      $field_name = $this->options['enclosure_field'];
+      $entity = $this->view->result[$row_index]->_entity;
+      $enclosure = $entity->$field_name;

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?

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

drup16’s picture

Status: Needs work » Reviewed & tested by the community

I tested the patch from #6 and it is working when adding an Image field.

Question remains:

  • When i add the image under the View's Fields, we can set the Image Style. Is the purpose of this patch only to add the <enclosure> tag without considering the Image Style?

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 6: views-rss-fields-enclosure-2511878.patch, failed testing. View results

quixxel’s picture

Patch #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}.

drup16’s picture

@quixxel it could be that one of your nodes does not have the image field set. Look at your error messageError: Call to a member function getFileUri() on null in , it alludes to needing a validation to make sure $file is set.

drup16’s picture

Status: Needs work » Needs review
quixxel’s picture

Thxx @drup16 !
Patch works for me.

BarisW’s picture

Version: 8.6.x-dev » 8.8.x-dev
StatusFileSize
new4.06 KB

Hi 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.

BarisW’s picture

StatusFileSize
new4.06 KB

My bad, I switched the filesize and mimetype attributes.

drup16’s picture

Hi @BarisW,

I am not sure where you got the PDFs from, but this was for adding Images to 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.

lendude’s picture

Status: Needs review » Needs work

Thanks for working on this.

  1. +++ b/core/modules/views/src/Plugin/views/row/RssFields.php
    @@ -84,6 +88,13 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    +      '#type' => 'select',
    

    This now only allows one 'enclosure' field per feed, does that make sense in RSS? (I'm asking, no idea really)

  2. +++ b/core/modules/views/src/Plugin/views/row/RssFields.php
    @@ -84,6 +88,13 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    +      '#description' => $this->t('Describes a media object that is attached to the item. This must be a file field.'),
    +      '#options' => $view_fields_labels,
    

    Wouldn't it be better if we can validate this somehow? Maybe limit the options to the allowed fields only and add validation?

  3. +++ b/core/modules/views/src/Plugin/views/row/RssFields.php
    @@ -154,6 +165,57 @@ public function render($row) {
    +          if($file = File::load($value[0]['target_id'])) {
    

    Lets not use setters inside if(), also this needs a space after the if

  4. +++ b/core/modules/views/src/Plugin/views/row/RssFields.php
    @@ -154,6 +165,57 @@ public function render($row) {
    +                $image = \Drupal::service('image.factory')->get($derivative_uri);
    

    We should inject this

  5. +++ b/core/modules/views/src/Plugin/views/row/RssFields.php
    @@ -154,6 +165,57 @@ public function render($row) {
    +              // In RSS feeds, it is necessary to use absolute URLs. The 'url.site'
    +              // cache context is already associated with RSS feed responses, so it
    

    comment > 80 characters

Also, this needs tests.

christian le fournis’s picture

Can we allow media field entity to be used as enclosure? Looks like this patch works great for file only.

attheshow’s picture

I was also trying to use the patch to allow enclosure of a media item and couldn't get it to work.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

jacobbell84’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new6.85 KB
new6.85 KB

I 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.

lendude’s picture

Issue tags: +Needs tests

Just some nits to pick:

  1. +++ b/core/modules/views/src/Plugin/views/row/RssFields.php
    @@ -152,6 +213,71 @@ public function render($row) {
    +      $field_name = $this->options['enclosure_field'];
    +      $field_options = $this->view->field[$field_name]->options;
    +      $entity = $this->view->result[$row_index]->_entity;
    +      $enclosure = $entity->$field_name;
    

    Better to use the getEntity method here that also takes any relationships into account.:

          $field_name = $this->options['enclosure_field'];
          $field = $this->view->field[$field_name];
          $field_options = $field->options;
          $entity = $field->getEntity($this->view->result[$row_index]);
          $enclosure = $entity->$field_name;
    

    And getEntity() can return NULL so that also has to be taken into account.

  2. +++ b/core/modules/views/src/Plugin/views/row/RssFields.php
    @@ -152,6 +213,71 @@ public function render($row) {
    +        $file = File::load($value[0]['target_id']);
    

    We have the entity type manager injected, why not use it instead of a direct call to File::load

  3. +++ b/core/modules/views/src/Plugin/views/row/RssFields.php
    @@ -152,6 +213,71 @@ public function render($row) {
    +      elseif ($enclosure instanceof EntityReferenceFieldItemList && sizeOf($enclosure->referencedEntities()) > 0) {
    

    sizeOf -> count

  4. +++ b/core/modules/views/src/Plugin/views/row/RssFields.php
    @@ -152,6 +213,71 @@ public function render($row) {
    +          if ($field->getType() == 'entity_reference' && $field_storage->getSetting("target_type") == "media") {
    

    == can be ===

But yeah, this needs tests above all.

rapindrive’s picture

The 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

jacobbell84’s picture

Hi @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.

swetaranjan’s picture

I 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.

zyla’s picture

Patch #23 works fine for me with Drupal 8.8.1. Thank you !

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

adevms’s picture

I 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.

playful’s picture

Patch #30 working well for me on D8.9.7. Thanks!

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

jacobbell84’s picture

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mschudders’s picture

Patch against D9.2
Works properly.

Only change vs patch #30 is that:

      if ($enclosure instanceof FileFieldItemList && $enclosure->count() > 0) {
        $value = $enclosure->getValue();

There is a check if the FileFieldItemList contains any value. Otherwise the code will throw a FATAL.

xamount’s picture

Patch at #30 works for me on 8.9.16. Thanks very much!

parisek made their first commit to this issue’s fork.

karishmaamin’s picture

StatusFileSize
new1.34 KB

Patch #35 works in D9.2, here is the patch that removes custom code error in #35

karishmaamin’s picture

StatusFileSize
new7.03 KB
new1.34 KB

Patch #35 works in D9.2, here is the patch that removes custom code error in #35

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mirondi’s picture

Adding patch with alt tag included.

mirondi’s picture

StatusFileSize
new7.45 KB
askibinski’s picture

According 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 :(

mirondi’s picture

jor_kai’s picture

Great 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

liliplanet’s picture

Oh thank you so much! Patch #42 works perfectly, most appreciated.

bartlangelaan’s picture

Status: Needs review » Needs work

The patch from #42 is missing a config schema for the new configuration. This should be added, to make sure the config schema is correct.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

bartlangelaan’s picture

Status: Needs work » Needs review
StatusFileSize
new7.61 KB

This is the same patch as #42, but with the config schema extended to include the new option.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

nsciacca’s picture

Working for me on 9.4.8 with a media field configured to use a specific image style - thanks!

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new2.19 KB

The 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.

pooja saraah’s picture

StatusFileSize
new7.57 KB
new1.42 KB

Fixed failed commands on #52
Attached patch against Drupal 10.1.x

kakoum’s picture

Got this error "Call to undefined function Drupal\views\Plugin\views\row\file_create_url()" :'( file_create_url depreciated in drupal 10.0

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

navneet0693’s picture

Status: Needs work » Needs review
StatusFileSize
new4.65 KB
new9.02 KB
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs upgrade path

For the CC failure.

Also with the schema change will need an upgrade path.

Thanks.

parisek’s picture

Seems 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)

abhijeet.kumar2107’s picture

Its 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]

^

hebl’s picture

I've attached a patch modified from #56 which fixes the D10 deprecation errors when using the file_create_url() method.

Works with D10.1

ralphvdhoudt’s picture

StatusFileSize
new8.51 KB

Imporved patch to have correct dependency injection and better support for getAbsoluteUrl

ralphvdhoudt’s picture

StatusFileSize
new8.61 KB

Add missing param description

ralphvdhoudt’s picture

StatusFileSize
new8.62 KB

Correct naming

xamount’s picture

Status: Needs work » Needs review

I've tested the patch at #67 and it's working for me on D10.1.6

needs-review-queue-bot’s picture

Status: Needs review » Needs work

The 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.)

stefan.korn’s picture

while 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.

cedewey’s picture

Issue summary: View changes

Thanks 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.

cedewey’s picture

Title: Support enclosure field in Views RssFields row plugin » Add support for enclosure field in Views RssFields row plugin so that posts can include media items

kekkis made their first commit to this issue’s fork.

kekkis changed the visibility of the branch 11.x to hidden.

kekkis’s picture

Assigned: Unassigned » kekkis
kekkis’s picture

Assigned: kekkis » Unassigned
StatusFileSize
new11.03 KB

I 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.

gfbarbosa changed the visibility of the branch 2511878-support-enclosure-field to active.

gfbarbosa changed the visibility of the branch 11.x to active.

gfbarbosa changed the visibility of the branch 11.x to hidden.

gfbarbosa changed the visibility of the branch 2511878-support-enclosure-field to hidden.

gfbarbosa changed the visibility of the branch 10.3.x to hidden.

gfbarbosa’s picture

I created a new updated branch for 10.3.x with previous commits from #76.

timohuisman’s picture

Added "Needs subsystem maintainer review" based on the summary and #70

lendude’s picture

In 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

timohuisman’s picture

StatusFileSize
new9.11 KB

Alright, 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.

timohuisman’s picture

matt b’s picture

@timohuisman's page (#85) works for me. Thank you.

ckhalilo’s picture

I 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

$referenced_entities = reset($enclosure->referencedEntities());
$file = $referenced_entities->get('thumbnail')->entity;
ckhalilo’s picture

StatusFileSize
new9.17 KB

here the new patch

fox mulder’s picture

StatusFileSize
new9.24 KB

[#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.)

rkelbel48’s picture

Patch (#89) is working for me on Drupal 10.4.5.

mac501’s picture

StatusFileSize
new8.73 KB

Modified patch for D11.2

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

mmenavas’s picture

StatusFileSize
new8.78 KB
new2.12 KB

Updating patch #89 with code changes suggested by Gemini, which I reviewed and tested on my Drupal 10.6.3 site.

jacobbell84’s picture

StatusFileSize
new8.71 KB

Just a quick reroll for 11.4