Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sidebar menu label added #156

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example-views/yiisoft/yii2-app/layouts/left.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
56 changes: 56 additions & 0 deletions widgets/Label.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/

namespace dmstr\widgets;

use yii\bootstrap\Widget;

class Label extends Widget
{
/**
* @var array the label types configuration for the flash messages.
* This array is setup as $key => $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' => '<i class="icon fa fa-ban"></i>',
],
'danger' => [
'class' => 'label-danger',
'icon' => '<i class="icon fa fa-ban"></i>',
],
'success' => [
'class' => 'label-success',
'icon' => '<i class="icon fa fa-check"></i>',
],
'info' => [
'class' => 'label-info',
'icon' => '<i class="icon fa fa-info"></i>',
],
'warning' => [
'class' => 'label-warning',
'icon' => '<i class="icon fa fa-warning"></i>',
],
];

/**
* 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
}
}
28 changes: 25 additions & 3 deletions widgets/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ class Menu extends \yii\widgets\Menu
/**
* @inheritdoc
*/
public $linkTemplate = '<a href="{url}">{icon} {label}</a>';
public $linkTemplate = '<a href="{url}">{icon} {label} {labelCount}</a>';
/**
* @inheritdoc
* Styles all labels of items on sidebar by AdminLTE
*/
public $labelTemplate = '<span>{label}</span>';
public $labelRightTemplate ;
public $labelCount = '{labelCount}';
public $submenuTemplate = "\n<ul class='treeview-menu' {show}>\n{items}\n</ul>\n";
public $activateParents = true;
public $defaultIconHtml = '<i class="fa fa-circle-o"></i> ';
Expand Down Expand Up @@ -71,9 +73,27 @@ public function run()
protected function renderItem($item)
{
if (isset($item['items'])) {
$labelTemplate = '<a href="{url}">{icon} {label} <span class="pull-right-container"><i class="fa fa-angle-left pull-right"></i></span></a>';
$linkTemplate = '<a href="{url}">{icon} {label} <span class="pull-right-container"><i class="fa fa-angle-left pull-right"></i></span></a>';

if (!isset($item['labelCount']))
{
$labelRightTemplate = '<span class="pull-right-container"> <i class="fa fa-angle-left pull-right"></i> </span>';
}
else
{
$labelRightTemplate = '<span class="pull-right-container"> <i class="fa fa-angle-left pull-right"></i> <span class="{labelCountClass} pull-right">{labelCount}</span> </span>';
}
$labelTemplate = '<a href="{url}">{icon} {label} {labelCount} </a>';
$linkTemplate = '<a href="{url}">{icon} {label} {labelCount} </a>';
} else {

if (!isset($item['labelCount']))
{
$labelRightTemplate = '';
}
else
{
$labelRightTemplate = '<span class="pull-right-container"> <span class="{labelCountClass} pull-right">{labelCount}</span> </span>';
}
$labelTemplate = $this->labelTemplate;
$linkTemplate = $this->linkTemplate;
}
Expand All @@ -82,6 +102,8 @@ protected function renderItem($item)
'{label}' => strtr($this->labelTemplate, ['{label}' => $item['label'],]),
'{icon}' => empty($item['icon']) ? $this->defaultIconHtml
: '<i class="' . self::$iconClassPrefix . $item['icon'] . '"></i> ',
'{labelCount}' => empty($item['labelCount']) ? $labelRightTemplate
: strtr($labelRightTemplate, ['{labelCountClass}' => $item['labelCountClass'],'{labelCount}' => $item['labelCount'],]),
'{url}' => isset($item['url']) ? Url::to($item['url']) : 'javascript:void(0);',
];

Expand Down