1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Zikula package. |
7
|
|
|
* |
8
|
|
|
* Copyright Zikula Foundation - https://ziku.la/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Zikula\RoutesModule\Menu; |
15
|
|
|
|
16
|
|
|
use Knp\Menu\FactoryInterface; |
17
|
|
|
use Knp\Menu\ItemInterface; |
18
|
|
|
use Zikula\MenuModule\ExtensionMenu\ExtensionMenuInterface; |
19
|
|
|
use Zikula\PermissionsModule\Api\ApiInterface\PermissionApiInterface; |
20
|
|
|
|
21
|
|
|
class ExtensionMenu implements ExtensionMenuInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var FactoryInterface |
25
|
|
|
*/ |
26
|
|
|
private $factory; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var PermissionApiInterface |
30
|
|
|
*/ |
31
|
|
|
private $permissionApi; |
32
|
|
|
|
33
|
|
|
public function __construct( |
34
|
|
|
FactoryInterface $factory, |
35
|
|
|
PermissionApiInterface $permissionApi |
36
|
|
|
) { |
37
|
|
|
$this->factory = $factory; |
38
|
|
|
$this->permissionApi = $permissionApi; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function get(string $type = self::TYPE_ADMIN): ?ItemInterface |
42
|
|
|
{ |
43
|
|
|
if (self::TYPE_ADMIN === $type) { |
44
|
|
|
return $this->getAdmin(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return null; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
private function getAdmin(): ?ItemInterface |
51
|
|
|
{ |
52
|
|
|
if (!$this->permissionApi->hasPermission($this->getBundleName() . ':route:', '::', ACCESS_ADMIN)) { |
53
|
|
|
return null; |
54
|
|
|
} |
55
|
|
|
$menu = $this->factory->createItem('routesAdminMenu'); |
56
|
|
|
$menu->addChild('Routes', [ |
57
|
|
|
'route' => 'zikularoutesmodule_route_adminview', |
58
|
|
|
])->setAttribute('icon', 'fas fa-list') |
59
|
|
|
->setLinkAttribute('title', 'Route list'); |
60
|
|
|
$menu->addChild('Reload routes', [ |
61
|
|
|
'route' => 'zikularoutesmodule_update_reload', |
62
|
|
|
])->setAttribute('icon', 'fas fa-sync-alt') |
63
|
|
|
->setLinkAttribute('title', 'Reload routes'); |
64
|
|
|
$menu->addChild('Reload multilingual routing settings', [ |
65
|
|
|
'route' => 'zikularoutesmodule_update_renew', |
66
|
|
|
])->setAttribute('icon', 'fas fa-sync-alt') |
67
|
|
|
->setLinkAttribute('title', 'Reload multilingual routing settings'); |
68
|
|
|
$menu->addChild('Dump exposed js routes to file', [ |
69
|
|
|
'route' => 'zikularoutesmodule_update_dumpjsroutes', |
70
|
|
|
])->setAttribute('icon', 'fas fa-file') |
71
|
|
|
->setLinkAttribute('title', 'Dump exposed js routes to file'); |
72
|
|
|
|
73
|
|
|
if ($this->permissionApi->hasPermission($this->getBundleName() . '::', '::', ACCESS_ADMIN)) { |
74
|
|
|
$menu->addChild('Configuration', [ |
75
|
|
|
'route' => 'zikularoutesmodule_config_config', |
76
|
|
|
])->setAttribute('icon', 'fas fa-wrench') |
77
|
|
|
->setLinkAttribute('title', 'Manage settings for this application'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return $menu->count() === 0 ? null : $menu; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function getBundleName(): string |
84
|
|
|
{ |
85
|
|
|
return 'ZikulaRoutesModule'; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|