Total Complexity | 7 |
Total Lines | 60 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
18 | class MainMenu extends Widget |
||
19 | { |
||
20 | /** |
||
21 | * Main menu item config. |
||
22 | * |
||
23 | * @var MainMenuItem[] |
||
24 | */ |
||
25 | protected $menuItems = []; |
||
26 | |||
27 | /** |
||
28 | * @return MainMenuItem[] |
||
29 | */ |
||
30 | public function getMenuItems() |
||
31 | { |
||
32 | return $this->menuItems; |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Main menu items setter. |
||
37 | * |
||
38 | * @param array|MainMenuItem[] $menuItems menu items config. |
||
39 | * |
||
40 | * @return $this |
||
41 | */ |
||
42 | public function setMenuItems(array $menuItems) |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * Create a MenuItem instance and fill menu items array. |
||
53 | * |
||
54 | * @param array|MainMenuItem $item |
||
55 | * |
||
56 | * @return void |
||
57 | */ |
||
58 | public function addMenuItem($item) |
||
59 | { |
||
60 | if (is_array($item)) { |
||
61 | if (!array_key_exists('class', $item)) { |
||
62 | $item['class'] = MainMenuItem::class; |
||
63 | } |
||
64 | $item = Yii::createObject($item); |
||
65 | } |
||
66 | $this->menuItems[] = $item; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Returns main menu template with rendered menu items. |
||
71 | * |
||
72 | * @return string. |
||
|
|||
73 | */ |
||
74 | public function run() |
||
78 | ]); |
||
79 | } |
||
80 | } |
||
81 |