-
Notifications
You must be signed in to change notification settings - Fork 639
/
AbstractController.php
151 lines (134 loc) · 5.49 KB
/
AbstractController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Extensionmanager\Controller;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\RequestInterface;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/**
* Abstract action controller.
* @internal This class is a specific controller implementation and is not considered part of the Public TYPO3 API.
*/
class AbstractController extends ActionController
{
public const TRIGGER_RefreshModuleMenu = 'refreshModuleMenu';
public const TRIGGER_RefreshTopbar = 'refreshTopbar';
protected ModuleTemplateFactory $moduleTemplateFactory;
protected array $triggerArguments = [
self::TRIGGER_RefreshModuleMenu,
self::TRIGGER_RefreshTopbar,
];
public function injectModuleTemplateFactory(ModuleTemplateFactory $moduleTemplateFactory)
{
$this->moduleTemplateFactory = $moduleTemplateFactory;
}
/**
* Translation shortcut
*/
protected function translate(string $key, ?array $arguments = null): string
{
return LocalizationUtility::translate($key, 'extensionmanager', $arguments) ?? '';
}
/**
* Handles trigger arguments, e.g. refreshing the module menu
* widget if an extension with backend modules has been enabled
* or disabled.
*/
protected function handleTriggerArguments(ModuleTemplate $view): void
{
$triggers = [];
foreach ($this->triggerArguments as $triggerArgument) {
if ($this->request->hasArgument($triggerArgument)) {
$triggers[$triggerArgument] = $this->request->getArgument($triggerArgument);
}
}
$view->assign('triggers', $triggers);
}
/**
* Generates the action menu. Helper used in action that render backend moduleTemplate
* views and not just redirect or response download things.
*/
protected function initializeModuleTemplate(RequestInterface $request): ModuleTemplate
{
$menuItems = [
'installedExtensions' => [
'controller' => 'List',
'action' => 'index',
'label' => $this->translate('installedExtensions'),
],
'extensionComposerStatus' => [
'controller' => 'ExtensionComposerStatus',
'action' => 'list',
'label' => $this->translate('extensionComposerStatus'),
],
];
if (!(bool)($this->settings['offlineMode'] ?? false) && !Environment::isComposerMode()) {
$menuItems['getExtensions'] = [
'controller' => 'List',
'action' => 'ter',
'label' => $this->translate('getExtensions'),
];
$menuItems['distributions'] = [
'controller' => 'List',
'action' => 'distributions',
'label' => $this->translate('distributions'),
];
if ($this->actionMethodName === 'showAllVersionsAction') {
$menuItems['showAllVersions'] = [
'controller' => 'List',
'action' => 'showAllVersions',
'label' => $this->translate('showAllVersions') . ' ' . $request->getArgument('extensionKey'),
];
}
}
$view = $this->moduleTemplateFactory->create($request);
// Assign some view vars we always need.
$view->assignMultiple([
'extensionName' => $request->getControllerExtensionName(),
'controllerName' => $request->getControllerName(),
'actionName' => $request->getControllerActionName(),
]);
$menu = $view->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
$menu->setIdentifier('ExtensionManagerModuleMenu');
$menu->setLabel(
$this->translate(
'LLL:EXT:backend/Resources/Private/Language/locallang.xlf:moduleMenu.dropdown.label'
)
);
foreach ($menuItems as $menuItemConfig) {
if ($request->getControllerName() === $menuItemConfig['controller']) {
$isActive = $request->getControllerActionName() === $menuItemConfig['action'];
} else {
$isActive = false;
}
$menuItem = $menu->makeMenuItem()
->setTitle($menuItemConfig['label'])
->setHref($this->uriBuilder->reset()->uriFor($menuItemConfig['action'], [], $menuItemConfig['controller']))
->setActive($isActive);
$menu->addMenuItem($menuItem);
if ($isActive) {
$view->setTitle(
$this->translate('LLL:EXT:extensionmanager/Resources/Private/Language/locallang_mod.xlf:mlang_tabs_tab'),
$menuItemConfig['label']
);
}
}
$view->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
$view->setFlashMessageQueue($this->getFlashMessageQueue());
return $view;
}
}