Browse Source

Simplify API for HtmlHelper::nestedList and complete documentation.

euromark 12 years ago
parent
commit
bcb7d795a1
2 changed files with 8 additions and 10 deletions
  1. 7 6
      src/View/Helper/HtmlHelper.php
  2. 1 4
      tests/TestCase/View/Helper/HtmlHelperTest.php

+ 7 - 6
src/View/Helper/HtmlHelper.php

@@ -1076,6 +1076,11 @@ class HtmlHelper extends Helper {
 /**
  * Build a nested list (UL/OL) out of an associative array.
  *
+ * Options for $itemOptions:
+ *
+ * - `even` - Class to use for even rows.
+ * - `odd` - Class to use for odd rows.
+ *
  * @param array $list Set of elements to list
  * @param string|array $options Additional HTML attributes of the list (ol/ul) tag or if ul/ol use that as tag
  * @param array $itemOptions Additional HTML attributes of the list item (LI) tag
@@ -1083,11 +1088,7 @@ class HtmlHelper extends Helper {
  * @return string The nested list
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::nestedList
  */
-	public function nestedList($list, $options = array(), array $itemOptions = array(), $tag = 'ul') {
-		if (is_string($options)) {
-			$tag = $options;
-			$options = array();
-		}
+	public function nestedList(array $list, array $options = array(), array $itemOptions = array(), $tag = 'ul') {
 		$items = $this->_nestedListItem($list, $options, $itemOptions, $tag);
 		return $this->formatTemplate($tag, [
 			'attrs' => $this->templater()->formatAttributes($options),
@@ -1105,7 +1106,7 @@ class HtmlHelper extends Helper {
  * @return string The nested list element
  * @see HtmlHelper::nestedList()
  */
-	protected function _nestedListItem($items, $options, array $itemOptions, $tag) {
+	protected function _nestedListItem($items, $options, $itemOptions, $tag) {
 		$out = '';
 
 		$index = 1;

+ 1 - 4
tests/TestCase/View/Helper/HtmlHelperTest.php

@@ -1318,7 +1318,7 @@ class HtmlHelperTest extends TestCase {
 		);
 		$this->assertTags($result, $expected);
 
-		$result = $this->Html->nestedList($list, null);
+		$result = $this->Html->nestedList($list);
 		$this->assertTags($result, $expected);
 
 		$result = $this->Html->nestedList($list, array(), array(), 'ol');
@@ -1351,9 +1351,6 @@ class HtmlHelperTest extends TestCase {
 		);
 		$this->assertTags($result, $expected);
 
-		$result = $this->Html->nestedList($list, 'ol');
-		$this->assertTags($result, $expected);
-
 		$result = $this->Html->nestedList($list, array('class' => 'list'));
 		$expected = array(
 			array('ul' => array('class' => 'list')),