Passed
Push — master ( 806b7a...235898 )
by
unknown
14:08
created

AbstractModuleController::getHref()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the TYPO3 CMS project.
5
 *
6
 * It is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License, either version 2
8
 * of the License, or any later version.
9
 *
10
 * For the full copyright and license information, please read the
11
 * LICENSE.txt file that was distributed with this source code.
12
 *
13
 * The TYPO3 project - inspiring people to share!
14
 */
15
16
namespace TYPO3\CMS\Extensionmanager\Controller;
17
18
use TYPO3\CMS\Backend\View\BackendTemplateView;
19
use TYPO3\CMS\Core\Core\Environment;
20
21
/**
22
 * Abstract action controller.
23
 * @internal This class is a specific controller implementation and is not considered part of the Public TYPO3 API.
24
 */
25
class AbstractModuleController extends AbstractController
26
{
27
    /**
28
     * BackendTemplateContainer
29
     *
30
     * @var BackendTemplateView
31
     */
32
    protected $view;
33
34
    /**
35
     * Backend Template Container
36
     *
37
     * @var string
38
     */
39
    protected $defaultViewObjectName = BackendTemplateView::class;
40
41
    /**
42
     * Resolve view and initialize the general view-variables extensionName,
43
     * controllerName and actionName based on the request object
44
     *
45
     * @return \TYPO3\CMS\Fluid\View\TemplateView
46
     */
47
    protected function resolveView()
48
    {
49
        $view = parent::resolveView();
50
        $view->assignMultiple([
51
            'extensionName' => $this->request->getControllerExtensionName(),
52
            'controllerName' => $this->request->getControllerName(),
53
            'actionName' => $this->request->getControllerActionName()
54
        ]);
55
        return $view;
56
    }
57
58
    /**
59
     * Generates the action menu
60
     */
61
    protected function generateMenu()
62
    {
63
        $menuItems = [
64
            'installedExtensions' => [
65
                'controller' => 'List',
66
                'action' => 'index',
67
                'label' => $this->translate('installedExtensions')
68
            ]
69
        ];
70
71
        if (!$this->settings['offlineMode'] && !Environment::isComposerMode()) {
72
            $menuItems['getExtensions'] = [
73
                'controller' => 'List',
74
                'action' => 'ter',
75
                'label' => $this->translate('getExtensions')
76
            ];
77
            $menuItems['distributions'] = [
78
                'controller' => 'List',
79
                'action' => 'distributions',
80
                'label' => $this->translate('distributions')
81
            ];
82
83
            if ($this->actionMethodName === 'showAllVersionsAction') {
84
                $menuItems['showAllVersions'] = [
85
                    'controller' => 'List',
86
                    'action' => 'showAllVersions',
87
                    'label' => $this->translate('showAllVersions') . ' ' . $this->request->getArgument('extensionKey')
0 ignored issues
show
Bug introduced by
Are you sure $this->request->getArgument('extensionKey') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

87
                    'label' => $this->translate('showAllVersions') . ' ' . /** @scrutinizer ignore-type */ $this->request->getArgument('extensionKey')
Loading history...
88
                ];
89
            }
90
        }
91
92
        $menu = $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
93
        $menu->setIdentifier('ExtensionManagerModuleMenu');
94
95
        foreach ($menuItems as  $menuItemConfig) {
96
            if ($this->request->getControllerName() === $menuItemConfig['controller']) {
97
                $isActive = $this->request->getControllerActionName() === $menuItemConfig['action'] ? true : false;
98
            } else {
99
                $isActive = false;
100
            }
101
            $menuItem = $menu->makeMenuItem()
102
                ->setTitle($menuItemConfig['label'])
103
                ->setHref($this->uriBuilder->reset()->uriFor($menuItemConfig['action'], [], $menuItemConfig['controller']))
104
                ->setActive($isActive);
105
            $menu->addMenuItem($menuItem);
106
        }
107
108
        $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
109
        $this->view->getModuleTemplate()->setFlashMessageQueue($this->getFlashMessageQueue());
110
    }
111
}
112