1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace KyleMassacre\Menus\Presenters\Admin; |
4
|
|
|
|
5
|
|
|
use KyleMassacre\Menus\Contracts\MenuItemContract; |
6
|
|
|
use KyleMassacre\Menus\Presenters\Presenter; |
7
|
|
|
|
8
|
|
|
class AdminltePresenter extends Presenter |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* {@inheritdoc} |
12
|
|
|
*/ |
13
|
|
|
public function getOpenTagWrapper(): ?string |
14
|
|
|
{ |
15
|
|
|
return PHP_EOL . '<ul class="sidebar-menu tree" data-widget="tree">' . PHP_EOL; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* {@inheritdoc} |
20
|
|
|
*/ |
21
|
|
|
public function getCloseTagWrapper(): ?string |
22
|
|
|
{ |
23
|
|
|
return PHP_EOL . '</ul>' . PHP_EOL; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
|
|
public function getMenuWithoutDropdownWrapper(MenuItemContract $item): ?string |
30
|
|
|
{ |
31
|
|
|
return '<li' . $this->getActiveState($item) . '><a href="' . $item->getUrl() . '" ' . $item->getAttributes() . '>' . $item->getIcon() . ' <span>' . $item->title . '</span></a></li>' . PHP_EOL; |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc}. |
36
|
|
|
*/ |
37
|
|
|
public function getActiveState(MenuItemContract $item, $state = ' class="active"'): mixed |
38
|
|
|
{ |
39
|
|
|
return $item->isActive() ? $state : null; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Get active state on child items. |
44
|
|
|
* |
45
|
|
|
* @param $item |
46
|
|
|
* @param string $state |
47
|
|
|
* |
48
|
|
|
* @return null|string |
49
|
|
|
*/ |
50
|
|
|
public function getActiveStateOnChild(MenuItemContract $item, string $state = 'active'): ?string |
51
|
|
|
{ |
52
|
|
|
return $item->hasActiveOnChild() ? $state : null; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
|
|
public function getDividerWrapper(): ?string |
59
|
|
|
{ |
60
|
|
|
return '<li class="divider"></li>'; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
|
|
public function getHeaderWrapper(MenuItemContract $item): ?string |
67
|
|
|
{ |
68
|
|
|
return '<li class="header">' . $item->title . '</li>'; |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc}. |
73
|
|
|
*/ |
74
|
|
|
public function getMenuWithDropDownWrapper(MenuItemContract $item): ?string |
75
|
|
|
{ |
76
|
|
|
return '<li class="treeview' . $this->getActiveStateOnChild($item, ' active') . '"> |
77
|
|
|
<a href="#"> |
78
|
|
|
' . $item->getIcon() . ' <span>' . $item->title . '</span> |
|
|
|
|
79
|
|
|
<span class="pull-right-container"> |
80
|
|
|
<i class="fa fa-angle-left pull-right"></i> |
81
|
|
|
</span> |
82
|
|
|
</a> |
83
|
|
|
<ul class="treeview-menu"> |
84
|
|
|
' . $this->getChildMenuItems($item) . ' |
85
|
|
|
</ul> |
86
|
|
|
</li>' |
87
|
|
|
. PHP_EOL; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Get multilevel menu wrapper. |
92
|
|
|
* |
93
|
|
|
* @param MenuItemContract $item |
94
|
|
|
* |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
|
|
public function getMultiLevelDropdownWrapper(MenuItemContract $item): string |
98
|
|
|
{ |
99
|
|
|
return '<li class="treeview' . $this->getActiveStateOnChild($item, ' active') . '"> |
100
|
|
|
<a href="#"> |
101
|
|
|
' . $item->getIcon() . ' <span>' . $item->title . '</span> |
|
|
|
|
102
|
|
|
<span class="pull-right-container"> |
103
|
|
|
<i class="fa fa-angle-left pull-right"></i> |
104
|
|
|
</span> |
105
|
|
|
</a> |
106
|
|
|
<ul class="treeview-menu"> |
107
|
|
|
' . $this->getChildMenuItems($item) . ' |
108
|
|
|
</ul> |
109
|
|
|
</li>' |
110
|
|
|
. PHP_EOL; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.