-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dropdown.php
49 lines (40 loc) · 1.2 KB
/
Dropdown.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace iutbay\yii2bootstrap;
use yii\helpers\ArrayHelper;
use yii\bootstrap\Html;
use iutbay\yii2fontawesome\FontAwesome as FA;
/**
* Dropdown widget
* @author Kevin LEVRON <[email protected]>
*/
class Dropdown extends \yii\bootstrap\Dropdown
{
public $submenuOptions = ['class' => 'dropdown-menu'];
/**
* @inheritdoc
*/
public function run()
{
foreach ($this->items as &$item) {
// icon ?
if (isset($item['icon'])) {
$icon = FA::icon($item['icon'] . ' fw');
$item['label'] = trim($icon . ' ' . ArrayHelper::getValue($item, 'label', ''));
$item['encode'] = false;
unset($item['icon']);
}
// active ?
if (isset($item['active'])) {
$active = $item['active'];
if ($active instanceof \Closure) {
$active = call_user_func($active, $this->getView()->getContext());
}
if ($active) {
Html::addCssClass($item['options'], 'active');
}
unset($item['active']);
}
}
return parent::run();
}
}