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 2 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
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