diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 8b24c9d91d6e136736ecc21cdd50598b8f8c769f..9e93550eddfef18d6233d045f08d0d29fc0bf2fb 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -465,6 +465,10 @@ function block_list($region) { $blocks[$region] = array(); } + uasort($blocks[$region], function($first, $second) { + return $first->weight < $second->weight ? ($first->weight === $second->weight ? 0 : -1) : 1; + }); + return $blocks[$region]; } diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockRenderOrderTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockRenderOrderTest.php new file mode 100644 index 0000000000000000000000000000000000000000..d69d844f6a17994a3cf4e711b588168abe1354b1 --- /dev/null +++ b/core/modules/block/lib/Drupal/block/Tests/BlockRenderOrderTest.php @@ -0,0 +1,63 @@ + 'Block Render Order', + 'description' => 'Test blocks are being rendered in order by weight.', + 'group' => 'Block', + ); + } + + function setUp() { + parent::setUp(); + // Create a test user. + $end_user = $this->drupalCreateUser(array( + 'access content', + 'search content', + )); + $this->drupalLogin($end_user); + } + + /** + * Tests the render order of the blocks. + */ + function testBlockRenderOrder() { + //Enable test blocks and place them in the same region. + $blocks = array(array($this->randomName(8), 'system_powered_by_block'), array($this->randomName(8), 'search_form_block')); + foreach ($blocks as $weight => $settings) { + $this->drupalPlaceBlock($settings[1], array( + 'label' => $settings[0], + 'weight' => $weight, + 'region' => 'header', + )); + } + $this->drupalGet(''); + $test_content = $this->drupalGetContent(''); + foreach ($blocks as $weight => $settings) { + $this->assertRaw('

' . $settings[0] . '

', 'Block "' . $settings[0] . '" is in place.'); + $position[$weight] = strpos($test_content, $settings[0]); + } + $this->assertTrue($position[0] < $position[1], 'The blocks are rendered in the correct order.'); + } +}