diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php index a049afc..3bc60e3 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php @@ -2217,7 +2217,9 @@ public function elementPreRender(array $element) { public function renderArea($area, $empty = FALSE) { $return = array(); foreach ($this->getHandlers($area) as $key => $area_handler) { - $return[$key] = $area_handler->render($empty); + if ($area_render = $area_handler->render($empty)) { + $return[$key] = $area_render; + } } return $return; } diff --git a/core/modules/views/src/Tests/Handler/AreaTest.php b/core/modules/views/src/Tests/Handler/AreaTest.php index de41c3d..953f737 100644 --- a/core/modules/views/src/Tests/Handler/AreaTest.php +++ b/core/modules/views/src/Tests/Handler/AreaTest.php @@ -116,6 +116,44 @@ public function testRenderArea() { } /** + * Tests that the header and footer areas are not rendered if empty. + */ + public function testRenderEmptyHeaderFooter() { + $header_string = '

' . $this->randomMachineName() . '

'; + $footer_string = '

' . $this->randomMachineName() . '

'; + $empty_string = '

' . $this->randomMachineName() . '

'; + + $view = Views::getView('test_example_area'); + $view->initHandlers(); + + $view->empty['test_example']->options['string'] = $empty_string; + + $output = $view->preview(); + $html = $this->container->get('renderer')->renderRoot($output); + $this->setRawContent($html); + + $xpath = '//div[contains(@class, :class)]'; + $this->assertEqual(0, count($this->xpath($xpath, [':class' => 'view-header']))); + $this->assertEqual(0, count($this->xpath($xpath, [':class' => 'view-footer']))); + + $view->header['test_example']->options['string'] = $header_string; + $view->header['test_example']->options['empty'] = TRUE; + + $view->footer['test_example']->options['string'] = $footer_string; + $view->footer['test_example']->options['empty'] = TRUE; + + $view->empty['test_example']->options['string'] = $empty_string; + + $output = $view->preview(); + $html = $this->container->get('renderer')->renderRoot($output); + $this->setRawContent($html); + + $xpath = '//div[contains(@class, :class)]'; + $this->assertEqual(1, count($this->xpath($xpath, [':class' => 'view-header']))); + $this->assertEqual(1, count($this->xpath($xpath, [':class' => 'view-footer']))); + } + + /** * Tests the access for an area. */ public function testAreaAccess() {