From 71a156ebdfe32e91688ea80387c289f31e0183a7 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Tue, 25 Jun 2013 16:16:36 -0400 Subject: [PATCH] Added itemOptions for Html::ol --- framework/yii/helpers/base/Html.php | 10 +++++++--- tests/unit/framework/helpers/HtmlTest.php | 10 ++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/framework/yii/helpers/base/Html.php b/framework/yii/helpers/base/Html.php index 9abf537..f5a4076 100644 --- a/framework/yii/helpers/base/Html.php +++ b/framework/yii/helpers/base/Html.php @@ -849,7 +849,8 @@ class Html * @param array $options options (name => config) for the radio button list. The following options are supported: * * - encode: boolean, whether to HTML-encode the items. Defaults to true. - * This option is ignored if the `item` option below is specified. + * This option is ignored if the `item` option is specified. + * - itemOptions: array, the HTML attributes for the `li` tags. This option is ignored if the `item` option is specified. * - item: callable, a callback that is used to generate each individual list item. * The signature of this callback must be: * @@ -870,13 +871,14 @@ class Html $tag = isset($options['tag']) ? $options['tag'] : 'ul'; $encode = !isset($options['encode']) || $options['encode']; $formatter = isset($options['item']) ? $options['item'] : null; - unset($options['tag'], $options['encode'], $options['item']); + $itemOptions = isset($options['itemOptions']) ? $options['itemOptions'] : array(); + unset($options['tag'], $options['encode'], $options['item'], $options['itemOptions']); $results = array(); foreach ($items as $index => $item) { if ($formatter !== null) { $results[] = call_user_func($formatter, $index, $item); } else { - $results[] = '
  • ' . ($encode ? static::encode($item) : $item) . '
  • '; + $results[] = static::tag('li', $encode ? static::encode($item) : $item, $itemOptions); } } return static::tag($tag, "\n" . implode("\n", $results) . "\n", $options); @@ -889,6 +891,8 @@ class Html * @param array $options options (name => config) for the radio button list. The following options are supported: * * - encode: boolean, whether to HTML-encode the items. Defaults to true. + * This option is ignored if the `item` option is specified. + * - itemOptions: array, the HTML attributes for the `li` tags. This option is ignored if the `item` option is specified. * - item: callable, a callback that is used to generate each individual list item. * The signature of this callback must be: * diff --git a/tests/unit/framework/helpers/HtmlTest.php b/tests/unit/framework/helpers/HtmlTest.php index dc6214f..aef2855 100644 --- a/tests/unit/framework/helpers/HtmlTest.php +++ b/tests/unit/framework/helpers/HtmlTest.php @@ -401,12 +401,14 @@ EOD; ); $expected = << -
  • 1
  • -
  • abc
  • -
  • <>
  • +
  • 1
  • +
  • abc
  • +
  • <>
  • EOD; - $this->assertEqualsWithoutLE($expected, Html::ol($data)); + $this->assertEqualsWithoutLE($expected, Html::ol($data, array( + 'itemOptions' => array('class' => 'ti'), + ))); $expected = <<
  • 1