From 2e94575d27f7f1b3f5b956a26d2277a775089d02 Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Wed, 20 Dec 2023 23:29:42 +0000 Subject: [PATCH] Issue #3383219 by Lendude, greatmatter, HeikkiY, PapaGrande, hansfn: Views RSS Feed Fields adds <time> tag --- .../views/src/Plugin/views/row/RssFields.php | 4 +++- .../test_views/views.view.test_display_feed.yml | 16 +++++++++++++++- .../tests/src/Kernel/Plugin/RssFieldsTest.php | 8 ++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/core/modules/views/src/Plugin/views/row/RssFields.php b/core/modules/views/src/Plugin/views/row/RssFields.php index 734e338b3337..924cd7b6e287 100644 --- a/core/modules/views/src/Plugin/views/row/RssFields.php +++ b/core/modules/views/src/Plugin/views/row/RssFields.php @@ -136,7 +136,9 @@ public function render($row) { $item->description = is_array($field) ? $field : ['#markup' => $field]; $item->elements = [ - ['key' => 'pubDate', 'value' => $this->getField($row_index, $this->options['date_field'])], + // Default rendering of date fields adds a <time> tag and whitespace, we + // want to remove these because this breaks RSS feeds. + ['key' => 'pubDate', 'value' => trim(strip_tags($this->getField($row_index, $this->options['date_field'])))], [ 'key' => 'dc:creator', 'value' => $this->getField($row_index, $this->options['creator_field']), diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_display_feed.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_display_feed.yml index b244793a8353..063d68f05f43 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_display_feed.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_display_feed.yml @@ -47,6 +47,20 @@ display: plugin_id: field entity_type: node entity_field: title + created: + id: created + table: node_field_data + field: created + relationship: none + group_type: group + admin_label: '' + entity_type: node + entity_field: created + plugin_id: field + type: timestamp + settings: + date_format: custom + custom_date_format: 'Y-m-d' body: id: body table: node__body @@ -315,7 +329,7 @@ display: link_field: view_node description_field: body creator_field: title - date_field: title + date_field: created guid_field_options: guid_field: view_node guid_field_is_permalink: true diff --git a/core/modules/views/tests/src/Kernel/Plugin/RssFieldsTest.php b/core/modules/views/tests/src/Kernel/Plugin/RssFieldsTest.php index f2b6ee75809f..d72000a36818 100644 --- a/core/modules/views/tests/src/Kernel/Plugin/RssFieldsTest.php +++ b/core/modules/views/tests/src/Kernel/Plugin/RssFieldsTest.php @@ -42,20 +42,23 @@ protected function setUp($import_test_views = TRUE): void { } /** - * Tests correct processing of link fields. + * Tests correct processing of RSS fields. * * This overlaps with \Drupal\Tests\views\Functional\Plugin\DisplayFeedTest to * ensure that root-relative links also work in a scenario without * subdirectory. */ - public function testLink() { + public function testRssFields() { // Set up the current user as uid 1 so the test doesn't need to deal with // permission. $this->setUpCurrentUser(['uid' => 1]); + $date = '1975-05-18'; + $node = $this->createNode([ 'type' => 'article', 'title' => 'Article title', + 'created' => strtotime($date), 'body' => [ 0 => [ 'value' => 'A paragraph', @@ -72,6 +75,7 @@ public function testLink() { $output = $view->preview('feed_2'); $output = (string) $renderer->renderRoot($output); $this->assertStringContainsString('<link>' . $node_url . '</link>', $output); + $this->assertStringContainsString('<pubDate>' . $date . '</pubDate>', $output); } } -- GitLab