summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2012-11-04 23:19:40 -0500
committerDavid Rothstein <drothstein@gmail.com>2012-11-04 23:19:40 -0500
commitff1d0fccf766764d0fa925f2ac9336c5543bb31d (patch)
treebebb91c21b01c1e72af65cb4c23af1035850e8d1
parent01f18eb540c968d1bfae7def22de558bdc208c17 (diff)
downloadbrdo-ff1d0fccf766764d0fa925f2ac9336c5543bb31d.tar.gz
brdo-ff1d0fccf766764d0fa925f2ac9336c5543bb31d.tar.bz2
Issue #1809836 by danillonunes: Fixed theme_item_list() is broken when 'items' variable is an associative array.
-rw-r--r--CHANGELOG.txt2
-rw-r--r--includes/theme.inc8
-rw-r--r--modules/simpletest/tests/theme.test13
3 files changed, 14 insertions, 9 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 10980a1e9..17e4024d7 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,6 +1,8 @@
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
given an "error" class when the form fails validation.
- Prevented duplicate HTML IDs from appearing when two forms are displayed on
diff --git a/includes/theme.inc b/includes/theme.inc
index 1f8dfcf9e..777922f05 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -2069,10 +2069,12 @@ function theme_item_list($variables) {
if (!empty($items)) {
$output .= "<$type" . drupal_attributes($attributes) . '>';
$num_items = count($items);
- foreach ($items as $i => $item) {
+ $i = 0;
+ foreach ($items as $item) {
$attributes = array();
$children = array();
$data = '';
+ $i++;
if (is_array($item)) {
foreach ($item as $key => $value) {
if ($key == 'data') {
@@ -2093,10 +2095,10 @@ function theme_item_list($variables) {
// Render nested list.
$data .= theme_item_list(array('items' => $children, 'title' => NULL, 'type' => $type, 'attributes' => $attributes));
}
- if ($i == 0) {
+ if ($i == 1) {
$attributes['class'][] = 'first';
}
- if ($i == $num_items - 1) {
+ if ($i == $num_items) {
$attributes['class'][] = 'last';
}
$output .= '<li' . drupal_attributes($attributes) . '>' . $data . "</li>\n";
diff --git a/modules/simpletest/tests/theme.test b/modules/simpletest/tests/theme.test
index 27a8e47b9..0ee473e3f 100644
--- a/modules/simpletest/tests/theme.test
+++ b/modules/simpletest/tests/theme.test
@@ -230,18 +230,19 @@ class ThemeItemListUnitTest extends DrupalWebTestCase {
}
/**
- * Test nested list rendering.
+ * Test item list rendering.
*/
- function testNestedList() {
- $items = array('a', array('data' => 'b', 'children' => array('c', 'd')), 'e');
+ function testItemList() {
+ $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>
<li>b<div class="item-list"><ul><li class="first">c</li>
-<li class="last">d</li>
-</ul></div></li>
+<li>d</li>
<li class="last">e</li>
+</ul></div></li>
+<li class="last">f</li>
</ul></div>';
$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.');
}
}