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\AdminModule\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
|
|
|
if (self::TYPE_ACCOUNT === $type) { |
47
|
|
|
return $this->getAccount(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return null; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
private function getAdmin(): ?ItemInterface |
54
|
|
|
{ |
55
|
|
|
$menu = $this->factory->createItem('adminAdminMenu'); |
56
|
|
|
if ($this->permissionApi->hasPermission($this->getBundleName() . '::', '::', ACCESS_READ)) { |
57
|
|
|
$menu->addChild('Module categories list', [ |
58
|
|
|
'route' => 'zikulaadminmodule_admin_view', |
59
|
|
|
])->setAttribute('icon', 'fas fa-list'); |
60
|
|
|
} |
61
|
|
|
if ($this->permissionApi->hasPermission($this->getBundleName() . '::', '::', ACCESS_ADD)) { |
62
|
|
|
$menu->addChild('Create new module category', [ |
63
|
|
|
'route' => 'zikulaadminmodule_admin_newcat', |
64
|
|
|
])->setAttribute('icon', 'fas fa-plus'); |
65
|
|
|
} |
66
|
|
|
if ($this->permissionApi->hasPermission($this->getBundleName() . '::', '::', ACCESS_ADD)) { |
67
|
|
|
$menu->addChild('Settings', [ |
68
|
|
|
'route' => 'zikulaadminmodule_config_config', |
69
|
|
|
])->setAttribute('icon', 'fas fa-wrench'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return 0 === $menu->count() ? null : $menu; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
private function getAccount(): ?ItemInterface |
76
|
|
|
{ |
77
|
|
|
$menu = $this->factory->createItem('adminAccountMenu'); |
78
|
|
|
|
79
|
|
|
if ($this->permissionApi->hasPermission($this->getBundleName() . '::', '::', ACCESS_ADMIN)) { |
80
|
|
|
$menu->addChild('Administration panel', [ |
81
|
|
|
'route' => 'zikulaadminmodule_admin_adminpanel', |
82
|
|
|
])->setAttribute('icon', 'fas fa-wrench'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
return 0 === $menu->count() ? null : $menu; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getBundleName(): string |
89
|
|
|
{ |
90
|
|
|
return 'ZikulaAdminModule'; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|