Fixes #8064: Added ability to remove containing menu tag by setting yii\widgets\Menu::$options['tag'] to false

This commit is contained in:
Kirsa Denis
2015-04-13 15:14:30 +03:00
committed by Alexander Makarov
parent ea55a71a2c
commit cafd135022
3 changed files with 43 additions and 2 deletions

View File

@ -42,6 +42,7 @@ Yii Framework 2 Change Log
- Enh #7918: `yii\widgets\Pjax` got ability to avoid registering link/form handler via setting `false` to `$linkSelector`/`$formSelector` (usualdesigner, Alex-Code, samdark)
- Enh #7973: Added `Schema::getSchemaNames` method (nineinchnick)
- Enh #8027: Added support for using sub queries in simple Query WHERE conditions (cebe)
- Enh #8064: Added ability to remove containing menu tag by setting `yii\widgets\Menu::$options['tag']` to `false` (kirsenn, samdark)
- Enh: Added `yii\helper\Console::wrapText()` method to wrap indented text by console window width and used it in `yii help` command (cebe)
- Enh: Implement batchInsert for oci (nineinchnick)
- Enh: Detecting IntegrityException for oci (nineinchnick)

View File

@ -79,7 +79,7 @@ class Menu extends Widget
* specifies its `options`, it will be merged with this property before being used to generate the HTML
* attributes for the menu item tag. The following special options are recognized:
*
* - tag: string, defaults to "li", the tag name of the item container tags.
* - tag: string, defaults to "li", the tag name of the item container tags. Set to false to disable container tag.
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
@ -175,7 +175,12 @@ class Menu extends Widget
if (!empty($items)) {
$options = $this->options;
$tag = ArrayHelper::remove($options, 'tag', 'ul');
if ($tag !== false) {
echo Html::tag($tag, $this->renderItems($items), $options);
} else {
echo $this->renderItems($items);
}
}
}

View File

@ -66,4 +66,39 @@ HTML
, $output);
}
/**
* @see https://github.com/yiisoft/yii2/issues/8064
*/
public function testTagOption()
{
$output = Menu::widget([
'route' => 'test/test',
'params' => [],
'encodeLabels' => true,
'options' => [
'tag' => false,
],
'items' => [
[
'label' => 'item1',
'url' => '#',
'options' => ['tag' => 'div'],
],
[
'label' => 'item2',
'url' => '#',
'options' => ['tag' => false],
],
]
]);
$this->assertEqualsWithoutLE(<<<HTML
<div><a href="#">item1</a></div>
<a href="#">item2</a>
HTML
, $output);
}
}