1 | <?php |
||
20 | class Menu { |
||
21 | use |
||
22 | Singleton; |
||
23 | const INIT_STATE_METHOD = 'init'; |
||
24 | /** |
||
25 | * @var array |
||
26 | */ |
||
27 | public $section_items; |
||
28 | /** |
||
29 | * @var array |
||
30 | */ |
||
31 | public $items; |
||
32 | |||
33 | 6 | protected function init () { |
|
37 | /** |
||
38 | * Get menu in HTML format |
||
39 | * |
||
40 | * @return string |
||
41 | */ |
||
42 | 6 | function get_menu () { |
|
43 | 6 | Event::instance()->fire('admin/System/Menu'); |
|
44 | 6 | $current_module = Request::instance()->current_module; |
|
45 | 6 | if (isset($this->section_items[$current_module])) { |
|
46 | 4 | $content = $this->render_sections($current_module); |
|
47 | } else { |
||
48 | 2 | $content = $this->render_items($current_module); |
|
49 | } |
||
50 | 6 | return h::{'nav[is=cs-nav-button-group]'}($content ?: false); |
|
51 | } |
||
52 | /** |
||
53 | * Render sections (automatically includes nested items) |
||
54 | * |
||
55 | * @param string $module |
||
56 | * |
||
57 | * @return string |
||
58 | */ |
||
59 | 4 | protected function render_sections ($module) { |
|
74 | /** |
||
75 | * Render items |
||
76 | * |
||
77 | * @param string $module |
||
78 | * @param string $base_href If passed - only nested elements for this base href will be rendered |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | 6 | protected function render_items ($module, $base_href = '') { |
|
101 | /** |
||
102 | * Add second-level item into menu |
||
103 | * |
||
104 | * All third-level items which start with the same `$href` will be inside this second-level menu item |
||
105 | * |
||
106 | * @param string $module |
||
107 | * @param string $title |
||
108 | * @param array $attributes |
||
109 | */ |
||
110 | 4 | function add_section_item ($module, $title, $attributes = []) { |
|
116 | /** |
||
117 | * Add third-level item into menu (second-level when there is corresponding section items) |
||
118 | * |
||
119 | * @param string $module |
||
120 | * @param string $title |
||
121 | * @param array $attributes |
||
122 | */ |
||
123 | 4 | function add_item ($module, $title, $attributes = []) { |
|
129 | } |
||
130 |