From 062ca316d775c183e307cfa2fea773b3f6dfcdee Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Thu, 9 Oct 2014 11:29:36 +0100
Subject: [PATCH] Issue #2293899 by leon.nk, nlisgo: Fixed
 hook_views_preview_info passes an instance of ViewsUI instead of
 ViewExecutable.

---
 .../modules/views_ui/src/Tests/PreviewTest.php | 18 ++++++++++++++++++
 core/modules/views_ui/src/ViewUI.php           |  2 +-
 .../views_ui_test/views_ui_test.info.yml       |  8 ++++++++
 .../modules/views_ui_test/views_ui_test.module | 17 +++++++++++++++++
 4 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 core/modules/views_ui/tests/modules/views_ui_test/views_ui_test.info.yml
 create mode 100644 core/modules/views_ui/tests/modules/views_ui_test/views_ui_test.module

diff --git a/core/modules/views_ui/src/Tests/PreviewTest.php b/core/modules/views_ui/src/Tests/PreviewTest.php
index c7fc24bc175a..191e4b459c2f 100644
--- a/core/modules/views_ui/src/Tests/PreviewTest.php
+++ b/core/modules/views_ui/src/Tests/PreviewTest.php
@@ -201,6 +201,24 @@ public function testPreviewWithPagersUI() {
     $this->assertTrue($elements[2]->a, "Link to next page found.");
   }
 
+  /**
+   * Tests the additional information query info area.
+   */
+  public function testPreviewAdditionalInfo() {
+    \Drupal::moduleHandler()->install(array('views_ui_test'));
+    $this->resetAll();
+
+    $this->drupalGet('admin/structure/views/view/test_preview/edit');
+    $this->assertResponse(200);
+
+    $this->drupalPostForm(NULL, $edit = array(), t('Update preview'));
+
+    // Check for implementation of hook_views_preview_info_alter().
+    // @see views_ui_test.module
+    $elements = $this->xpath('//div[@id="views-live-preview"]/div[contains(@class, views-query-info)]//td[text()=:text]', array(':text' => t('Test row count')));
+    $this->assertEqual(count($elements), 1, 'Views Query Preview Info area altered.');
+  }
+
   /**
    * Get the preview form and force an AJAX preview update.
    *
diff --git a/core/modules/views_ui/src/ViewUI.php b/core/modules/views_ui/src/ViewUI.php
index 260a71e84380..31af29691b40 100644
--- a/core/modules/views_ui/src/ViewUI.php
+++ b/core/modules/views_ui/src/ViewUI.php
@@ -707,7 +707,7 @@ public function renderPreview($display_id, $args = array()) {
             $rows['statistics'][] = array('<strong>' . t('View render time') . '</strong>', t('@time ms', array('@time' => intval($this->executable->render_time * 100000) / 100)));
 
           }
-          \Drupal::moduleHandler()->alter('views_preview_info', $rows, $this);
+          \Drupal::moduleHandler()->alter('views_preview_info', $rows, $this->executable);
         }
         else {
           // No query was run. Display that information in place of either the
diff --git a/core/modules/views_ui/tests/modules/views_ui_test/views_ui_test.info.yml b/core/modules/views_ui/tests/modules/views_ui_test/views_ui_test.info.yml
new file mode 100644
index 000000000000..93ba44e64bf3
--- /dev/null
+++ b/core/modules/views_ui/tests/modules/views_ui_test/views_ui_test.info.yml
@@ -0,0 +1,8 @@
+name: 'Views UI Test'
+type: module
+description: 'Test module for Views UI.'
+package: Testing
+version: VERSION
+core: 8.x
+dependencies:
+  - views_ui
diff --git a/core/modules/views_ui/tests/modules/views_ui_test/views_ui_test.module b/core/modules/views_ui/tests/modules/views_ui_test/views_ui_test.module
new file mode 100644
index 000000000000..f68c40bdb2c4
--- /dev/null
+++ b/core/modules/views_ui/tests/modules/views_ui_test/views_ui_test.module
@@ -0,0 +1,17 @@
+<?php
+
+/**
+ * @file
+ * Helper module for Views UI tests.
+ */
+
+/**
+ * Implements hook_views_preview_info_alter().
+ *
+ * Add a row count row to the live preview area.
+ */
+function views_ui_test_views_preview_info_alter(&$rows, $view) {
+  $rows['query'][] = array(
+    t('Test row count'), count($view->result),
+  );
+}
-- 
GitLab