From a2bcb00ae9efac437ed989e8984eb8af1a60032f Mon Sep 17 00:00:00 2001 From: Renjel Cabaral Date: Mon, 15 Jan 2018 18:33:05 +0800 Subject: [PATCH 1/3] Sidebar menu label added --- example-views/yiisoft/yii2-app/layouts/left.php | 2 ++ widgets/Menu.php | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/example-views/yiisoft/yii2-app/layouts/left.php b/example-views/yiisoft/yii2-app/layouts/left.php index 53b2cb3..ae7c326 100644 --- a/example-views/yiisoft/yii2-app/layouts/left.php +++ b/example-views/yiisoft/yii2-app/layouts/left.php @@ -36,6 +36,8 @@ ['label' => 'Login', 'url' => ['site/login'], 'visible' => Yii::$app->user->isGuest], [ 'label' => 'Some tools', + 'labelCount' => 2, + 'labelCountClass' => 'label label-primary', 'icon' => 'share', 'url' => '#', 'items' => [ diff --git a/widgets/Menu.php b/widgets/Menu.php index e5417cb..7fcf407 100644 --- a/widgets/Menu.php +++ b/widgets/Menu.php @@ -13,12 +13,14 @@ class Menu extends \yii\widgets\Menu /** * @inheritdoc */ - public $linkTemplate = '{icon} {label}'; + public $linkTemplate = '{icon} {label} {labelCount}'; /** * @inheritdoc * Styles all labels of items on sidebar by AdminLTE */ public $labelTemplate = '{label}'; + public $labelRightTemplate ; + public $labelCount = '{labelCount}'; public $submenuTemplate = "\n\n"; public $activateParents = true; public $defaultIconHtml = ' '; @@ -71,9 +73,11 @@ public function run() protected function renderItem($item) { if (isset($item['items'])) { - $labelTemplate = '{icon} {label} '; - $linkTemplate = '{icon} {label} '; + $labelRightTemplate = ' {labelCount} '; + $labelTemplate = '{icon} {label} {labelCount} '; + $linkTemplate = '{icon} {label} {labelCount} '; } else { + $labelRightTemplate = ' {labelCount} '; $labelTemplate = $this->labelTemplate; $linkTemplate = $this->linkTemplate; } @@ -82,6 +86,8 @@ protected function renderItem($item) '{label}' => strtr($this->labelTemplate, ['{label}' => $item['label'],]), '{icon}' => empty($item['icon']) ? $this->defaultIconHtml : ' ', + '{labelCount}' => empty($item['labelCount']) ? '' + : strtr($labelRightTemplate, ['{labelCountClass}' => $item['labelCountClass'],'{labelCount}' => $item['labelCount'],]), '{url}' => isset($item['url']) ? Url::to($item['url']) : 'javascript:void(0);', ]; From dc0021673b5a9c3a2a6a2d4ff8fcc1880346acf9 Mon Sep 17 00:00:00 2001 From: Renjel Cabaral Date: Mon, 15 Jan 2018 19:15:38 +0800 Subject: [PATCH 2/3] Sidebar menu label added a default value --- widgets/Menu.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/widgets/Menu.php b/widgets/Menu.php index 7fcf407..0623fc7 100644 --- a/widgets/Menu.php +++ b/widgets/Menu.php @@ -73,11 +73,27 @@ public function run() protected function renderItem($item) { if (isset($item['items'])) { - $labelRightTemplate = ' {labelCount} '; + + if (!isset($item['labelCount'])) + { + $labelRightTemplate = ' '; + } + else + { + $labelRightTemplate = ' {labelCount} '; + } $labelTemplate = '{icon} {label} {labelCount} '; $linkTemplate = '{icon} {label} {labelCount} '; } else { - $labelRightTemplate = ' {labelCount} '; + + if (!isset($item['labelCount'])) + { + $labelRightTemplate = ''; + } + else + { + $labelRightTemplate = ' {labelCount} '; + } $labelTemplate = $this->labelTemplate; $linkTemplate = $this->linkTemplate; } @@ -86,7 +102,7 @@ protected function renderItem($item) '{label}' => strtr($this->labelTemplate, ['{label}' => $item['label'],]), '{icon}' => empty($item['icon']) ? $this->defaultIconHtml : ' ', - '{labelCount}' => empty($item['labelCount']) ? '' + '{labelCount}' => empty($item['labelCount']) ? $labelRightTemplate : strtr($labelRightTemplate, ['{labelCountClass}' => $item['labelCountClass'],'{labelCount}' => $item['labelCount'],]), '{url}' => isset($item['url']) ? Url::to($item['url']) : 'javascript:void(0);', ]; From a3d48bc26c990e2084a3900e72119ebd91fd62a6 Mon Sep 17 00:00:00 2001 From: renjelc Date: Mon, 22 Jan 2018 16:44:41 +0800 Subject: [PATCH 3/3] Yii2 AdminLTE Label Widget added --- widgets/Label.php | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 widgets/Label.php diff --git a/widgets/Label.php b/widgets/Label.php new file mode 100644 index 0000000..0ef8c45 --- /dev/null +++ b/widgets/Label.php @@ -0,0 +1,56 @@ + $value, where: + * - $key is the name of the session flash variable + * - $value is the array: + * - class of label type (i.e. danger, success, info, warning) + * - icon for label AdminLTE + */ + public $labelTypes = [ + 'error' => [ + 'class' => 'label-danger', + 'icon' => '', + ], + 'danger' => [ + 'class' => 'label-danger', + 'icon' => '', + ], + 'success' => [ + 'class' => 'label-success', + 'icon' => '', + ], + 'info' => [ + 'class' => 'label-info', + 'icon' => '', + ], + 'warning' => [ + 'class' => 'label-warning', + 'icon' => '', + ], + ]; + + /** + * Initializes the widget. + * This method will register the bootstrap asset bundle. If you override this method, + * make sure you call the parent implementation first. + */ + public function init() + { + parent::init(); + + // CODE HERE + } +}