-
Notifications
You must be signed in to change notification settings - Fork 28
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
* @link http://adminlte.yiister.ru | ||
*/ | ||
|
||
|
@@ -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>'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implement |
||
|
||
/** | ||
* @inheritdoc | ||
|
@@ -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); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if we have no array? This feature breaks a backward compatibility. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that using of |
||
} | ||
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') | ||
: '' | ||
] | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong link