Commit 366afa1b authored by webchick's avatar webchick
Browse files

Issue #1861814 by tim.plunkett, dawehner: Fixed All views are rendered twice.

parent bebb3459
<?php
/**
* @file
* Contains \Drupal\views\Tests\ViewRenderTest.
*/
namespace Drupal\views\Tests;
use Drupal\views\Tests\ViewTestBase;
class ViewRenderTest extends ViewTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_view_render');
public static function getInfo() {
return array(
'name' => 'View render tests',
'description' => 'Tests the general rendering of a view.',
'group' => 'Views'
);
}
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
}
/**
* Tests render functionality.
*/
public function testRender() {
$GLOBALS['views_render.test'] = 0;
// Make sure that the rendering just calls the preprocess function once.
$view = views_get_view('test_view_render');
$view->preview();
$this->assertEqual($GLOBALS['views_render.test'], 1);
}
}
api_version: '3.0'
base_table: views_test_data
core: '8'
description: ''
disabled: '0'
display:
default:
display_options:
defaults:
fields: '0'
pager: '0'
pager_options: '0'
sorts: '0'
fields:
age:
field: age
id: age
relationship: none
table: views_test_data
id:
field: id
id: id
relationship: none
table: views_test_data
name:
field: name
id: name
relationship: none
table: views_test_data
pager:
options:
offset: '0'
type: none
pager_options: { }
sorts:
id:
field: id
id: id
order: ASC
relationship: none
table: views_test_data
style:
type: table
display_plugin: default
display_title: Master
id: default
position: '0'
human_name: ''
name: test_view_render
tag: ''
......@@ -78,6 +78,9 @@ function views_test_data_handler_test_access_callback_argument($argument = FALSE
/**
* Implements hook_views_pre_render().
*
* @see \Drupal\views\Tests\Plugin\CacheTest
* @see \Drupal\views\Tests\Plugin\RenderTest
*/
function views_test_data_views_pre_render(ViewExecutable $view) {
if ($view->storage->get('name') == 'test_cache_header_storage') {
......@@ -86,6 +89,16 @@ function views_test_data_views_pre_render(ViewExecutable $view) {
$view->element['#attached']['css'][] = "$path/views_cache.test.css";
$view->build_info['pre_render_called'] = TRUE;
}
}
/**
* Implements hook_preprocess_HOOK() for views-view-table.tpl.php.
*/
function views_test_data_preprocess_views_view_table(&$variables) {
if ($variables['view']->storage->get('name') == 'test_view_render') {
$GLOBALS['views_render.test']++;
}
}
/**
......
......@@ -72,11 +72,7 @@ function template_preprocess_views_view(&$vars) {
$vars['attributes']['class'][] = $vars['css_class'];
}
// Render the rows render array to check for contents.
$rows = $vars['rows'];
$rows = drupal_render($rows);
$empty = empty($rows);
$empty = empty($view->result);
$vars['header'] = $view->display_handler->renderArea('header', $empty);
$vars['footer'] = $view->display_handler->renderArea('footer', $empty);
$vars['empty'] = $empty ? $view->display_handler->renderArea('empty', $empty) : FALSE;
......@@ -149,6 +145,9 @@ function template_preprocess_views_view(&$vars) {
// If form fields were found in the View, reformat the View output as a form.
if (views_view_has_form_elements($view)) {
// Copy the rows so as not to modify them by reference when rendering.
$rows = $vars['rows'];
$rows = drupal_render($rows);
$output = !empty($rows) ? $rows : $vars['empty'];
$form = drupal_get_form(views_form_id($view), $view, $output);
// The form is requesting that all non-essential views elements be hidden,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment