Completed
Push — master ( 689e98...bb1346 )
by Craig
15:41
created

ActionsMenu::setTranslator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Zikula package.
5
 *
6
 * Copyright Zikula Foundation - http://zikula.org/
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zikula\ExtensionsModule\Menu;
13
14
use Knp\Menu\FactoryInterface;
15
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
16
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
17
use Zikula\Common\Translator\TranslatorTrait;
18
use Zikula\ExtensionsModule\Api\ExtensionApi;
19
20
class ActionsMenu implements ContainerAwareInterface
21
{
22
    use ContainerAwareTrait;
23
    use TranslatorTrait;
24
25
    public function setTranslator($translator)
26
    {
27
        $this->translator = $translator;
28
    }
29
30
    public function adminExtensionsMenu(FactoryInterface $factory, array $options)
31
    {
32
        $this->setTranslator($this->container->get('translator'));
33
        $permissionApi = $this->container->get('zikula_permissions_module.api.permission');
34
        $extension = $options['extension'];
35
        $menu = $factory->createItem('adminActions');
36
        $menu->setChildrenAttribute('class', 'list-inline');
37
38
        if (!$permissionApi->hasPermission('ZikulaExtensionsModule::', $extension->getName() . '::' . $extension->getId(), ACCESS_ADMIN)) {
39
            return $menu;
40
        }
41
42
        $csrfToken = $this->container->get('zikula_core.common.csrf_token_handler')->generate(true);
43
44
        switch ($extension->getState()) {
45
            case ExtensionApi::STATE_ACTIVE:
46
                if ($extension->getName() == 'ZikulaPageLockModule' || !\ZikulaKernel::isCoreModule($extension->getName())) {
47
                    $menu->addChild($this->__f('Deactivate %s', ['%s' => $extension->getDisplayname()]), [
48
                        'route' => 'zikulaextensionsmodule_module_deactivate',
49
                        'routeParameters' => ['id' => $extension->getId(), 'csrftoken' => $csrfToken],
50
                    ])->setAttribute('icon', 'fa fa-minus-circle')
51
                    ->setLinkAttribute('class', 'text-danger');
52
                    // or set style text-color #0c00
53
                }
54 View Code Duplication
                if (\PluginUtil::hasModulePlugins($extension->getName())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
                    $menu->addChild($this->__f('Plugins for %s', ['%s' => $extension->getDisplayname()]), [
56
                        'route' => 'zikulaextensionsmodule_admin_viewplugins',
57
                        'routeParameters' => ['bymodule' => $extension->getName(),
58
                            'csrftoken' => $csrfToken],
59
                    ])->setAttribute('icon', 'fa fa-plug')
60
                        ->setLinkAttribute('style', 'color:black');
61
                }
62
                break;
63 View Code Duplication
            case ExtensionApi::STATE_INACTIVE:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
                $menu->addChild($this->__f('Activate %s', ['%s' => $extension->getDisplayname()]), [
65
                    'route' => 'zikulaextensionsmodule_module_activate',
66
                    'routeParameters' => ['id' => $extension->getId(), 'csrftoken' => $csrfToken],
67
                ])->setAttribute('icon', 'fa fa-plus-square')
68
                    ->setLinkAttribute('class', 'text-success');
69
                $menu->addChild($this->__f('Uninstall %s', ['%s' => $extension->getDisplayname()]), [
70
                    'route' => 'zikulaextensionsmodule_module_uninstall',
71
                    'routeParameters' => ['id' => $extension->getId()],
72
                ])->setAttribute('icon', 'fa fa-trash-o')
73
                    ->setLinkAttribute('style', 'color:#c00');
74
                break;
75
            case ExtensionApi::STATE_MISSING:
76
                // Nothing to do.
77
                break;
78 View Code Duplication
            case ExtensionApi::STATE_UPGRADED:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
                $menu->addChild($this->__f('Upgrade %s', ['%s' => $extension->getDisplayname()]), [
80
                    'route' => 'zikulaextensionsmodule_module_upgrade',
81
                    'routeParameters' => ['id' => $extension->getId(), 'csrftoken' => $csrfToken],
82
                ])->setAttribute('icon', 'fa fa-refresh')
83
                    ->setLinkAttribute('style', 'color:#00c');
84
                break;
85
            case ExtensionApi::STATE_INVALID:
86
                // nothing to do.
87
                // do not allow deletion of invalid modules if previously installed (#1278)
88
                break;
89 View Code Duplication
            case ExtensionApi::STATE_NOTALLOWED:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
90
                $menu->addChild($this->__f('Remove %s', ['%s' => $extension->getDisplayname()]), [
91
                    'route' => 'zikulaextensionsmodule_module_uninstall',
92
                    'routeParameters' => ['id' => $extension->getId()],
93
                ])->setAttribute('icon', 'fa fa-trash-o')
94
                    ->setLinkAttribute('style', 'color:#c00');
95
                break;
96
            case ExtensionApi::STATE_UNINITIALISED:
97 View Code Duplication
            default:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
                if ($extension->getState() < 10) {
99
                    $menu->addChild($this->__f('Install %s', ['%s' => $extension->getDisplayname()]), [
100
                        'route' => 'zikulaextensionsmodule_module_install',
101
                        'routeParameters' => ['id' => $extension->getId()],
102
                    ])->setAttribute('icon', 'fa fa-cog')
103
                        ->setLinkAttribute('class', 'text-success');
104
                } else {
105
                    $menu->addChild($this->__f('Core compatibility information: %s', ['%s' => $extension->getDisplayname()]), [
106
                        'route' => 'zikulaextensionsmodule_module_compatibility',
107
                        'routeParameters' => ['id' => $extension->getId()],
108
                    ])->setAttribute('icon', 'fa fa-info-circle')
109
                        ->setLinkAttribute('style', 'color:black');
110
                }
111
                break;
112
        }
113
114 View Code Duplication
        if ($extension->getState() != ExtensionApi::STATE_INVALID) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
115
            $menu->addChild($this->__f('Edit %s', ['%s' => $extension->getDisplayname()]), [
116
                'route' => 'zikulaextensionsmodule_module_modify',
117
                'routeParameters' => ['id' => $extension->getId()],
118
            ])->setAttribute('icon', 'fa fa-wrench')
119
                ->setLinkAttribute('style', 'color:black');
120
        }
121
122
        return $menu;
123
    }
124
}
125