diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/area/ListingEmpty.php b/core/modules/node/lib/Drupal/node/Plugin/views/area/ListingEmpty.php index c669c3e5055..acacb23d443 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/area/ListingEmpty.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/area/ListingEmpty.php @@ -37,8 +37,9 @@ class ListingEmpty extends AreaPluginBase { ) , '#access' => _node_add_access() ); - return drupal_render($element); + return $element; } + return array(); } } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/area/AreaPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/area/AreaPluginBase.php index fa394aeacda..62ac0c8321d 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/area/AreaPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/area/AreaPluginBase.php @@ -159,7 +159,13 @@ abstract class AreaPluginBase extends HandlerBase { } /** - * Render the area + * Render the area. + * + * @param bool $empty + * (optional) Indicator if view result is empty or not. Defaults to FALSE. + * + * @return array + * In any case we need a valid Drupal render array to return. */ public abstract function render($empty = FALSE); diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/area/Broken.php b/core/modules/views/lib/Drupal/views/Plugin/views/area/Broken.php index 772304c2dcb..39fc9d04e8a 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/area/Broken.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/area/Broken.php @@ -27,7 +27,13 @@ class Broken extends AreaPluginBase { public function defineOptions() { return array(); } public function ensureMyTable() { /* No table to ensure! */ } public function query($group_by = FALSE) { /* No query to run */ } - function render($empty = FALSE) { return ''; } + /** + * Implements \Drupal\views\Plugin\views\area\AreaPluginBase::render(). + */ + public function render($empty = FALSE) { + // Simply render nothing by returning an empty render array. + return array(); + } public function buildOptionsForm(&$form, &$form_state) { $form['markup'] = array( '#markup' => '
' . t('The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.') . '
', diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/area/Entity.php b/core/modules/views/lib/Drupal/views/Plugin/views/area/Entity.php index db5a40cb9ab..200cecb2b63 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/area/Entity.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/area/Entity.php @@ -103,13 +103,11 @@ class Entity extends AreaPluginBase { } $entity_id = $this->globalTokenReplace($entity_id); if ($entity = entity_load($this->entityType, $entity_id)) { - $build = entity_view($entity, $this->options['view_mode']); - // @todo Support to just return a render array. - return drupal_render($build); + return entity_view($entity, $this->options['view_mode']); } } - return ''; + return array(); } } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php b/core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php index e4d11bd9b78..67bd9c79650 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php @@ -57,12 +57,12 @@ class Result extends AreaPluginBase { /** - * Find out the information to render. + * Implements \Drupal\views\Plugin\views\area\AreaPluginBase::render(). */ function render($empty = FALSE) { // Must have options and does not work on summaries. if (!isset($this->options['content']) || $this->view->plugin_name == 'default_summary') { - return; + return array(); } $output = ''; $format = $this->options['content']; @@ -99,7 +99,10 @@ class Result extends AreaPluginBase { if (!empty($total)) { $output .= filter_xss_admin(str_replace(array_keys($replacements), array_values($replacements), $format)); } - return $output; + // Return as render array. + return array( + '#markup' => $output, + ); } } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/area/Text.php b/core/modules/views/lib/Drupal/views/Plugin/views/area/Text.php index 38c12c7898c..74959332f3c 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/area/Text.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/area/Text.php @@ -49,12 +49,18 @@ class Text extends AreaPluginBase { parent::submitOptionsForm($form, $form_state); } + /** + * Implements \Drupal\views\Plugin\views\area\AreaPluginBase::render(). + */ function render($empty = FALSE) { $format = isset($this->options['format']) ? $this->options['format'] : filter_default_format(); if (!$empty || !empty($this->options['empty'])) { - return $this->render_textarea($this->options['content'], $format); + return array( + '#markup' => $this->render_textarea($this->options['content'], $format), + ); } - return ''; + + return array(); } /** diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/area/TextCustom.php b/core/modules/views/lib/Drupal/views/Plugin/views/area/TextCustom.php index 782ab9afd84..754dd4fe713 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/area/TextCustom.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/area/TextCustom.php @@ -44,12 +44,17 @@ class TextCustom extends AreaPluginBase { public function submitOptionsForm(&$form, &$form_state) { } + /** + * Implements \Drupal\views\Plugin\views\area\AreaPluginBase::render(). + */ function render($empty = FALSE) { if (!$empty || !empty($this->options['empty'])) { - return $this->render_textarea($this->options['content']); + return array( + '#markup' => $this->render_textarea($this->options['content']), + ); } - return ''; + return array(); } /** diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/area/Title.php b/core/modules/views/lib/Drupal/views/Plugin/views/area/Title.php index 84b95e50a1d..61cb8e07ec1 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/area/Title.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/area/Title.php @@ -59,10 +59,11 @@ class Title extends AreaPluginBase { } /** - * Implements \Drupal\views\Plugins\views\area\AreaPluginBase::render(); + * Implements \Drupal\views\Plugin\views\area\AreaPluginBase::render(). */ public function render($empty = FALSE) { - // Do nothing for this handler. + // Do nothing for this handler by returning an empty render array. + return array(); } } 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 ffc94e7dd23..f4eba6abd9e 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 @@ -56,7 +56,7 @@ class View extends AreaPluginBase { } /** - * Render the area + * Implements \Drupal\views\Plugin\views\area\AreaPluginBase::render(). */ function render($empty = FALSE) { if (!empty($this->options['view_to_insert'])) { @@ -64,7 +64,7 @@ class View extends AreaPluginBase { $view = views_get_view($view_name); if (empty($view) || !$view->access($display_id)) { - return; + return array(); } $view->setDisplay($display_id); @@ -78,15 +78,21 @@ class View extends AreaPluginBase { 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 $view->preview($display_id, $this->view->args); + return array( + '#markup' => $view->preview($display_id, $this->view->args), + ); } else { - return $view->preview($display_id); + return array( + '#markup' => $view->preview($display_id), + ); } } } - return ''; + return array(); } } 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 ab19e11d796..a252414235c 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 @@ -2466,10 +2466,22 @@ abstract class DisplayPluginBase extends PluginBase { return $element; } + /** + * Render one of the available areas. + * + * @param string $area + * Identifier of the specific area to render. + * @param bool $empty + * (optional) Indicator whether or not the view result is empty. Defaults to + * FALSE + * + * @return array + * A render array for the given area. + */ public function renderArea($area, $empty = FALSE) { - $return = ''; - foreach ($this->getHandlers($area) as $area) { - $return .= $area->render($empty); + $return = array(); + foreach ($this->getHandlers($area) as $key => $area_handler) { + $return[$key] = $area_handler->render($empty); } return $return; } diff --git a/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTextTest.php b/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTextTest.php index 525f3271fea..82057983bdc 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTextTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTextTest.php @@ -58,16 +58,16 @@ class AreaTextTest extends ViewUnitTestBase { $this->executeView($view); $view->display_handler->handlers['header']['area']->options['format'] = $this->randomString(); - $this->assertEqual(NULL, $view->display_handler->handlers['header']['area']->render(), 'Non existant format should return nothing'); + $this->assertEqual(array('#markup' => ''), $view->display_handler->handlers['header']['area']->render(), 'Non existant format should return empty markup.'); $view->display_handler->handlers['header']['area']->options['format'] = filter_default_format(); - $this->assertEqual(check_markup($string), $view->display_handler->handlers['header']['area']->render(), 'Existant format should return something'); + $this->assertEqual(array('#markup' => check_markup($string)), $view->display_handler->handlers['header']['area']->render(), 'Existant format should return something'); // Empty results, and it shouldn't be displayed . - $this->assertEqual('', $view->display_handler->handlers['header']['area']->render(TRUE), 'No result should lead to no header'); + $this->assertEqual(array(), $view->display_handler->handlers['header']['area']->render(TRUE), 'No result should lead to no header'); // Empty results, and it should be displayed. $view->display_handler->handlers['header']['area']->options['empty'] = TRUE; - $this->assertEqual(check_markup($string), $view->display_handler->handlers['header']['area']->render(TRUE), 'No result, but empty enabled lead to a full header'); + $this->assertEqual(array('#markup' => check_markup($string)), $view->display_handler->handlers['header']['area']->render(TRUE), 'No result, but empty enabled lead to a full header'); } } diff --git a/core/modules/views/templates/views-view.tpl.php b/core/modules/views/templates/views-view.tpl.php index 05ce4c7b5b4..ca8faef17cc 100644 --- a/core/modules/views/templates/views-view.tpl.php +++ b/core/modules/views/templates/views-view.tpl.php @@ -35,7 +35,7 @@
- +
@@ -57,7 +57,7 @@
- +
@@ -77,7 +77,7 @@ diff --git a/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/area/TestExample.php b/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/area/TestExample.php index ea53407449e..38ec004a282 100644 --- a/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/area/TestExample.php +++ b/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/area/TestExample.php @@ -40,12 +40,15 @@ class TestExample extends AreaPluginBase { } /** - * Overrides Drupal\views\Plugin\views\area\AreaPluginBase::render(). + * Implements \Drupal\views\Plugin\views\area\AreaPluginBase::render(). */ public function render($empty = FALSE) { if (!$empty || !empty($this->options['empty'])) { - return $this->globalTokenReplace($this->options['string']); + return array( + '#markup' => $this->globalTokenReplace($this->options['string']), + ); } + return array(); } }