Hi, I have tried outputting rss feeds straight as RSS feed, RSS default and force as fields.

Still the feeds publish with ‘submitted by’ and ‘publishing date’ shown inside the description tag, don’t want that :)

Have made sure that each content type has ‘authored by’ deselected, still no joy.

Is it hardcoded somewhere? Would most appreciate any suggestions on how to remove the unneccesary text that appears in my feeds.

The description is build inside \Drupal\node\Plugin\views\row\Rss::render

This seems ok, but somehow this doesn't account for some of the settings on the node type:

$build_mode = $display_mode;

    $build = node_view($node, $build_mode);
    unset($build['#theme']);

Workaround is using fields instead of content, steps can be found in #17

Comments

Liliplanet created an issue. See original summary.

damienmckenna’s picture

Project: Views (for Drupal 7) » Drupal core
Version: 8.x-3.x-dev » 8.6.x-dev
Component: Miscellaneous » views.module
Issue tags: -Views RSS

Views was moved into core in D8, so I'm moving the issue over to its issue queue.

liliplanet’s picture

I’m still trying to remove date and authored by on rss feeds coming from views.

My feed is a simple Format: RSS Feed and Show Content: Use default RSS settings

As mentioned, ‘authored by’ is switched off in content type.

<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xml:base="{{ link }}"{{ namespaces }}>
  <channel>
    <title>{{ title }}</title>
    <link>{{ link }}</link>
    <description>{{ description }}</description>
    <language>{{ langcode }}</language>
    {{ channel_elements }}
    {{ items }}
  </channel>
</rss>

I tried removing {{ channel elements }} from views-view-rss.html.twig, makes no difference.

‘Authored by and date’ is coming from somewhere else in views, please have a look at your rss feed, please how can I fix this?

Most appreciate any support :)

liliplanet’s picture

On a mission here .. removed the following from node.html.twig, still no joy (:

{% if display_submitted %}
    <footer>
      {{ author_picture }}
      <div{{ author_attributes }}>
        {% trans %}Submitted by {{ author_name }} on {{ date }}{% endtrans %}
        {{ metadata }}
      </div>
    </footer>
  {% endif %}

If it’s not in the core views or node templates, where else can I look please?

liliplanet’s picture

Category: Support request » Bug report
lendude’s picture

@Liliplanet Yes this appears to get added in \Drupal\node\Plugin\views\row\Rss::render

    $node->link = $node->url('canonical', ['absolute' => TRUE]);
    $node->rss_namespaces = [];
    $node->rss_elements = [
      [
        'key' => 'pubDate',
        'value' => gmdate('r', $node->getCreatedTime()),
      ],
      [
        'key' => 'dc:creator',
        'value' => $node->getOwner()->getDisplayName(),
      ],
      [
        'key' => 'guid',
        'value' => $node->id() . ' at ' . $base_url,
        'attributes' => ['isPermaLink' => 'false'],
      ],
    ];

Might be needed to get valid feed XML, although it looks like they are optional.....

liliplanet’s picture

Thank you so much for your response @Lendude! The module viewsrss not ready for D8, what do mean ‘get a valid feed xml?

Are you saying it is not possible currently to get a clean feed without

'key' => 'pubDate',
        'value' => gmdate('r', $node->getCreatedTime()),
      ],
      [
        'key' => 'dc:creator',

What is the solution please, most appreciate your time 🌸

lendude’s picture

Category: Bug report » Support request
Status: Active » Postponed (maintainer needs more info)

what do mean ‘get a valid feed xml?

Well a RSS feed needs to contain certain elements to adhere to the RSS specs, like described here http://www.rss-specifications.com/rss-specifications.htm
It may be that the elements you want to take out are required in some version of those specs. They aren't required in the 2.0 specs, but they may be in an older version, I don't know.

I think the easiest way to get the result you want is to override views-view-row-rss.html.twig in your theme and add an if inside for loop to test item.key != pubDate or item.key != dc:creator

  {% for item in item_elements -%}
<-- ADD AN IF HERE --->
    <{{ item.key }}{{ item.attributes -}}
    {% if item.value -%}
      >{{ item.value }}</{{ item.key }}>
    {% else -%}
      {{ ' />' }}
    {% endif %}
  {%- endfor %}

Does that work for you?

Moving this back to a support request because I don't think we want to change the default behaviour here.

liliplanet’s picture

Thank you so much for your help Lendude! I replaced the code with the following:

<item>
  <title>{{ title }}</title>
  <link>{{ link }}</link>
  <description>{{ description }}</description>
 {% for item in item_elements -%}
<-- ADD AN IF HERE --->
    <{{ item.key }}{{ item.attributes -}}
    {% if item.value -%}
      >{{ item.value }}</{{ item.key }}>
    {% else -%}
      {{ ' />' }}
    {% endif %}
  {%- endfor %}
</item>

Still no change. I even tried ..

<item>
  <title>{{ title }}</title>
  <link>{{ link }}</link>
  <description>{{ description }}</description>
</item>

in core, not even duplicated the template to my themes/bootstrap/templates/views

cache cleared, authored by and date still shows up on feeds 😅

Lendude, outputting rss feeds this way is not usable, I would consider it a bug 🤗

liliplanet’s picture

The great news is that Drupal\node\Plugin\views\row\Rss::render is not the culprit, when I removed pubdate and creator (which is indeed necessary to validate the feed), submitted by and date still shows up.

liliplanet’s picture

Sorry, but really trying to figure this out ..

I went as far to copy code views-view-row-rss.html.twig from rss views D7

<item>
    <title><?php print $title; ?></title>
    <link><?php print $link; ?></link>
    <description><?php print $description; ?></description>
    <?php print $item_elements; ?>
  </item>

Author and publising date is still in the feed 😔

It does not seem to be coming from the templates, not from Drupal\node\Plugin\views\row\Rss::render

then where? :)

lendude’s picture

@Liliplanet well it is coming from the templates but I'm guessing not the ones you are modifying. Using a D7 template should totally break everything, so if stuff still gets printed when you do that, that means you are not working on the right template.

You need to copy the provided template to the theme you are using, then the one in the theme will be used.

Oh and lots of cache clearing when you change stuff for it to be picked up.

liliplanet’s picture

Thank you for your patience Lendude, so much appreciated 🌸

In the code you posted earlier, please can we try again?

What is the ADD AN IF here? Sorry, way over my head 🤓

<item>
  <title>{{ title }}</title>
  <link>{{ link }}</link>
  <description>{{ description }}</description>
 {% for item in item_elements -%}
<-- ADD AN IF HERE --->
    <{{ item.key }}{{ item.attributes -}}
    {% if item.value -%}
      >{{ item.value }}</{{ item.key }}>
    {% else -%}
      {{ ' />' }}
    {% endif %}
  {%- endfor %}
</item>
liliplanet’s picture

Category: Support request » Bug report
liliplanet’s picture

Status: Postponed (maintainer needs more info) » Active
liliplanet’s picture

lendude’s picture

Title: Views RSS feed outputs ‘submitted’ by and ‘authored on date’ » Views RSS display always outputs ‘submitted’ by and ‘authored on date’ inside the description tag
StatusFileSize
new71.72 KB
new212.73 KB

@Liliplanet ahhh! Wait a minute, are you talking about the create date and author name INSIDE the description tag? Sorry totally missed that you might be referring to those!

I can reproduce that locally, and looked around a bit more in \Drupal\node\Plugin\views\row\Rss::render

and this is done by:

    $build_mode = $display_mode;

    $build = node_view($node, $build_mode);
    unset($build['#theme']);

But no idea why the RSS display mode would show those at the moment.

But looking at your description output (and mine locally), even if you take the author and submitted date out, that output is still crap. It contains wrappers for quick edit and all sorts of other escaped HTML tags. So using 'Show: content', looks like a bad idea to begin with.

I can get some nice clean output:
- Chose 'Show: Fields' (so not 'Force using fields', just plain fields output)
- Close the dialog without setting the required fields (just click the X in the top right corner)
- Add some fields (title, body, a url, node id)
- Go to Row style options (so click on the 'Settings' link behind 'Show: Fields'
- Fill out the required fields with the fields you've added
- Add more fields if you need them to will out the required settings

So setting it up like this:

So that ends up looking like this:

    <item>
  <title><a href="/en/no/way/dude" hreflang="en">Art my cle</a></title>
  <link>http://d8.mamp/en/no/way/dude</link>
  <description>&lt;p&gt;bod&lt;/p&gt;</description>
  <pubDate>2018-01-29T15:40:36+0100</pubDate>
    <dc:creator>admin</dc:creator>
    <guid isPermaLink="false">1</guid>
    </item>

But the fact that the default output is Content, and it outputs totally useless escaped HTML filled junk, is something that needs to be addressed.

liliplanet’s picture

Wow, that sounds awesome, will revert back as soon as I can run a test, thank you so much!

liliplanet’s picture

LenDude, you are my absolute hero! Thank you so much for finding the solution here ✨

Just a note, relative path needs to rewritten in the field, output somehow cuts off the first part.

Image size for social networks is 1200x630px

RSS feed date is ‘r’ and it looks so beautiful.

LenDude, arms full of virtual flowers for you 🌸🌷🌸🌷🌸🌷🌸🌷🌸🌷🌸🌷

liliplanet’s picture

Category: Bug report » Feature request
Status: Active » Needs review
lendude’s picture

Category: Feature request » Bug report
Issue summary: View changes
Status: Needs review » Active

@Liliplanet glad it works now!

Lets leave this as a bug. The fact that RSS displays default to showing content and then display lots of HTML garbage isn't right. But with a valid workaround it's not high on my fix list :)

seirerman’s picture

Same problem here on Drupal 8.5.5, but you can get rid of the unwanted HTML tags:
Edit the field for the description in the view, then check "Strip HTML tags" under "Rewrite results". Save the view after that.

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

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now 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.

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

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

diamondsea’s picture

This issue doesn't seem to have anything to do with the twig templates, it seems it is being added somewhere in the rendering of the node in the Content format, where it renders the node and assigns it to $item->description in /core/modules/node/src/Plugin/views/row/Rss.php.

Line 129 renders the node:

   $build = node_view($node, $build_mode);

and Line 148 assigns it to the $item->description which gets rendered as the . tag in the XML output:

      $item->description = $build;

I haven't been able to find out where yet, though (stepping through render functions is tedious at best).

mhdev90’s picture

You can use the "entity_view_display_alter" hook.

e.g.:

use Drupal\Core\Entity\Display\EntityViewDisplayInterface;

function HOOK_entity_view_display_alter(EntityViewDisplayInterface $display, $context) {
  if($context['view_mode'] === 'rss') {
    $display->removeComponent('created');
  }
}
laura.gates’s picture

@Lendude your workaround posted in #17 doesn't seem to work anymore in 8.7.4. When I follow your example and use fields, I get validation errors when ingesting the feed into a third-party-application.

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.

fjgarlin’s picture

I was facing the same issue here.

I ended up creating a template hook: "template_preprocess_views_view_row_rss" to strip those undesired elements as due to the project set up I couldn't change the view to show fields instead of RSS teaser mode.

I used this technique to get rid of the tags: https://stackoverflow.com/questions/15627523/delete-html-elements-with-p...

function mytheme_preprocess_views_view_row_rss(&$variables) {
  $html = $variables['description'];

  $dom = new \DOMDocument;
  $dom->loadHTML($html);
  $xpath = new \DOMXpath($dom);
  $to_replace = [];
  $replace_with = [];

  // Created info.
  $found = $xpath->query('//*[contains(@class,"field--name-created")]');
  if (!empty($found[0])) {
    $to_replace[] = $found[0]->ownerDocument->saveXML($found[0]);
    $replace_with[] = '';
  }

  // Author info.
  $found = $xpath->query('//*[contains(@class,"field--name-uid")]');
  if (!empty($found[0])) {
    $to_replace[] = $found[0]->ownerDocument->saveXML($found[0]);
    $replace_with[] = '';
  }

  $html = str_replace($to_replace, $replace_with , $html);
  $variables['description'] = $html;
}
cuman’s picture

Hi

I tried it and get:

Warning: DOMDocument::loadHTML(): Tag section invalid in Entity, line: 22 в mytheme_preprocess_views_view_row_rss() (строка 13 из /home/u13436/domains/mydomen/web/themes/custom/mytheme/mytheme.theme) #0 /home/u13436/domains/mydomen/web/core/includes/bootstrap.inc(587): _drupal_error_handler_real(2, 'DOMDocument::lo...', '/home/u13436/do...', 13, Array) #1 [internal function]: _drupal_error_handler(2, 'DOMDocument::lo...', '/home/u13436/do...', 13, Array) #2 /home/u13436/domains/mydomen/web/themes/custom/mytheme/mytheme.theme(13): DOMDocument->loadHTML('<span property=...') #3 /home/u13436/domains/mydomen/web/core/lib/Drupal/Core/Theme/ThemeManager.php(287): mytheme_preprocess_views_view_row_rss(Array, 'views_view_row_...', Array) #4 /home/u13436/domains/mydomen/web/core/lib/Drupal/Core/Render/Renderer.php(437): Drupal\Core\Theme\ThemeManager->render('views_view_row_...', Array) #5 /home/u13436/domains/mydomen/web/core/lib/Drupal/Core/Render/Renderer.php(450): Drupal\Core\Render\Renderer->doRender(Array) #6 /home/u13436/domains/mydomen/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, false) #7 /home/u13436/domains/mydomen/web/core/lib/Drupal/Core/Template/TwigExtension.php(501): Drupal\Core\Render\Renderer->render(Array) #8 /home/u13436/domains/mydomen/web/sites/default/files/php/twig/5dc2e6cdd1459_views-view-rss.html.twig_UUnUjJ9j_KcYvCDefjA8wlfA_/c8WB115fheBBwNwBUPF-VqrqSRq-EZiQzEVSc4MepvI.php(85): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true) #9 /home/u13436/domains/mydomen/vendor/twig/twig/src/Template.php(455): __TwigTemplate_b41ef8aa305cef138fa389ffb238aa4b4b8378a4e17cc1354c1d9e0372cadd40->doDisplay(Array, Array) #10 /home/u13436/domains/mydomen/vendor/twig/twig/src/Template.php(422): Twig\Template->displayWithErrorHandling(Array, Array) #11 /home/u13436/domains/mydomen/vendor/twig/twig/src/Template.php(434): Twig\Template->display(Array) #12 /home/u13436/domains/mydomen/web/core/themes/engines/twig/twig.engine(64): Twig\Template->render(Array) #13 /home/u13436/domains/mydomen/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template('core/modules/vi...', Array) #14 /home/u13436/domains/mydomen/web/core/lib/Drupal/Core/Render/Renderer.php(437): Drupal\Core\Theme\ThemeManager->render('views_view_rss', Array) #15 /home/u13436/domains/mydomen/web/core/lib/Drupal/Core/Render/Renderer.php(450): Drupal\Core\Render\Renderer->doRender(Array) #16 /home/u13436/domains/mydomen/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, true) #17 /home/u13436/domains/mydomen/web/core/lib/Drupal/Core/Render/Renderer.php(139): Drupal\Core\Render\Renderer->render(Array, true) #18 /home/u13436/domains/mydomen/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() #19 /home/u13436/domains/mydomen/web/core/lib/Drupal/Core/Render/Renderer.php(140): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #20 /home/u13436/domains/mydomen/web/core/modules/views/src/Plugin/views/display/Feed.php(63): Drupal\Core\Render\Renderer->renderRoot(Array) #21 /home/u13436/domains/mydomen/web/core/modules/views/src/Routing/ViewPageController.php(52): Drupal\views\Plugin\views\display\Feed::buildResponse('rss', 'feed_2', Array) #22 [internal function]: Drupal\views\Routing\ViewPageController->handle('rss', 'feed_2', Object(Drupal\Core\Routing\RouteMatch)) #23 /home/u13436/domains/mydomen/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #24 /home/u13436/domains/mydomen/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #25 /home/u13436/domains/mydomen/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #26 /home/u13436/domains/mydomen/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #27 /home/u13436/domains/mydomen/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #28 /home/u13436/domains/mydomen/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #29 /home/u13436/domains/mydomen/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #30 /home/u13436/domains/mydomen/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #31 /home/u13436/domains/mydomen/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(191): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #32 /home/u13436/domains/mydomen/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(128): Drupal\page_cache\StackMiddleware\PageCache->fetch(Object(Symfony\Component\HttpFoundation\Request), 1, true) #33 /home/u13436/domains/mydomen/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(82): Drupal\page_cache\StackMiddleware\PageCache->lookup(Object(Symfony\Component\HttpFoundation\Request), 1, true) #34 /home/u13436/domains/mydomen/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #35 /home/u13436/domains/mydomen/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #36 /home/u13436/domains/mydomen/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #37 /home/u13436/domains/mydomen/web/core/lib/Drupal/Core/DrupalKernel.php(693): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #38 /home/u13436/domains/mydomen/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #39 {main}.

What's wrong?

fjgarlin’s picture

Nothing seems wrong, you might just need to turn warnings off for that call as suggested here: https://stackoverflow.com/questions/6090667/php-domdocument-errors-warni...

...
$dom = new \DOMDocument;
libxml_use_internal_errors(true);
$dom->loadHTML($html);
libxml_clear_errors();
...
cuman’s picture

Thank you for errors-cleaning

But I still get ‘submitted by’ and ‘authored on date’ inside the description tag

<item>
  <title>Title</title>
  <link>mydomen</link>
  <description>&lt;span property="schema:name"&gt;Title&lt;/span&gt;

            &lt;div&gt;Subtitle&lt;/div&gt;
      &lt;span rel="schema:author"&gt;&lt;a title="Просмотр профиля пользователя." href="https://mydomen/user/1" lang="" about="https://mydomen/user/1" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Admin&lt;/a&gt;&lt;/span&gt;
&lt;span property="schema:dateCreated" content="2019-11-07T15:00:38+00:00"&gt;18:00, 7 ноября 2019&lt;/span&gt;

            &lt;div&gt;  &lt;img src="https://mydomen/sites/default/files/styles/864x410/public/2019-11/text_0.jpg?h=9e875c58&amp;itok=xxZ_g_3l" width="864" height="410" typeof="foaf:Image" /&gt;&lt;/div&gt;
      </description>
  <pubDate>Thu, 07 Nov 2019 15:00:38 +0000</pubDate>
    <dc:creator>Admin</dc:creator>
    <guid isPermaLink="false">142 at https://mydomen</guid>
    </item>
fjgarlin’s picture

@cuman, that's because your markup doesn't contain the classes that the code was looking for. You can change the xpath selector to target: rel="schema:author" instead. Likewise for the date.

cuman’s picture

@fjgarlin, i did so:

function mytheme_preprocess_views_view_row_rss(&$variables) {
  $html = $variables['description'];

  $dom = new \DOMDocument;
  libxml_use_internal_errors(true);
  $dom->loadHTML($html);
  libxml_clear_errors();
  $xpath = new \DOMXpath($dom);
  $to_replace = [];
  $replace_with = [];

  // Created info.
  $found = $xpath->query('//*[contains(@property,"schema:dateCreated")]');
  if (!empty($found[0])) {
    $to_replace[] = $found[0]->ownerDocument->saveXML($found[0]);
    $replace_with[] = '';
  }

  // Author info.
  $found = $xpath->query('//*[contains(@rel,"schema:author")]');
  if (!empty($found[0])) {
    $to_replace[] = $found[0]->ownerDocument->saveXML($found[0]);
    $replace_with[] = '';
  }

  $html = str_replace($to_replace, $replace_with , $html);
  $variables['description'] = $html;
}

But no changes

cuman’s picture

Finaly I solved by views_rss and this patch: https://www.drupal.org/project/views_rss/issues/3070596

laura.gates’s picture

@cuman

Thanks for this! However, IMO, a patch to core is still the preferred solution as views_rss is still considered an experimental module and the current dev branch has been broken for a while and relies on some old patches to hold things together. I'm concerned about possible security issues with views_rss.

rodricels’s picture

This issue will be fixed by #2353867: [META] Expose Title and other base fields in Manage Display and #1399990: Remove "Display author and date information" in Display Settings in favor of listing Author and Date in Manage Displays

A workaround is possible for 8.7 and 8.8 with https://www.drupal.org/project/manage_display.

Another workaround if you're using View display content instead of fields, is create twig's files for these node-fields, they're based on core/themes/stable/templates/field/field.html.twig

  • field--node--created.html.twig
  • field--node--title.html.twig
  • field--node--uid.html.twig

You can remove all displayed content for RSS, with:

{% if element['#view_mode'] == 'rss' %}
  {% spaceless %}{% endspaceless %}
{% else %}
  {%
    set title_classes = [
    label_display == 'visually_hidden' ? 'visually-hidden',
  ]
  %}

  {% if label_hidden %}
    {% if multiple %}
      <div{{ attributes }}>
        {% for item in items %}
          <div{{ item.attributes }}>{{ item.content }}</div>
        {% endfor %}
      </div>
    {% else %}
      {% for item in items %}
        <div{{ attributes }}>{{ item.content }}</div>
      {% endfor %}
    {% endif %}
  {% else %}
    <div{{ attributes }}>
      <div{{ title_attributes.addClass(title_classes) }}>{{ label }}</div>
      {% if multiple %}
      <div>
        {% endif %}
        {% for item in items %}
          <div{{ item.attributes }}>{{ item.content }}</div>
        {% endfor %}
        {% if multiple %}
      </div>
      {% endif %}
    </div>
  {% endif %}
{% endif %}
eiriksm’s picture

Here is another workaround:

In your theme or module (example is from theme):


/**
 * Implements hook_preprocess_HOOK().
 */
function mytheme_preprocess_views_view_row_rss(&$variables) {
  $item = $variables['row'];
  if (isset($item->description) && is_array($item->description)) {
    // Re-render it.
    $item->description['#theme'] = 'node';
    unset($item->description["#children"]);
    unset($item->description["#markup"]);
    unset($item->description["#printed"]);
    $variables['description'] = (string) \Drupal::service('renderer')->render($item->description);
  }
}

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.

mrshowerman’s picture

Thanks @eiriksm, this worked for me. However, I had to remove the overriding of the #theme key, because it led to a fatal error in the node theme suggestion processing. I also changed the last line, so altogether it now looks like this:


/**
 * Implements hook_preprocess_HOOK().
 */
function mytheme_preprocess_views_view_row_rss(&$variables) {
  $item = $variables['row'];
  if (isset($item->description) && is_array($item->description)) {
    // Re-render it.
    unset($item->description["#children"]);
    unset($item->description["#markup"]);
    unset($item->description["#printed"]);
    $item->description = (string) \Drupal::service('renderer')->render($item->description);
  }
}

jabastin arul’s picture

@mrshowerman

Still Its not working.

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.

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.

robertom’s picture

Component: views.module » node system
Status: Active » Needs review
StatusFileSize
new602 bytes

Same problem here.

Attached a proposed patch that permit to use the node template override, so we can use a template like node--rss.html.twig

Status: Needs review » Needs work

The last submitted patch, 44: 2946812-44.patch, failed testing. View results

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.

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.

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.

joshua1234511’s picture

Workaround can be done via theme

/**
 * Implements template_preprocess_views_view_rss().
 */
function template_preprocess_views_view_row_rss(&$variables) {
  foreach ($variables['item_elements'] as $key => $item) {
    if (str_contains($item['key'], 'dc:creator')) {
      unset($variables['item_elements'][$key]);
    }
    if (str_contains($item['key'], 'guid')) {
      $uuid = $item['value'];
    }
  }
}

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.

tichris59’s picture

Workaround #49 works like a charm but the following part is not useful, $uuid is not used after this:

 if (str_contains($item['key'], 'guid')) {
      $uuid = $item['value'];
    }
acbramley’s picture

Status: Needs work » Postponed (maintainer needs more info)

There seems to be quite a few options for fixing this in custom code including a somewhat simple preprocess hook. Do we need to do anything else here?

smustgrave’s picture

Wanted to bump 1 more time before closing.

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.

noah’s picture

I'm willing to take a shot at putting together a patch for this when I can.

There are options for working around it currently but most of them require parsing core's hardcoded output with DOMDocument(), which is not ideal (and not very Drupally). Giving template_preprocess_views_view_row_rss() access to the various components of the feed item without having to parse HTML would be a step in the right direction—I'll see where I can get with that.

noah’s picture

Apologies for having been so slow to follow up on this, but I have some answers now. I'm convinced this is a real bug (for reasons explained here), but also that the current path forward is a contrib module.

First, why this happens: in the context of feeds, nodes are rendered by \Drupal\node\Plugin\views\row\Rss::render() which, around line 125, does:

unset($build['#theme']);

Once '#theme' is gone, no preprocessing is done on the node, including the core node module's own preprocessing at \Drupal\node\Hook\NodeThemeHooks::preprocessNode(). The core preprocessing includes some code that extracts and then unsets the relevant elements, preceded by this comment:

// Make created, uid and title fields available separately. Skip this custom
// preprocessing if the field display is configurable and skipping has been
// enabled.
// @todo https://www.drupal.org/project/drupal/issues/3015623
//   Eventually delete this code and matching template lines. Using
//   $variables['content'] is more flexible and consistent.

So because nodes displayed in feeds have no '#theme' element they're never preprocessed, and because they're never preprocessed the title, uid, and created elements are never extracted to be addressed separately in a template file; as a result the elements are still present when the description is built and they show up there.

A good fix for this in core is going to depend on https://www.drupal.org/project/drupal/issues/3015623 being sorted out, which does not appear to be likely to happen anytime soon. So I'm working on a module that I'll link to here when (if) it's available.