1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AbterPhp\Website\Events\Listeners; |
6
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Constant\Html5; |
8
|
|
|
use AbterPhp\Framework\Events\NavigationReady; |
9
|
|
|
use AbterPhp\Framework\Html\Component\ButtonFactory; |
10
|
|
|
use AbterPhp\Framework\Navigation\Dropdown; |
11
|
|
|
use AbterPhp\Framework\Navigation\Extended; |
|
|
|
|
12
|
|
|
use AbterPhp\Framework\Navigation\Item; |
13
|
|
|
use AbterPhp\Framework\Navigation\Navigation; |
14
|
|
|
use AbterPhp\Website\Constant\Routes; |
15
|
|
|
|
16
|
|
|
class NavigationBuilder |
17
|
|
|
{ |
18
|
|
|
const BASE_WEIGHT = 400; |
19
|
|
|
|
20
|
|
|
/** @var ButtonFactory */ |
21
|
|
|
protected $buttonFactory; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* NavigationRegistrar constructor. |
25
|
|
|
* |
26
|
|
|
* @param ButtonFactory $buttonFactory |
27
|
|
|
*/ |
28
|
|
|
public function __construct(ButtonFactory $buttonFactory) |
29
|
|
|
{ |
30
|
|
|
$this->buttonFactory = $buttonFactory; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param NavigationReady $event |
35
|
|
|
*/ |
36
|
|
|
public function handle(NavigationReady $event) |
37
|
|
|
{ |
38
|
|
|
$navigation = $event->getNavigation(); |
39
|
|
|
|
40
|
|
|
if (!$navigation->hasIntent(Navigation::INTENT_PRIMARY)) { |
41
|
|
|
return; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$dropdown = new Dropdown(); |
45
|
|
|
$dropdown[] = $this->createPageItem(); |
46
|
|
|
$dropdown[] = $this->createPageLayoutItem(); |
47
|
|
|
$dropdown[] = $this->createBlockItem(); |
48
|
|
|
$dropdown[] = $this->createBlockLayoutItem(); |
49
|
|
|
|
50
|
|
|
$item = $this->createPageItem(); |
51
|
|
|
$item->setIntent(Item::INTENT_DROPDOWN); |
52
|
|
|
$item->setAttribute(Html5::ATTR_ID, 'nav-pages'); |
53
|
|
|
$item[0]->setAttribute(Html5::ATTR_HREF, 'javascript:void(0);'); |
|
|
|
|
54
|
|
|
$item[1] = $dropdown; |
55
|
|
|
|
56
|
|
|
$navigation->addItem($item, static::BASE_WEIGHT); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return Item |
61
|
|
|
* @throws \Opulence\Routing\Urls\UrlException |
62
|
|
|
*/ |
63
|
|
|
protected function createPageItem(): Item |
64
|
|
|
{ |
65
|
|
|
$text = 'website:pages'; |
66
|
|
|
$icon = 'text_format'; |
67
|
|
|
|
68
|
|
|
$button = $this->buttonFactory->createFromName($text, Routes::ROUTE_PAGES, [], $icon); |
69
|
|
|
$resource = $this->getAdminResource(Routes::ROUTE_PAGES); |
70
|
|
|
|
71
|
|
|
$item = new Item($button); |
72
|
|
|
$item->setResource($resource); |
|
|
|
|
73
|
|
|
|
74
|
|
|
return $item; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return Item |
79
|
|
|
* @throws \Opulence\Routing\Urls\UrlException |
80
|
|
|
*/ |
81
|
|
|
protected function createPageLayoutItem(): Item |
82
|
|
|
{ |
83
|
|
|
$text = 'website:pageLayouts'; |
84
|
|
|
$icon = 'view_quilt'; |
85
|
|
|
|
86
|
|
|
$button = $this->buttonFactory->createFromName($text, Routes::ROUTE_PAGE_LAYOUTS, [], $icon); |
87
|
|
|
$resource = $this->getAdminResource(Routes::ROUTE_PAGE_LAYOUTS); |
88
|
|
|
|
89
|
|
|
$item = new Item($button); |
90
|
|
|
$item->setResource($resource); |
91
|
|
|
|
92
|
|
|
return $item; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return Item |
97
|
|
|
* @throws \Opulence\Routing\Urls\UrlException |
98
|
|
|
*/ |
99
|
|
|
protected function createBlockItem(): Item |
100
|
|
|
{ |
101
|
|
|
$text = 'website:blocks'; |
102
|
|
|
$icon = 'view_module'; |
103
|
|
|
|
104
|
|
|
$button = $this->buttonFactory->createFromName($text, Routes::ROUTE_BLOCKS, [], $icon); |
105
|
|
|
$resource = $this->getAdminResource(Routes::ROUTE_BLOCKS); |
106
|
|
|
|
107
|
|
|
$item = new Item($button); |
108
|
|
|
$item->setResource($resource); |
109
|
|
|
|
110
|
|
|
return $item; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return Item |
115
|
|
|
* @throws \Opulence\Routing\Urls\UrlException |
116
|
|
|
*/ |
117
|
|
|
protected function createBlockLayoutItem(): Item |
118
|
|
|
{ |
119
|
|
|
$text = 'website:blockLayouts'; |
120
|
|
|
$icon = 'view_quilt'; |
121
|
|
|
|
122
|
|
|
$button = $this->buttonFactory->createFromName($text, Routes::ROUTE_BLOCK_LAYOUTS, [], $icon); |
123
|
|
|
$resource = $this->getAdminResource(Routes::ROUTE_BLOCK_LAYOUTS); |
124
|
|
|
|
125
|
|
|
$item = new Item($button); |
126
|
|
|
$item->setResource($resource); |
127
|
|
|
|
128
|
|
|
return $item; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param string $resource |
133
|
|
|
* |
134
|
|
|
* @return string |
135
|
|
|
*/ |
136
|
|
|
protected function getAdminResource(string $resource): string |
137
|
|
|
{ |
138
|
|
|
return sprintf('admin_resource_%s', $resource); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths