Test Setup Failed
Push — master ( 195648...185a1e )
by Craig
58s queued 15s
created

ExtensionMenu::getBundleName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
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\BlocksModule\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
        $menu = $this->factory->createItem('blocksAdminMenu');
53
        if ($this->permissionApi->hasPermission($this->getBundleName() . '::', '::', ACCESS_EDIT)) {
54
            $menu->addChild('Blocks list', [
55
                'route' => 'zikulablocksmodule_admin_view',
56
            ])->setAttribute('icon', 'fas fa-table');
57
        }
58
        if ($this->permissionApi->hasPermission($this->getBundleName() . '::', '::', ACCESS_ADD)) {
59
            $menu->addChild('Create new block', [
60
                'route' => 'zikulablocksmodule_block_new',
61
            ])->setAttribute('icon', 'fas fa-plus');
62
            $menu->addChild('Create new block position', [
63
                'route' => 'zikulablocksmodule_position_edit',
64
            ])->setAttribute('icon', 'fas fa-plus');
65
        }
66
        if ($this->permissionApi->hasPermission($this->getBundleName() . '::', '::', ACCESS_ADMIN)) {
67
            $menu->addChild('Settings', [
68
                'route' => 'zikulablocksmodule_config_config',
69
            ])->setAttribute('icon', 'fas fa-wrench');
70
        }
71
72
        return 0 === $menu->count() ? null : $menu;
73
    }
74
75
    public function getBundleName(): string
76
    {
77
        return 'ZikulaBlocksModule';
78
    }
79
}
80