Commit 71a156eb by Qiang Xue

Added itemOptions for Html::ol

parent d87afeb4
......@@ -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[] = '<li>' . ($encode ? static::encode($item) : $item) . '</li>';
$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:
*
......
......@@ -401,12 +401,14 @@ EOD;
);
$expected = <<<EOD
<ol>
<li>1</li>
<li>abc</li>
<li>&lt;&gt;</li>
<li class="ti">1</li>
<li class="ti">abc</li>
<li class="ti">&lt;&gt;</li>
</ol>
EOD;
$this->assertEqualsWithoutLE($expected, Html::ol($data));
$this->assertEqualsWithoutLE($expected, Html::ol($data, array(
'itemOptions' => array('class' => 'ti'),
)));
$expected = <<<EOD
<ol class="test">
<li class="item-0">1</li>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment