[TASK] Hide "upload extension" button in composer mode
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Controller / AbstractModuleController.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Controller;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 use TYPO3\CMS\Backend\View\BackendTemplateView;
17 use TYPO3\CMS\Core\Core\Bootstrap;
18 use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
19
20 /**
21 * Abstract action controller.
22 */
23 class AbstractModuleController extends AbstractController {
24
25 /**
26 * BackendTemplateContainer
27 *
28 * @var BackendTemplateView
29 */
30 protected $view;
31
32 /**
33 * Backend Template Container
34 *
35 * @var string
36 */
37 protected $defaultViewObjectName = BackendTemplateView::class;
38
39 /**
40 * Resolve view and initialize the general view-variables extensionName,
41 * controllerName and actionName based on the request object
42 *
43 * @return \TYPO3\CMS\Fluid\View\TemplateView
44 */
45 protected function resolveView()
46 {
47 $view = parent::resolveView();
48 $view->assignMultiple(array(
49 'extensionName' => $this->request->getControllerExtensionName(),
50 'controllerName' => $this->request->getControllerName(),
51 'actionName' => $this->request->getControllerActionName()
52 ));
53 return $view;
54 }
55
56 /**
57 * Generates the action menu
58 *
59 * @return void
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'] && !Bootstrap::usesComposerClassLoading()) {
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')
88 ];
89 }
90 }
91
92 $uriBuilder = $this->objectManager->get(UriBuilder::class);
93 $uriBuilder->setRequest($this->request);
94
95 $menu = $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
96 $menu->setIdentifier('ExtensionManagerModuleMenu');
97
98 foreach ($menuItems as $menuItemConfig) {
99 if ($this->request->getControllerName() === $menuItemConfig['controller']) {
100 $isActive = $this->request->getControllerActionName() === $menuItemConfig['action'] ? true : false;
101 } else {
102 $isActive = false;
103 }
104 $menuItem = $menu->makeMenuItem()
105 ->setTitle($menuItemConfig['label'])
106 ->setHref($this->getHref($menuItemConfig['controller'], $menuItemConfig['action']))
107 ->setActive($isActive);
108 $menu->addMenuItem($menuItem);
109 }
110
111 $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
112 $this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
113 }
114
115 /**
116 * Creates te URI for a backend action
117 *
118 * @param string $controller
119 * @param string $action
120 * @param array $parameters
121 * @return string
122 */
123 protected function getHref($controller, $action, $parameters = [])
124 {
125 $uriBuilder = $this->objectManager->get(UriBuilder::class);
126 $uriBuilder->setRequest($this->request);
127 return $uriBuilder->reset()->uriFor($action, $parameters, $controller);
128 }
129 }