Commit 24296577 authored by webchick's avatar webchick

Issue #2120807 by Mark Carver: Add empty option to item_list().

parent dac79f29
...@@ -2244,6 +2244,8 @@ function template_preprocess_item_list(&$variables) { ...@@ -2244,6 +2244,8 @@ function template_preprocess_item_list(&$variables) {
* - title: The title of the list. * - title: The title of the list.
* - list_type: The type of HTML list (e.g. "ul", "ol"). * - list_type: The type of HTML list (e.g. "ul", "ol").
* - attributes: The attributes applied to the list element. * - 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) { function theme_item_list($variables) {
$items = $variables['items']; $items = $variables['items'];
...@@ -2277,6 +2279,9 @@ function theme_item_list($variables) { ...@@ -2277,6 +2279,9 @@ function theme_item_list($variables) {
} }
$output .= "</$list_type>"; $output .= "</$list_type>";
} }
elseif (!empty($variables['empty'])) {
$output .= render($variables['empty']);
}
// Only output the list container and title, if there are any list items. // 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. // Check to see whether the block title exists before adding a header.
...@@ -3040,7 +3045,7 @@ function drupal_common_theme() { ...@@ -3040,7 +3045,7 @@ function drupal_common_theme() {
'variables' => array('status' => MARK_NEW), 'variables' => array('status' => MARK_NEW),
), ),
'item_list' => array( '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( 'feed_icon' => array(
'variables' => array('url' => NULL, 'title' => NULL), 'variables' => array('url' => NULL, 'title' => NULL),
......
...@@ -25,16 +25,30 @@ public static function getInfo() { ...@@ -25,16 +25,30 @@ public static function getInfo() {
* Tests theme_item_list(). * Tests theme_item_list().
*/ */
function testItemList() { function testItemList() {
// Verify that empty variables produce no output. // Verify that empty items produce no output.
$variables = array(); $variables = array();
$expected = ''; $expected = '';
$this->assertThemeOutput('item_list', $variables, $expected, 'Empty %callback generates no output.'); $this->assertThemeOutput('item_list', $variables, $expected, 'Empty %callback generates no output.');
// Verify that empty items with title produce no output.
$variables = array(); $variables = array();
$variables['title'] = 'Some title'; $variables['title'] = 'Some title';
$expected = ''; $expected = '';
$this->assertThemeOutput('item_list', $variables, $expected, 'Empty %callback with title generates no output.'); $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. // Verify nested item lists.
$variables = array(); $variables = array();
$variables['title'] = 'Some title'; $variables['title'] = 'Some title';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment