-
Notifications
You must be signed in to change notification settings - Fork 0
/
SideNav.php
77 lines (62 loc) · 1.6 KB
/
SideNav.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* @link http://foundationize.com
* @package shqear/yii2-foundation6
* @version 1.0.0
*/
namespace shqear\foundation6;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
/**
* Description of SideNav
*
*/
class SideNav extends NavigationWidget {
/**
*
* @var type array
*
* 'label' => 'label'
* 'url' => 'url'
* 'linkOptions' => []
* 'options' => []
* 'active => true|false
* 'visible => true|false
*
*/
public $items = [];
/**
*
*/
public function run() {
Html::addCssClass($this->options, 'side-nav');
if (empty($this->options['role'])) {
$this->options['role'] = 'navigation';
}
echo Html::tag('ul', implode("\n", $this->renderItems()), $this->options);
}
/**
*
* @return type
*/
public function renderItems() {
$out = [];
foreach ($this->items as $i => $item) {
$encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels;
$label = $encodeLabel ? Html::encode($item['label']) : $item['label'];
$options = ArrayHelper::getValue($item, 'options', []);
$url = ArrayHelper::getValue($item, 'url', '#');
$linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
if (isset($item['active'])) {
$active = ArrayHelper::remove($item, 'active', false);
} else {
$active = $this->isItemActive($item);
}
if ($this->activateItems && $active) {
Html::addCssClass($options, 'active');
}
$out[] = Html::tag('li', Html::a($label, $url, $linkOptions), $options);
}
return $out;
}
}