Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
221
Merge Requests
221
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
6a30c869
Commit
6a30c869
authored
Sep 28, 2011
by
catch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#1283892
by tim.plunkett, chx: Let Render API fail in a tale-telling way on invalid element.
parent
398b181e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
4 deletions
+50
-4
includes/common.inc
includes/common.inc
+10
-3
modules/menu/menu.admin.inc
modules/menu/menu.admin.inc
+1
-1
modules/simpletest/tests/common.test
modules/simpletest/tests/common.test
+17
-0
modules/simpletest/tests/common_test.module
modules/simpletest/tests/common_test.module
+22
-0
No files found.
includes/common.inc
View file @
6a30c869
...
@@ -6145,11 +6145,18 @@ function element_children(&$elements, $sort = FALSE) {
...
@@ -6145,11 +6145,18 @@ function element_children(&$elements, $sort = FALSE) {
$sortable
=
FALSE
;
$sortable
=
FALSE
;
foreach
(
$elements
as
$key
=>
$value
)
{
foreach
(
$elements
as
$key
=>
$value
)
{
if
(
$key
===
''
||
$key
[
0
]
!==
'#'
)
{
if
(
$key
===
''
||
$key
[
0
]
!==
'#'
)
{
if
(
is_array
(
$value
))
{
$children
[
$key
]
=
$value
;
$children
[
$key
]
=
$value
;
if
(
is_array
(
$value
)
&&
isset
(
$value
[
'#weight'
]))
{
if
(
isset
(
$value
[
'#weight'
]))
{
$sortable
=
TRUE
;
$sortable
=
TRUE
;
}
}
}
}
// Only trigger an error if the value is not null.
// @see http://drupal.org/node/1283892
elseif
(
isset
(
$value
))
{
trigger_error
(
t
(
'"@key" is an invalid render array key'
,
array
(
'@key'
=>
$key
)),
E_USER_ERROR
);
}
}
}
}
// Sort the children if necessary.
// Sort the children if necessary.
if
(
$sort
&&
$sortable
)
{
if
(
$sort
&&
$sortable
)
{
...
...
modules/menu/menu.admin.inc
View file @
6a30c869
...
@@ -158,7 +158,7 @@ function menu_overview_form_submit($form, &$form_state) {
...
@@ -158,7 +158,7 @@ function menu_overview_form_submit($form, &$form_state) {
// are sent by $_POST, ensuring parents are saved first, then their children.
// are sent by $_POST, ensuring parents are saved first, then their children.
// See http://drupal.org/node/181126#comment-632270
// See http://drupal.org/node/181126#comment-632270
$order
=
array_flip
(
array_keys
(
$form_state
[
'input'
]));
// Get the $_POST order.
$order
=
array_flip
(
array_keys
(
$form_state
[
'input'
]));
// Get the $_POST order.
$form
=
array_
merge
(
$order
,
$form
);
// Update our original form with the new order.
$form
=
array_
intersect_key
(
array_merge
(
$order
,
$form
)
,
$form
);
// Update our original form with the new order.
$updated_items
=
array
();
$updated_items
=
array
();
$fields
=
array
(
'weight'
,
'plid'
);
$fields
=
array
(
'weight'
,
'plid'
);
...
...
modules/simpletest/tests/common.test
View file @
6a30c869
...
@@ -1724,6 +1724,23 @@ class DrupalRenderTestCase extends DrupalWebTestCase {
...
@@ -1724,6 +1724,23 @@ class DrupalRenderTestCase extends DrupalWebTestCase {
));
));
}
}
/**
* Test rendering elements with invalid keys.
*/
function
testDrupalRenderInvalidKeys
()
{
$error
=
array
(
'%type'
=>
'User error'
,
'!message'
=>
'"child" is an invalid render array key'
,
'%function'
=>
'element_children()'
,
);
$message
=
t
(
'%type: !message in %function (line '
,
$error
);
variable_set
(
'error_level'
,
ERROR_REPORTING_DISPLAY_ALL
);
$this
->
drupalGet
(
'common-test/drupal-render-invalid-keys'
);
$this
->
assertResponse
(
200
,
t
(
'Received expected HTTP status code.'
));
$this
->
assertRaw
(
$message
,
t
(
'Found error message: !message.'
,
array
(
'!message'
=>
$message
)));
}
protected
function
assertRenderedElement
(
array
$element
,
$xpath
,
array
$xpath_args
=
array
())
{
protected
function
assertRenderedElement
(
array
$element
,
$xpath
,
array
$xpath_args
=
array
())
{
$original_element
=
$element
;
$original_element
=
$element
;
$this
->
drupalSetContent
(
drupal_render
(
$element
));
$this
->
drupalSetContent
(
drupal_render
(
$element
));
...
...
modules/simpletest/tests/common_test.module
View file @
6a30c869
...
@@ -52,6 +52,12 @@ function common_test_menu() {
...
@@ -52,6 +52,12 @@ function common_test_menu() {
'access arguments'
=>
array
(
'access content'
),
'access arguments'
=>
array
(
'access content'
),
'type'
=>
MENU_CALLBACK
,
'type'
=>
MENU_CALLBACK
,
);
);
$items
[
'common-test/drupal-render-invalid-keys'
]
=
array
(
'title'
=>
'Drupal Render'
,
'page callback'
=>
'common_test_drupal_render_invalid_keys'
,
'access arguments'
=>
array
(
'access content'
),
'type'
=>
MENU_CALLBACK
,
);
return
$items
;
return
$items
;
}
}
...
@@ -100,6 +106,22 @@ function common_test_destination() {
...
@@ -100,6 +106,22 @@ function common_test_destination() {
print
"The destination: "
.
check_plain
(
$destination
[
'destination'
]);
print
"The destination: "
.
check_plain
(
$destination
[
'destination'
]);
}
}
/**
* Render an element with an invalid render array key.
*/
function
common_test_drupal_render_invalid_keys
()
{
define
(
'SIMPLETEST_COLLECT_ERRORS'
,
FALSE
);
// Keys that begin with # may contain a value of any type, otherwise they must
// contain arrays.
$key
=
'child'
;
$value
=
'This should be an array.'
;
$element
=
array
(
$key
=>
$value
,
);
return
drupal_render
(
$element
);
}
/**
/**
* Implements hook_TYPE_alter().
* Implements hook_TYPE_alter().
*/
*/
...
...
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