summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDries2013-05-24 18:40:46 (GMT)
committer Dries2013-05-24 18:40:46 (GMT)
commit4f6113f56639caf2881188f2a6f5144273ae1399 (patch)
treef795efe6c39c832888a5c7fac8036354fc1000c0
parent8dc1fab2c7950f15c2fd517f8e9b075f56caa3d8 (diff)
Issue #1987952 by brantwynn, Freemantus: Fixed Order of rendered blocks is wrong.
-rw-r--r--core/modules/block/block.module4
-rw-r--r--core/modules/block/lib/Drupal/block/Tests/BlockRenderOrderTest.php63
2 files changed, 67 insertions, 0 deletions
diff --git a/core/modules/block/block.module b/core/modules/block/block.module
index 8b24c9d..9e93550 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 0000000..d69d844
--- /dev/null
+++ b/core/modules/block/lib/Drupal/block/Tests/BlockRenderOrderTest.php
@@ -0,0 +1,63 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\block\Tests\BlockRenderOrderTest.
+ */
+
+namespace Drupal\block\Tests;
+
+use Drupal\simpletest\WebTestBase;
+
+/**
+ * Tests block HTML ID validity.
+ */
+class BlockRenderOrderTest extends WebTestBase {
+
+ /**
+ * Modules to enable.
+ *
+ * @var array
+ */
+ public static $modules = array('block', 'block_test', 'search');
+
+ public static function getInfo() {
+ return array(
+ 'name' => '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('<h2>' . $settings[0] . '</h2>', '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.');
+ }
+}