diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php index 193e20b07e992a7788e74f524420eceffb74e13c..102718d4537398d65950d9f82625d24628663804 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php @@ -2217,6 +2217,10 @@ public function renderArea($area, $empty = FALSE) { $return = array(); foreach ($this->getHandlers($area) as $key => $area_handler) { if ($area_render = $area_handler->render($empty)) { + if (isset($area_handler->position)) { + // Fix weight of area. + $area_render['#weight'] = $area_handler->position; + } $return[$key] = $area_render; } } diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_area_order.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_area_order.yml new file mode 100644 index 0000000000000000000000000000000000000000..3a562dfef984e700c2254521294f2fa96657c179 --- /dev/null +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_area_order.yml @@ -0,0 +1,53 @@ +langcode: en +status: true +id: test_area_order +label: '' +module: views +description: '' +tag: '' +base_table: views_test_data +base_field: nid +core: '8' +display: + default: + display_options: + defaults: + fields: false + pager: false + sorts: false + header: + entity_block_2: + field: entity_block + id: entity_block + table: views + target: 'bartik_powered' + view_mode: full + plugin_id: entity + entity_block_1: + field: entity_block + id: entity_block + table: views + target: 'bartik_branding' + view_mode: full + plugin_id: entity + fields: + id: + field: id + id: id + relationship: none + table: views_test_data + plugin_id: numeric + arguments: + id: + id: id + table: views_test_data + field: id + plugin_id: numeric + pager: + options: + offset: 0 + type: none + display_plugin: default + display_title: Master + id: default + position: 0 diff --git a/core/modules/views/tests/src/Kernel/Handler/AreaOrderTest.php b/core/modules/views/tests/src/Kernel/Handler/AreaOrderTest.php new file mode 100644 index 0000000000000000000000000000000000000000..457c63579bf5c7011e266c19e63f7ee949a0f738 --- /dev/null +++ b/core/modules/views/tests/src/Kernel/Handler/AreaOrderTest.php @@ -0,0 +1,76 @@ +<?php + +namespace Drupal\Tests\views\Kernel\Handler; + +use Drupal\block\Entity\Block; +use Drupal\Tests\views\Kernel\ViewsKernelTestBase; +use Drupal\views\Views; + +/** + * Tests the view area handler. + * + * @group views + * @see \Drupal\views\Plugin\views\area\View + */ +class AreaOrderTest extends ViewsKernelTestBase { + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = array('user', 'block'); + + /** + * Views used by this test. + * + * @var array + */ + public static $testViews = array('test_area_order'); + + /** + * {@inheritdoc} + */ + protected function setUpFixtures() { + Block::create( + [ + 'id' => 'bartik_branding', + 'theme' => 'bartik', + 'plugin' => 'system_branding_block', + 'weight' => 1, + ] + )->save(); + + Block::create( + [ + 'id' => 'bartik_powered', + 'theme' => 'bartik', + 'plugin' => 'system_powered_by_block', + 'weight' => 2, + ] + )->save(); + + parent::setUpFixtures(); + } + + /** + * Tests the order of the handlers. + */ + public function testAreaOrder() { + $renderer = $this->container->get('renderer'); + $view = Views::getView('test_area_order'); + $renderable = $view->buildRenderable(); + $output = $this->render($renderable); + + $position_powered = strpos($output, 'block-bartik-powered'); + $position_branding = strpos($output, 'block-bartik-branding'); + + $this->assertNotEquals(0, $position_powered, 'ID bartik-powered found.'); + $this->assertNotEquals(0, $position_branding, 'ID bartik-branding found'); + + // Make sure "powered" is before "branding", so it reflects the position + // in the configuration, and not the weight of the blocks. + $this->assertTrue($position_powered < $position_branding, 'Block bartik-powered is positioned before block bartik-branding'); + } + +}