Commit 61b627a6 by Qiang Xue

Fixes #4318: `yii\helpers\Html::ul()` and `ol()` will return an empty list tag…

Fixes #4318: `yii\helpers\Html::ul()` and `ol()` will return an empty list tag if an empty item array is given
parent 28246f49
......@@ -177,6 +177,7 @@ Yii Framework 2 Change Log
- Chg #4147: `BaseMailer::compose()` will not overwrite the `message` parameter if it is explicitly provided (qiangxue)
- Chg #4201: change default value of `SyslogTarget::facility` from LOG_SYSLOG to LOG_USER (dizews)
- Chg #4227: `\yii\widgets\LinkPager::$hideOnSinglePage` is now `true` by default (samdark)
- Chg #4318: `yii\helpers\Html::ul()` and `ol()` will return an empty list tag if an empty item array is given (qiangxue)
- Chg: Replaced `clearAll()` and `clearAllAssignments()` in `yii\rbac\ManagerInterface` with `removeAll()`, `removeAllRoles()`, `removeAllPermissions()`, `removeAllRules()` and `removeAllAssignments()` (qiangxue)
- Chg: Added `$user` as the first parameter of `yii\rbac\Rule::execute()` (qiangxue)
- Chg: `yii\grid\DataColumn::getDataCellValue()` visibility is now `public` to allow accessing the value from a GridView directly (cebe)
......
......@@ -976,18 +976,20 @@ class BaseHtml
*
* See [[renderTagAttributes()]] for details on how attributes are being rendered.
*
* @return string the generated unordered list. An empty string is returned if `$items` is empty.
* @return string the generated unordered list. An empty list tag will be returned if `$items` is empty.
*/
public static function ul($items, $options = [])
{
if (empty($items)) {
return '';
}
$tag = isset($options['tag']) ? $options['tag'] : 'ul';
$encode = !isset($options['encode']) || $options['encode'];
$formatter = isset($options['item']) ? $options['item'] : null;
$itemOptions = isset($options['itemOptions']) ? $options['itemOptions'] : [];
unset($options['tag'], $options['encode'], $options['item'], $options['itemOptions']);
if (empty($items)) {
return static::tag($tag, '', $options);
}
$results = [];
foreach ($items as $index => $item) {
if ($formatter !== null) {
......
......@@ -439,6 +439,8 @@ EOD;
return "<li class=\"item-$index\">$item</li>";
}
]));
$this->assertEquals('<ul class="test"></ul>', Html::ul([], ['class' => 'test']));
}
public function testOl()
......@@ -469,6 +471,8 @@ EOD;
return "<li class=\"item-$index\">$item</li>";
}
]));
$this->assertEquals('<ol class="test"></ol>', Html::ol([], ['class' => 'test']));
}
public function testRenderOptions()
......
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