Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
4f6113f5
Commit
4f6113f5
authored
May 24, 2013
by
Dries
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#1987952
by brantwynn, Freemantus: Fixed Order of rendered blocks is wrong.
parent
8dc1fab2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
0 deletions
+67
-0
core/modules/block/block.module
core/modules/block/block.module
+4
-0
core/modules/block/lib/Drupal/block/Tests/BlockRenderOrderTest.php
...les/block/lib/Drupal/block/Tests/BlockRenderOrderTest.php
+63
-0
No files found.
core/modules/block/block.module
View file @
4f6113f5
...
...
@@ -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
];
}
...
...
core/modules/block/lib/Drupal/block/Tests/BlockRenderOrderTest.php
0 → 100644
View file @
4f6113f5
<?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.'
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment