diff --git a/core/modules/history/lib/Drupal/history/Tests/Views/HistoryTimestampTest.php b/core/modules/history/lib/Drupal/history/Tests/Views/HistoryTimestampTest.php index d92d02488fd8f2fb1baea43c1071727b0b2bbfe5..182174c42e91d1a46885c46b3e57c80f102879ea 100644 --- a/core/modules/history/lib/Drupal/history/Tests/Views/HistoryTimestampTest.php +++ b/core/modules/history/lib/Drupal/history/Tests/Views/HistoryTimestampTest.php @@ -76,7 +76,7 @@ public function testHandlers() { $this->executeView($view); $this->assertEqual(count($view->result), 2); $output = $view->preview(); - $this->drupalSetContent($output); + $this->drupalSetContent(drupal_render($output)); $result = $this->xpath('//span[@class=:class]', array(':class' => 'marker')); $this->assertEqual(count($result), 1, 'Just one node is marked as new'); diff --git a/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php b/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php index 3496ee0192cff14356fd96823c11bdcd01c1e370..e7e38719d94ab83754e4ef4777e0593a076ff24f 100644 --- a/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php +++ b/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php @@ -202,20 +202,24 @@ public function optionsSummary(&$categories, &$options) { public function execute() { parent::execute(); - return new Response($this->view->render(), 200, array('Content-type' => $this->getMimeType())); + $output = $this->view->render(); + return new Response(drupal_render($output), 200, array('Content-type' => $this->getMimeType())); } /** * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::render(). */ public function render() { - $output = $this->view->style_plugin->render(); + $build = array(); + $build['#markup'] = $this->view->style_plugin->render(); + // Wrap the output in a pre tag if this is for a live preview. if (!empty($this->view->live_preview)) { - return '<pre>' . $output . '</pre>'; + $build['#prefix'] = '<pre>'; + $build['#suffix'] = '</pre>'; } - return $output; + return $build; } /** diff --git a/core/modules/rest/lib/Drupal/rest/Tests/Views/StyleSerializerTest.php b/core/modules/rest/lib/Drupal/rest/Tests/Views/StyleSerializerTest.php index c38db82e8eb1de0160501841384a09384741f132..9bdfbbea2c26abf63050c457faa8b42c7bf67b00 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/Views/StyleSerializerTest.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/Views/StyleSerializerTest.php @@ -100,7 +100,8 @@ public function testSerializerResponses() { $view->setDisplay('rest_export_1'); // Mock the request content type by setting it on the display handler. $view->display_handler->setContentType('json'); - $this->assertIdentical($actual_json, $view->preview(), 'The expected JSON preview output was found.'); + $output = $view->preview(); + $this->assertIdentical($actual_json, drupal_render($output), 'The expected JSON preview output was found.'); // Test a 403 callback. $this->drupalGet('test/serialize/denied'); diff --git a/core/modules/views/includes/ajax.inc b/core/modules/views/includes/ajax.inc index 65ecd3f914cfd12d2e8f8b4848e24b7de8f61ab0..d938e34b7379a752e2ab6b591db4810675828e36 100644 --- a/core/modules/views/includes/ajax.inc +++ b/core/modules/views/includes/ajax.inc @@ -80,7 +80,8 @@ function views_ajax() { // Reuse the same DOM id so it matches that in Drupal.settings. $view->dom_id = $dom_id; - $response->addCommand(new ReplaceCommand(".view-dom-id-$dom_id", $view->preview($display_id, $args))); + $preview = $view->preview($display_id, $args); + $response->addCommand(new ReplaceCommand(".view-dom-id-$dom_id", drupal_render($preview))); } return $response; } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/area/View.php b/core/modules/views/lib/Drupal/views/Plugin/views/area/View.php index f4eba6abd9ee1998d1d6dddb6fa0a50f922512ea..7d5e994b847d8107f20f246772561492e2cf6359 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/area/View.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/area/View.php @@ -78,17 +78,11 @@ function render($empty = FALSE) { drupal_set_message(t("Recursion detected in view @view display @display.", array('@view' => $view_name, '@display' => $display_id)), 'error'); } else { - // Current $view->preview() does not return a render array, so we have - // to build a markup out if it. if (!empty($this->options['inherit_arguments']) && !empty($this->view->args)) { - return array( - '#markup' => $view->preview($display_id, $this->view->args), - ); + return $view->preview($display_id, $this->view->args); } else { - return array( - '#markup' => $view->preview($display_id), - ); + return $view->preview($display_id); } } } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php index 8238287bb7da56d1aba5bf5c0a5d6a1e6d53245f..eb22ed29a468d127cee6e822e8b269e12d223fee 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php @@ -2549,8 +2549,7 @@ public function execute() { } * some other AJAXy reason. */ function preview() { - $element = $this->view->render(); - return drupal_render($element); + return $this->view->render(); } /** diff --git a/core/modules/views/lib/Drupal/views/Tests/Handler/AreaEntityTest.php b/core/modules/views/lib/Drupal/views/Tests/Handler/AreaEntityTest.php index d6656617b2f7f8db3b3a306dbff9ea8e51d93da0..9cf013439351a43c06255628a5b769af57ba8c43 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Handler/AreaEntityTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Handler/AreaEntityTest.php @@ -88,7 +88,8 @@ public function testEntityArea() { } $view = views_get_view('test_entity_area'); - $this->drupalSetContent($view->preview('default', array($entities[1]->id()))); + $preview = $view->preview('default', array($entities[1]->id())); + $this->drupalSetContent(drupal_render($preview)); $result = $this->xpath('//div[@class = "view-header"]'); $this->assertTrue(strpos(trim((string) $result[0]), $entities[0]->label()) !== FALSE, 'The rendered entity appears in the header of the view.'); @@ -104,7 +105,8 @@ public function testEntityArea() { $item['view_mode'] = 'test'; $view->setItem('default', 'header', 'entity_entity_test_render', $item); - $this->drupalSetContent($view->preview('default', array($entities[1]->id()))); + $preview = $view->preview('default', array($entities[1]->id())); + $this->drupalSetContent(drupal_render($preview)); $result = $this->xpath('//div[@class = "view-header"]'); $this->assertTrue(strpos(trim((string) $result[0]), $entities[0]->label()) !== FALSE, 'The rendered entity appears in the header of the view.'); diff --git a/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTest.php b/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTest.php index 21804c577a9f637afc770b853990b1c765b28a4b..1ee08da333e1ed43d89a612db9db2e8f9b18ec6e 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTest.php @@ -111,6 +111,7 @@ public function testRenderArea() { // Check whether the strings exists in the output. $output = $view->preview(); + $output = drupal_render($output); $this->assertTrue(strpos($output, $header_string) !== FALSE); $this->assertTrue(strpos($output, $footer_string) !== FALSE); $this->assertTrue(strpos($output, $empty_string) !== FALSE); @@ -149,6 +150,7 @@ public function testRenderAreaToken() { // Test we have the site:name token in the output. $output = $view->preview(); + $output = drupal_render($output); $expected = token_replace('[site:name]'); $this->assertTrue(strpos($output, $expected) !== FALSE); } diff --git a/core/modules/views/lib/Drupal/views/Tests/Handler/FieldUnitTest.php b/core/modules/views/lib/Drupal/views/Tests/Handler/FieldUnitTest.php index afff1b33d08199f46f1dd61fa4115fa3b56f20ef..5dfa29b4a1cf9ad4ba8fa3a0e2bf80e28a39c71d 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Handler/FieldUnitTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Handler/FieldUnitTest.php @@ -218,6 +218,7 @@ public function testExclude() { $view->field['name']->options['exclude'] = TRUE; $output = $view->preview(); + $output = drupal_render($output); foreach ($this->dataSet() as $entry) { $this->assertNotSubString($output, $entry['name']); } @@ -226,6 +227,7 @@ public function testExclude() { $view->field['name']->options['exclude'] = FALSE; $output = $view->preview(); + $output = drupal_render($output); foreach ($this->dataSet() as $entry) { $this->assertSubString($output, $entry['name']); } diff --git a/core/modules/views/lib/Drupal/views/Tests/Handler/FieldWebTest.php b/core/modules/views/lib/Drupal/views/Tests/Handler/FieldWebTest.php index 9d8c66e11c0af0ff0bdbe2fd27dd126959193c69..43acdabe08e0968d67a1e028177b437be4aebf24 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Handler/FieldWebTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Handler/FieldWebTest.php @@ -331,11 +331,13 @@ public function testFieldClasses() { $id_field->options['element_default_classes'] = FALSE; $output = $view->preview(); + $output = drupal_render($output); $this->assertFalse($this->xpathContent($output, '//div[contains(@class, :class)]', array(':class' => 'field-content'))); $this->assertFalse($this->xpathContent($output, '//div[contains(@class, :class)]', array(':class' => 'field-label'))); $id_field->options['element_default_classes'] = TRUE; $output = $view->preview(); + $output = drupal_render($output); // Per default the label and the element of the field are spans. $this->assertTrue($this->xpathContent($output, '//span[contains(@class, :class)]', array(':class' => 'field-content'))); $this->assertTrue($this->xpathContent($output, '//span[contains(@class, :class)]', array(':class' => 'views-label'))); @@ -351,11 +353,13 @@ public function testFieldClasses() { // Set a custom wrapper element css class. $id_field->options['element_wrapper_class'] = $random_class; $output = $view->preview(); + $output = drupal_render($output); $this->assertTrue($this->xpathContent($output, "//{$element_type}[contains(@class, :class)]", array(':class' => $random_class))); // Set no custom css class. $id_field->options['element_wrapper_class'] = ''; $output = $view->preview(); + $output = drupal_render($output); $this->assertFalse($this->xpathContent($output, "//{$element_type}[contains(@class, :class)]", array(':class' => $random_class))); $this->assertTrue($this->xpathContent($output, "//li[contains(@class, views-row)]/{$element_type}")); } @@ -369,11 +373,13 @@ public function testFieldClasses() { // Set a custom label element css class. $id_field->options['element_label_class'] = $random_class; $output = $view->preview(); + $output = drupal_render($output); $this->assertTrue($this->xpathContent($output, "//li[contains(@class, views-row)]//{$element_type}[contains(@class, :class)]", array(':class' => $random_class))); // Set no custom css class. $id_field->options['element_label_class'] = ''; $output = $view->preview(); + $output = drupal_render($output); $this->assertFalse($this->xpathContent($output, "//li[contains(@class, views-row)]//{$element_type}[contains(@class, :class)]", array(':class' => $random_class))); $this->assertTrue($this->xpathContent($output, "//li[contains(@class, views-row)]//{$element_type}")); } @@ -387,11 +393,13 @@ public function testFieldClasses() { // Set a custom label element css class. $id_field->options['element_class'] = $random_class; $output = $view->preview(); + $output = drupal_render($output); $this->assertTrue($this->xpathContent($output, "//li[contains(@class, views-row)]//div[contains(@class, views-field)]//{$element_type}[contains(@class, :class)]", array(':class' => $random_class))); // Set no custom css class. $id_field->options['element_class'] = ''; $output = $view->preview(); + $output = drupal_render($output); $this->assertFalse($this->xpathContent($output, "//li[contains(@class, views-row)]//div[contains(@class, views-field)]//{$element_type}[contains(@class, :class)]", array(':class' => $random_class))); $this->assertTrue($this->xpathContent($output, "//li[contains(@class, views-row)]//div[contains(@class, views-field)]//{$element_type}")); } diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/CacheTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/CacheTest.php index 6ac76d7d20f8317f0f7e2e72afd84a3693af5f4e..886d815298968a7d506cf36c0897a9315df1131d 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/CacheTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/CacheTest.php @@ -139,14 +139,16 @@ function testHeaderStorage() { ) )); - $view->preview(); + $output = $view->preview(); + drupal_render($output); unset($view->pre_render_called); drupal_static_reset('drupal_add_css'); drupal_static_reset('drupal_add_js'); $view->destroy(); $view->setDisplay(); - $view->preview(); + $output = $view->preview(); + drupal_render($output); $css = drupal_add_css(); $css_path = drupal_get_path('module', 'views_test_data') . '/views_cache.test.css'; $js_path = drupal_get_path('module', 'views_test_data') . '/views_cache.test.js'; @@ -166,14 +168,14 @@ function testHeaderStorage() { drupal_add_js($system_js_path); $view->destroy(); - $view->setDisplay(); - $view->preview(); + $output = $view->preview(); + drupal_render($output); drupal_static_reset('drupal_add_css'); drupal_static_reset('drupal_add_js'); $view->destroy(); - $view->setDisplay(); - $view->preview(); + $output = $view->preview(); + drupal_render($output); $css = drupal_add_css(); $js = drupal_add_js(); diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php index 6b023f78f0b22347eb1a5ef8961e68209d882fdd..4ccd11d6bbb469115ce3875568b3a3363a526e71 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php @@ -82,6 +82,7 @@ function testDisplayPlugin() { $this->assertIdentical($view->display_handler->getOption('test_option'), ''); $output = $view->preview(); + $output = drupal_render($output); $this->assertTrue(strpos($output, '<h1></h1>') !== FALSE, 'An empty value for test_option found in output.'); @@ -90,6 +91,7 @@ function testDisplayPlugin() { $view->save(); $output = $view->preview(); + $output = drupal_render($output); // Test we have our custom <h1> tag in the output of the view. $this->assertTrue(strpos($output, '<h1>Test option title</h1>') !== FALSE, 'The test_option value found in display output title.'); diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleMappingTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleMappingTest.php index f745a08e29356133b3ba39869ebec3b094f956fc..5cea609751d372567d6ffb11359a2193258be9b8 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleMappingTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleMappingTest.php @@ -54,7 +54,8 @@ public function testMappedOutput() { * The view rendered as HTML. */ protected function mappedOutputHelper($view) { - $rendered_output = $view->preview(); + $output = $view->preview(); + $rendered_output = drupal_render($output); $this->storeViewPreview($rendered_output); $rows = $this->elements->body->div->div->div; $data_set = $this->dataSet(); diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleTest.php index 2e5f4d2a83da6c0264c0df9133e6cc787bcd7714..f567068bb4130cdc26817cfa80a821a3f686ea2a 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleTest.php @@ -64,6 +64,7 @@ public function testStyle() { // rendered. $view->style_plugin->setOutput($random_text); $output = $view->preview(); + $output = drupal_render($output); $this->assertTrue(strpos($output, $random_text) !== FALSE, 'Take sure that the rendering of the style plugin appears in the output of the view.'); // This run use the test row plugin and render with it. @@ -86,6 +87,7 @@ public function testStyle() { $view->rowPlugin->setOutput($random_text); $output = $view->preview(); + $output = drupal_render($output); $this->assertTrue(strpos($output, $random_text) !== FALSE, 'Take sure that the rendering of the row plugin appears in the output of the view.'); } @@ -225,8 +227,8 @@ function testCustomRowClasses() { $random_name = $this->randomName(); $view->style_plugin->options['row_class'] = $random_name . " test-token-[name]"; - $rendered_output = $view->preview(); - $this->storeViewPreview($rendered_output); + $output = $view->preview(); + $this->storeViewPreview(drupal_render($output)); $rows = $this->elements->body->div->div->div; $count = 0; diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleUnformattedTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleUnformattedTest.php index 5348fbc76ab52eaa13fd1087e9163b1a71a8fc70..72d6a93684c41a6a17fdcad868ed6fdb16882e4b 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleUnformattedTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleUnformattedTest.php @@ -33,8 +33,8 @@ public static function getInfo() { function testDefaultRowClasses() { $view = views_get_view('test_view'); $view->setDisplay(); - $rendered_output = $view->preview(); - $this->storeViewPreview($rendered_output); + $output = $view->preview(); + $this->storeViewPreview(drupal_render($output)); $rows = $this->elements->body->div->div->div; $count = 0; diff --git a/core/modules/views/lib/Drupal/views/Tests/UI/CustomBooleanTest.php b/core/modules/views/lib/Drupal/views/Tests/UI/CustomBooleanTest.php index 0b2ff19b101783b4a8c933083cb8f6ee0a04fb10..2416c427fead200fb76ec0758a0b7079e1db521c 100644 --- a/core/modules/views/lib/Drupal/views/Tests/UI/CustomBooleanTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/UI/CustomBooleanTest.php @@ -103,6 +103,7 @@ public function testCustomOption() { $view = views_get_view('test_view'); $output = $view->preview(); + $output = drupal_render($output); $replacements = array('%type' => $type); $this->{$values['test']}(strpos($output, $values['true']), format_string('Expected custom boolean TRUE value in output for %type.', $replacements)); diff --git a/core/modules/views/lib/Drupal/views/Tests/ViewRenderTest.php b/core/modules/views/lib/Drupal/views/Tests/ViewRenderTest.php index d70468b334197965be63ce27e43bb7ff98854bd3..8c7f07138cf32091949792db4caff81a357f96f9 100644 --- a/core/modules/views/lib/Drupal/views/Tests/ViewRenderTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/ViewRenderTest.php @@ -41,7 +41,8 @@ public function testRender() { // Make sure that the rendering just calls the preprocess function once. $view = views_get_view('test_view_render'); - $view->preview(); + $output = $view->preview(); + drupal_render($output); $this->assertEqual(state()->get('views_render.test'), 1); } diff --git a/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/display/DisplayTest.php b/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/display/DisplayTest.php index 0c42a58e930f3601f0943eb4028a860a9f41b5c5..7497a8c6df10bf7a013bb2571fa576b52992e094 100644 --- a/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/display/DisplayTest.php +++ b/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/display/DisplayTest.php @@ -127,8 +127,7 @@ public function execute() { * Override so preview and execute are the same output. */ public function preview() { - $element = $this->execute(); - return drupal_render($element); + return $this->execute(); } } diff --git a/core/modules/views/views.module b/core/modules/views/views.module index cd313c6c80ef14625b16022597c867691a380c28..58a7f358a2ade9bffa676b9659c0f16474051f47 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -69,7 +69,7 @@ function views_pre_render_view_element($element) { $view = views_get_view($element['#name']); if ($view && $view->access($element['#display_id'])) { - $element['view']['#markup'] = $view->preview($element['#display_id'], $element['#arguments']); + $element['view'] = $view->preview($element['#display_id'], $element['#arguments']); } return $element; diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php index fe49e411c593c7f066829daf0feb2dbf86feb71d..e4bd339a0f25e6d8cfd87a1d655b6c4086d90d4d 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php @@ -585,6 +585,7 @@ public function renderPreview($display_id, $args = array()) { // Execute/get the view preview. $preview = $this->executable->preview($display_id, $args); + $preview = drupal_render($preview); if ($show_additional_queries) { $this->endQueryCapture();