From 593813261daa362bce374d68873ace4f8a50e229 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Tue, 13 Aug 2019 06:52:54 +1000
Subject: [PATCH] Issue #3070978 by idebr: Remove early rendering of RSS
 channel elements in template_preprocess_views_view_rss()

---
 .../views_test_rss/views_test_rss.info.yml      |  6 ++++++
 .../views_test_rss/views_test_rss.module        | 17 +++++++++++++++++
 .../src/Functional/Plugin/DisplayFeedTest.php   |  3 ++-
 core/modules/views/views.theme.inc              |  2 +-
 4 files changed, 26 insertions(+), 2 deletions(-)
 create mode 100644 core/modules/views/tests/modules/views_test_rss/views_test_rss.info.yml
 create mode 100644 core/modules/views/tests/modules/views_test_rss/views_test_rss.module

diff --git a/core/modules/views/tests/modules/views_test_rss/views_test_rss.info.yml b/core/modules/views/tests/modules/views_test_rss/views_test_rss.info.yml
new file mode 100644
index 000000000000..3cc94385f0e6
--- /dev/null
+++ b/core/modules/views/tests/modules/views_test_rss/views_test_rss.info.yml
@@ -0,0 +1,6 @@
+name: 'Views Test RSS'
+type: module
+description: 'Provides hooks to alter RSS output for testing purposes.'
+package: Testing
+version: VERSION
+core: 8.x
diff --git a/core/modules/views/tests/modules/views_test_rss/views_test_rss.module b/core/modules/views/tests/modules/views_test_rss/views_test_rss.module
new file mode 100644
index 000000000000..5df73da91fec
--- /dev/null
+++ b/core/modules/views/tests/modules/views_test_rss/views_test_rss.module
@@ -0,0 +1,17 @@
+<?php
+
+/**
+ * @file
+ * Hook implementations for this module.
+ */
+
+/**
+ * Implements hook_preprocess_HOOK().
+ */
+function views_test_rss_preprocess_views_view_rss(&$variables) {
+  $variables['channel_elements'][] = [
+    '#type' => 'html_tag',
+    '#tag' => 'copyright',
+    '#value' => t('Copyright 2019 Dries Buytaert'),
+  ];
+}
diff --git a/core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php b/core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php
index 354ca7b4e03b..1b6215da2678 100644
--- a/core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php
+++ b/core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php
@@ -26,7 +26,7 @@ class DisplayFeedTest extends ViewTestBase {
    *
    * @var array
    */
-  public static $modules = ['block', 'node', 'views'];
+  public static $modules = ['block', 'node', 'views', 'views_test_rss'];
 
   protected function setUp($import_test_views = TRUE) {
     parent::setUp($import_test_views);
@@ -63,6 +63,7 @@ public function testFeedOutput() {
     $this->drupalGet('test-feed-display.xml');
     $this->assertEquals($site_name, $this->getSession()->getDriver()->getText('//title'));
     $this->assertEquals($frontpage_url, $this->getSession()->getDriver()->getText('//link'));
+    $this->assertEquals('Copyright 2019 Dries Buytaert', $this->getSession()->getDriver()->getText('//channel/copyright'));
     $this->assertEquals($node_title, $this->getSession()->getDriver()->getText('//item/title'));
     // Verify HTML is properly escaped in the description field.
     $this->assertRaw('&lt;p&gt;A paragraph&lt;/p&gt;');
diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc
index 82e4daa570ec..e7ae6ad26725 100644
--- a/core/modules/views/views.theme.inc
+++ b/core/modules/views/views.theme.inc
@@ -870,7 +870,7 @@ function template_preprocess_views_view_rss(&$variables) {
   $variables['langcode'] = \Drupal::languageManager()->getCurrentLanguage()->getId();
   $variables['namespaces'] = new Attribute($style->namespaces);
   $variables['items'] = $items;
-  $variables['channel_elements'] = \Drupal::service('renderer')->render($style->channel_elements);
+  $variables['channel_elements'] = $style->channel_elements;
 
   // During live preview we don't want to output the header since the contents
   // of the feed are being displayed inside a normal HTML page.
-- 
GitLab