Skip to content

Add an ability to use multiple badges in a left sidebar menu item wit… #5

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
32 changes: 16 additions & 16 deletions widgets/Menu.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @copyright Copyright (c) 2015 Yiister
* @license https://github.com/yiister/yii2-adminlte/blob/master/LICENSE
* @license https://github.com/yiister/adminlte/blob/master/LICENSE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong link

* @link http://adminlte.yiister.ru
*/

Expand All @@ -21,7 +21,7 @@ class Menu extends \yii\widgets\Menu
/**
* @inheritdoc
*/
public $linkTemplate = '<a href="{url}">{icon}<span>{label}</span>{badge}</a>';
public $linkTemplate = '<a href="{url}">{icon}<span>{label}</span><span class="pull-right-container">{dropDownIcon}{badges}</span></a>';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement dropDownIcon feature at the another pull request please.


/**
* @inheritdoc
Expand All @@ -48,27 +48,27 @@ public function init()
protected function renderItem($item)
{
$renderedItem = parent::renderItem($item);
if (isset($item['badge'])) {
$badgeOptions = ArrayHelper::getValue($item, 'badgeOptions', []);
Html::addCssClass($badgeOptions, 'label pull-right');
} else {
$badgeOptions = null;
$badges = '';
if (isset($item['badges']) && is_array($item['badges'])) {
foreach ($item['badges'] as $badge) {
$badgeContent = ArrayHelper::getValue($badge, 'content', '');
$badgeOptions = ArrayHelper::getValue($badge, 'badgeOptions', []);
Html::addCssClass($badgeOptions, 'label pull-right');
$badges .= Html::tag('small', $badgeContent, $badgeOptions);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we have no array? This feature breaks a backward compatibility.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that using of badge placeholder is a better solution for it. What do you think?

}
return strtr(
$renderedItem,
[
'{icon}' => isset($item['icon'])
? new Icon($item['icon'], ArrayHelper::getValue($item, 'iconOptions', []))
: '',
'{badge}' => (
isset($item['badge'])
? Html::tag('small', $item['badge'], $badgeOptions)
: ''
) . (
isset($item['items']) && count($item['items']) > 0
? new Icon('fa fa-angle-left pull-right')
: ''
),
'{badges}' => ($badges != '')
? $badges
: '',
'{dropDownIcon}' => isset($item['items']) && count($item['items']) > 0
? new Icon('fa fa-angle-left pull-right')
: ''
]
);
}
Expand Down