Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
f5a4f24b
Commit
f5a4f24b
authored
Jan 27, 2009
by
Angie Byron
Browse files
#364407
by catch: Fix drupal_render() sorting (with tests).
parent
2e8ca690
Changes
2
Hide whitespace changes
Inline
Side-by-side
includes/common.inc
View file @
f5a4f24b
...
...
@@ -3289,12 +3289,10 @@ function drupal_render(&$elements) {
}
}
// Sort the elements by weight, if there are any children, and they have not
// been sorted elsewhere already, for example by a database query. Pre-sorted
// elements should have $elements['#sorted'] set to TRUE to avoid unnecessary
// calls to uasort().
$children
=
!
isset
(
$elements
[
'#children'
])
?
element_children
(
$elements
)
:
FALSE
;
if
(
empty
(
$elements
[
'#sorted'
])
&&
$children
)
{
// Sort the elements by weight if they have not been sorted elsewhere already,
// for example by a database query. Pre-sorted elements should have
// $elements['#sorted'] set to TRUE to avoid unnecessary calls to uasort().
if
(
empty
(
$elements
[
'#sorted'
]))
{
uasort
(
$elements
,
'element_sort'
);
$elements
[
'#sorted'
]
=
TRUE
;
}
...
...
@@ -3302,6 +3300,7 @@ function drupal_render(&$elements) {
$content
=
''
;
$elements
+=
array
(
'#title'
=>
NULL
,
'#description'
=>
NULL
);
if
(
!
isset
(
$elements
[
'#children'
]))
{
$children
=
element_children
(
$elements
);
// Render all the children that use a theme function.
if
(
isset
(
$elements
[
'#theme'
])
&&
empty
(
$elements
[
'#theme_used'
]))
{
$elements
[
'#theme_used'
]
=
TRUE
;
...
...
modules/simpletest/tests/common.test
View file @
f5a4f24b
...
...
@@ -480,6 +480,42 @@ class JavaScriptTestCase extends DrupalWebTestCase {
}
}
/**
* Tests for drupal_render().
*/
class
DrupalRenderUnitTestCase
extends
DrupalWebTestCase
{
function
getInfo
()
{
return
array
(
'name'
=>
t
(
'Drupal render'
),
'description'
=>
t
(
'Performs unit tests on drupal_render().'
),
'group'
=>
t
(
'System'
),
);
}
/**
* Test sorting by weight.
*/
function
testDrupalRenderSorting
()
{
$first
=
$this
->
randomName
();
$second
=
$this
->
randomName
();
// Build an array with '#weight' set for each element.
$elements
=
array
(
'second'
=>
array
(
'#weight'
=>
10
,
'#markup'
=>
$second
,
),
'first'
=>
array
(
'#weight'
=>
0
,
'#markup'
=>
$first
,
),
);
$output
=
drupal_render
(
$elements
);
// The lowest weight element should appear last in $output.
$this
->
assertTrue
(
strpos
(
$output
,
$second
)
>
strpos
(
$output
,
$first
),
t
(
'Elements were sorted correctly by weight'
));
}
}
/**
* Tests Drupal error and exception handlers.
*/
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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