Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
24296577
Commit
24296577
authored
Oct 29, 2013
by
webchick
Browse files
Issue
#2120807
by Mark Carver: Add empty option to item_list().
parent
dac79f29
Changes
2
Hide whitespace changes
Inline
Side-by-side
core/includes/theme.inc
View file @
24296577
...
...
@@ -2244,6 +2244,8 @@ function template_preprocess_item_list(&$variables) {
* - title: The title of the list.
* - list_type: The type of HTML list (e.g. "ul", "ol").
* - attributes: The attributes applied to the list element.
* - empty: A message to display when there are no items. Allowed value is a
* string or render array.
*/
function
theme_item_list
(
$variables
)
{
$items
=
$variables
[
'items'
];
...
...
@@ -2277,6 +2279,9 @@ function theme_item_list($variables) {
}
$output
.
=
"</
$list_type
>"
;
}
elseif
(
!
empty
(
$variables
[
'empty'
]))
{
$output
.
=
render
(
$variables
[
'empty'
]);
}
// Only output the list container and title, if there are any list items.
// Check to see whether the block title exists before adding a header.
...
...
@@ -3040,7 +3045,7 @@ function drupal_common_theme() {
'variables'
=>
array
(
'status'
=>
MARK_NEW
),
),
'item_list'
=>
array
(
'variables'
=>
array
(
'items'
=>
array
(),
'title'
=>
''
,
'list_type'
=>
'ul'
,
'attributes'
=>
array
()),
'variables'
=>
array
(
'items'
=>
array
(),
'title'
=>
''
,
'list_type'
=>
'ul'
,
'attributes'
=>
array
()
,
'empty'
=>
NULL
),
),
'feed_icon'
=>
array
(
'variables'
=>
array
(
'url'
=>
NULL
,
'title'
=>
NULL
),
...
...
core/modules/system/lib/Drupal/system/Tests/Theme/FunctionsTest.php
View file @
24296577
...
...
@@ -25,16 +25,30 @@ public static function getInfo() {
* Tests theme_item_list().
*/
function
testItemList
()
{
// Verify that empty
variable
s produce no output.
// Verify that empty
item
s produce no output.
$variables
=
array
();
$expected
=
''
;
$this
->
assertThemeOutput
(
'item_list'
,
$variables
,
$expected
,
'Empty %callback generates no output.'
);
// Verify that empty items with title produce no output.
$variables
=
array
();
$variables
[
'title'
]
=
'Some title'
;
$expected
=
''
;
$this
->
assertThemeOutput
(
'item_list'
,
$variables
,
$expected
,
'Empty %callback with title generates no output.'
);
// Verify that empty items produce the empty string.
$variables
=
array
();
$variables
[
'empty'
]
=
'No items found.'
;
$expected
=
'<div class="item-list">No items found.</div>'
;
$this
->
assertThemeOutput
(
'item_list'
,
$variables
,
$expected
,
'Empty %callback generates empty string.'
);
// Verify that empty items produce the empty string with title.
$variables
=
array
();
$variables
[
'title'
]
=
'Some title'
;
$variables
[
'empty'
]
=
'No items found.'
;
$expected
=
'<div class="item-list"><h3>Some title</h3>No items found.</div>'
;
$this
->
assertThemeOutput
(
'item_list'
,
$variables
,
$expected
,
'Empty %callback generates empty string with title.'
);
// Verify nested item lists.
$variables
=
array
();
$variables
[
'title'
]
=
'Some title'
;
...
...
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