Browse Source

Include tag in options.

euromark 12 years ago
parent
commit
2fc3c43661
2 changed files with 14 additions and 8 deletions
  1. 11 8
      src/View/Helper/HtmlHelper.php
  2. 3 0
      tests/TestCase/View/Helper/HtmlHelperTest.php

+ 11 - 8
src/View/Helper/HtmlHelper.php

@@ -1076,6 +1076,10 @@ class HtmlHelper extends Helper {
 /**
  * Build a nested list (UL/OL) out of an associative array.
  *
+ * Options for $options:
+ *
+ * - `tag` - Type of list tag to use (ol/ul)
+ *
  * Options for $itemOptions:
  *
  * - `even` - Class to use for even rows.
@@ -1084,14 +1088,14 @@ class HtmlHelper extends Helper {
  * @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
- * @param string $tag Type of list tag to use (ol/ul)
  * @return string The nested list
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::nestedList
  */
-	public function nestedList(array $list, array $options = [], array $itemOptions = [], $tag = 'ul') {
-		$items = $this->_nestedListItem($list, $options, $itemOptions, $tag);
+	public function nestedList(array $list, array $options = [], array $itemOptions = []) {
+		$options += array('tag' => 'ul');
+		$items = $this->_nestedListItem($list, $options, $itemOptions);
 		return $this->formatTemplate($tag, [
-			'attrs' => $this->templater()->formatAttributes($options),
+			'attrs' => $this->templater()->formatAttributes($options, ['tag']),
 			'content' => $items
 		]);
 	}
@@ -1100,19 +1104,18 @@ class HtmlHelper extends Helper {
  * Internal function to build a nested list (UL/OL) out of an associative array.
  *
  * @param array $items Set of elements to list
- * @param array $options Additional HTML attributes of the list (ol/ul) tag
+ * @param array $options Options and additional HTML attributes of the list (ol/ul) tag
  * @param array $itemOptions Additional HTML attributes of the list item (LI) tag
- * @param string $tag Type of list tag to use (ol/ul)
  * @return string The nested list element
  * @see HtmlHelper::nestedList()
  */
-	protected function _nestedListItem($items, $options, $itemOptions, $tag) {
+	protected function _nestedListItem($items, $options, $itemOptions) {
 		$out = '';
 
 		$index = 1;
 		foreach ($items as $key => $item) {
 			if (is_array($item)) {
-				$item = $key . $this->nestedList($item, $options, $itemOptions, $tag);
+				$item = $key . $this->nestedList($item, $options, $itemOptions);
 			}
 			if (isset($itemOptions['even']) && $index % 2 === 0) {
 				$itemOptions['class'] = $itemOptions['even'];

+ 3 - 0
tests/TestCase/View/Helper/HtmlHelperTest.php

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