3
3
/**
4
4
* @copyright Copyright © Kartik Visweswaran, Krajee.com, 2013
5
5
* @package yii2-widgets
6
- * @version 1.0 .0
6
+ * @version 1.1 .0
7
7
*/
8
8
9
9
namespace kartik \widgets ;
@@ -62,6 +62,13 @@ class SideNav extends \yii\widgets\Menu
62
62
*/
63
63
public $ type = self ::TYPE_DEFAULT ;
64
64
65
+ /**
66
+ * @var string prefix for the icon in [[items]]. This string will be prepended
67
+ * before the icon name to get the icon CSS class. This defaults to `glyphicon glyphicon-`
68
+ * for usage with glyphicons available with Bootstrap.
69
+ */
70
+ public $ iconPrefix = 'glyphicon glyphicon- ' ;
71
+
65
72
/**
66
73
* @var array string/boolean the sidenav heading. This is not HTML encoded
67
74
* When set to false or null, no heading container will be displayed.
@@ -101,7 +108,6 @@ class SideNav extends \yii\widgets\Menu
101
108
* - icon: string, optional, specifies the glyphicon name to be placed before label.
102
109
* - url: string or array, optional, specifies the URL of the menu item. It will be processed by [[Url::to]].
103
110
* When this is set, the actual menu item content will be generated using [[linkTemplate]];
104
- * otherwise, [[labelTemplate]] will be used.
105
111
* - visible: boolean, optional, whether this menu item is visible. Defaults to true.
106
112
* - items: array, optional, specifies the sub-menu items. Its format is the same as the parent items.
107
113
* - active: boolean, optional, whether this menu item is in active state (currently selected).
@@ -111,7 +117,7 @@ class SideNav extends \yii\widgets\Menu
111
117
* - template: string, optional, the template used to render the content of this menu item.
112
118
* The token `{url}` will be replaced by the URL associated with this menu item,
113
119
* and the token `{label}` will be replaced by the label of the menu item.
114
- * If this option is not set, [[linkTemplate]] or [[labelTemplate]] will be used instead.
120
+ * If this option is not set, [[linkTemplate]] will be used instead.
115
121
* - options: array, optional, the HTML attributes for the menu item tag.
116
122
*
117
123
*/
@@ -201,8 +207,8 @@ protected function markTopItems()
201
207
protected function renderItem ($ item )
202
208
{
203
209
$ this ->validateItems ($ item );
210
+ $ template = ArrayHelper::getValue ($ item , 'template ' , $ this ->linkTemplate );
204
211
$ url = Url::to (ArrayHelper::getValue ($ item , 'url ' , '# ' ));
205
- $ template = $ this ->linkTemplate ;
206
212
if (empty ($ item ['top ' ])) {
207
213
if (empty ($ item ['items ' ])) {
208
214
$ template = str_replace ('{icon} ' , $ this ->indItem . '{icon} ' , $ template );
@@ -214,7 +220,7 @@ protected function renderItem($item)
214
220
$ template = str_replace ('{icon} ' , $ indicator . '{icon} ' , $ template );
215
221
}
216
222
}
217
- $ icon = empty ($ item ['icon ' ]) ? '' : '<i class="glyphicon glyphicon- ' . $ item ['icon ' ] . '"></i > ' ;
223
+ $ icon = empty ($ item ['icon ' ]) ? '' : '<span class=" ' . $ this -> iconPrefix . $ item ['icon ' ] . '"></span > ' ;
218
224
unset($ item ['icon ' ], $ item ['top ' ]);
219
225
return strtr ($ template , [
220
226
'{url} ' => $ url ,
0 commit comments