Issue #1809836 by danillonunes: Fixed theme_item_list() is broken when 'items' variable is an associative array.

merge-requests/26/head
David Rothstein 2012-11-04 23:19:40 -05:00
parent 01f18eb540
commit ff1d0fccf7
3 changed files with 14 additions and 9 deletions

View File

@ -1,6 +1,8 @@
Drupal 7.17, xxxx-xx-xx (development version) Drupal 7.17, xxxx-xx-xx (development version)
----------------------- -----------------------
- Made it possible to use associative arrays for the 'items' variable in
theme_item_list().
- Fixed a bug which prevented required form elements without a title from being - Fixed a bug which prevented required form elements without a title from being
given an "error" class when the form fails validation. given an "error" class when the form fails validation.
- Prevented duplicate HTML IDs from appearing when two forms are displayed on - Prevented duplicate HTML IDs from appearing when two forms are displayed on

View File

@ -2069,10 +2069,12 @@ function theme_item_list($variables) {
if (!empty($items)) { if (!empty($items)) {
$output .= "<$type" . drupal_attributes($attributes) . '>'; $output .= "<$type" . drupal_attributes($attributes) . '>';
$num_items = count($items); $num_items = count($items);
foreach ($items as $i => $item) { $i = 0;
foreach ($items as $item) {
$attributes = array(); $attributes = array();
$children = array(); $children = array();
$data = ''; $data = '';
$i++;
if (is_array($item)) { if (is_array($item)) {
foreach ($item as $key => $value) { foreach ($item as $key => $value) {
if ($key == 'data') { if ($key == 'data') {
@ -2093,10 +2095,10 @@ function theme_item_list($variables) {
// Render nested list. // Render nested list.
$data .= theme_item_list(array('items' => $children, 'title' => NULL, 'type' => $type, 'attributes' => $attributes)); $data .= theme_item_list(array('items' => $children, 'title' => NULL, 'type' => $type, 'attributes' => $attributes));
} }
if ($i == 0) { if ($i == 1) {
$attributes['class'][] = 'first'; $attributes['class'][] = 'first';
} }
if ($i == $num_items - 1) { if ($i == $num_items) {
$attributes['class'][] = 'last'; $attributes['class'][] = 'last';
} }
$output .= '<li' . drupal_attributes($attributes) . '>' . $data . "</li>\n"; $output .= '<li' . drupal_attributes($attributes) . '>' . $data . "</li>\n";

View File

@ -230,18 +230,19 @@ class ThemeItemListUnitTest extends DrupalWebTestCase {
} }
/** /**
* Test nested list rendering. * Test item list rendering.
*/ */
function testNestedList() { function testItemList() {
$items = array('a', array('data' => 'b', 'children' => array('c', 'd')), 'e'); $items = array('a', array('data' => 'b', 'children' => array('c' => 'c', 'd' => 'd', 'e' => 'e')), 'f');
$expected = '<div class="item-list"><ul><li class="first">a</li> $expected = '<div class="item-list"><ul><li class="first">a</li>
<li>b<div class="item-list"><ul><li class="first">c</li> <li>b<div class="item-list"><ul><li class="first">c</li>
<li class="last">d</li> <li>d</li>
</ul></div></li>
<li class="last">e</li> <li class="last">e</li>
</ul></div></li>
<li class="last">f</li>
</ul></div>'; </ul></div>';
$output = theme('item_list', array('items' => $items)); $output = theme('item_list', array('items' => $items));
$this->assertIdentical($expected, $output, 'Nested list is rendered correctly.'); $this->assertIdentical($expected, $output, 'Item list is rendered correctly.');
} }
} }