1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AbterPhp\Files\Events\Listeners; |
6
|
|
|
|
7
|
|
|
use AbterPhp\Files\Constant\Route; |
8
|
|
|
use AbterPhp\Files\Constant\Resource; |
9
|
|
|
use AbterPhp\Framework\Constant\Html5; |
10
|
|
|
use AbterPhp\Framework\Events\NavigationReady; |
11
|
|
|
use AbterPhp\Framework\Html\Component\ButtonFactory; |
12
|
|
|
use AbterPhp\Framework\Html\ITag; |
13
|
|
|
use AbterPhp\Framework\Navigation\Dropdown; |
14
|
|
|
use AbterPhp\Framework\Navigation\Item; |
15
|
|
|
use AbterPhp\Framework\Navigation\Navigation; |
16
|
|
|
|
17
|
|
|
class NavigationBuilder |
18
|
|
|
{ |
19
|
|
|
const BASE_WEIGHT = 600; |
20
|
|
|
|
21
|
|
|
/** @var ButtonFactory */ |
22
|
|
|
protected $buttonFactory; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* NavigationRegistrar constructor. |
26
|
|
|
* |
27
|
|
|
* @param ButtonFactory $buttonFactory |
28
|
|
|
*/ |
29
|
|
|
public function __construct(ButtonFactory $buttonFactory) |
30
|
|
|
{ |
31
|
|
|
$this->buttonFactory = $buttonFactory; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param NavigationReady $event |
36
|
|
|
*/ |
37
|
|
|
/** |
38
|
|
|
* @param NavigationReady $event |
39
|
|
|
* |
40
|
|
|
* @throws \Opulence\Routing\Urls\UrlException |
41
|
|
|
*/ |
42
|
|
|
public function handle(NavigationReady $event) |
43
|
|
|
{ |
44
|
|
|
$navigation = $event->getNavigation(); |
45
|
|
|
|
46
|
|
|
if (!$navigation->hasIntent(Navigation::INTENT_PRIMARY)) { |
47
|
|
|
return; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$item = $this->createItem(); |
51
|
|
|
|
52
|
|
|
$navigation->addItem($item, static::BASE_WEIGHT); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return Item |
57
|
|
|
* @throws \Opulence\Routing\Urls\UrlException |
58
|
|
|
*/ |
59
|
|
|
protected function createItem(): Item |
60
|
|
|
{ |
61
|
|
|
$text = 'files:files'; |
62
|
|
|
$icon = 'file_copy'; |
63
|
|
|
|
64
|
|
|
$button = $this->buttonFactory->createFromName($text, Route::FILES_LIST, [], $icon); |
65
|
|
|
$resource = $this->getAdminResource(Resource::FILES); |
66
|
|
|
|
67
|
|
|
$item = new Item($button); |
68
|
|
|
$item->setResource($resource); |
69
|
|
|
|
70
|
|
|
$item->setIntent(Item::INTENT_DROPDOWN); |
71
|
|
|
$item->setAttribute(Html5::ATTR_ID, 'nav-files'); |
72
|
|
|
|
73
|
|
|
if (!empty($item[0]) && $item[0] instanceof ITag) { |
74
|
|
|
$item[0]->setAttribute(Html5::ATTR_HREF, 'javascript:void(0);'); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$item[] = $this->createDropdown(); |
78
|
|
|
|
79
|
|
|
return $item; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return Dropdown |
84
|
|
|
* @throws \Opulence\Routing\Urls\UrlException |
85
|
|
|
*/ |
86
|
|
|
protected function createDropdown(): Dropdown |
87
|
|
|
{ |
88
|
|
|
$dropdown = new Dropdown(); |
89
|
|
|
$dropdown[] = $this->createFileCategoriesItem(); |
90
|
|
|
$dropdown[] = $this->createFilesItem(); |
91
|
|
|
$dropdown[] = $this->createFileDownloadsItem(); |
92
|
|
|
|
93
|
|
|
return $dropdown; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return Item |
98
|
|
|
* @throws \Opulence\Routing\Urls\UrlException |
99
|
|
|
*/ |
100
|
|
|
protected function createFileCategoriesItem(): Item |
101
|
|
|
{ |
102
|
|
|
$text = 'files:fileCategories'; |
103
|
|
|
$icon = 'folder'; |
104
|
|
|
|
105
|
|
|
$button = $this->buttonFactory->createFromName($text, Route::FILE_CATEGORIES_LIST, [], $icon); |
106
|
|
|
$resource = $this->getAdminResource(Resource::FILE_CATEGORIES); |
107
|
|
|
|
108
|
|
|
$item = new Item($button); |
109
|
|
|
$item->setResource($resource); |
110
|
|
|
|
111
|
|
|
return $item; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return Item |
116
|
|
|
* @throws \Opulence\Routing\Urls\UrlException |
117
|
|
|
*/ |
118
|
|
|
protected function createFilesItem(): Item |
119
|
|
|
{ |
120
|
|
|
$text = 'files:files'; |
121
|
|
|
$icon = 'file_copy'; |
122
|
|
|
|
123
|
|
|
$button = $this->buttonFactory->createFromName($text, Route::FILES_LIST, [], $icon); |
124
|
|
|
$resource = $this->getAdminResource(Resource::FILES); |
125
|
|
|
|
126
|
|
|
$item = new Item($button); |
127
|
|
|
$item->setResource($resource); |
128
|
|
|
|
129
|
|
|
return $item; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return Item |
134
|
|
|
* @throws \Opulence\Routing\Urls\UrlException |
135
|
|
|
*/ |
136
|
|
|
protected function createFileDownloadsItem(): Item |
137
|
|
|
{ |
138
|
|
|
$text = 'files:fileDownloads'; |
139
|
|
|
$icon = 'file_download'; |
140
|
|
|
|
141
|
|
|
$button = $this->buttonFactory->createFromName($text, Route::FILE_DOWNLOADS_LIST, [], $icon); |
142
|
|
|
$resource = $this->getAdminResource(Resource::FILE_DOWNLOADS); |
143
|
|
|
|
144
|
|
|
$item = new Item($button); |
145
|
|
|
$item->setResource($resource); |
146
|
|
|
|
147
|
|
|
return $item; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param string $resource |
152
|
|
|
* |
153
|
|
|
* @return string |
154
|
|
|
*/ |
155
|
|
|
protected function getAdminResource(string $resource): string |
156
|
|
|
{ |
157
|
|
|
return sprintf('admin_resource_%s', $resource); |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.