50a0194aecd6c7e3abc4bab26977bd416cefd9ec
[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\Extbase\Mvc\Web\Routing\UriBuilder;
18
19 /**
20 * Abstract action controller.
21 */
22 class AbstractModuleController extends AbstractController {
23
24 /**
25 * BackendTemplateContainer
26 *
27 * @var BackendTemplateView
28 */
29 protected $view;
30
31 /**
32 * Backend Template Container
33 *
34 * @var string
35 */
36 protected $defaultViewObjectName = BackendTemplateView::class;
37
38 /**
39 * Resolve view and initialize the general view-variables extensionName,
40 * controllerName and actionName based on the request object
41 *
42 * @return \TYPO3\CMS\Fluid\View\TemplateView
43 */
44 protected function resolveView()
45 {
46 $view = parent::resolveView();
47 $view->assignMultiple(array(
48 'extensionName' => $this->request->getControllerExtensionName(),
49 'controllerName' => $this->request->getControllerName(),
50 'actionName' => $this->request->getControllerActionName()
51 ));
52 return $view;
53 }
54
55 /**
56 * Generates the action menu
57 *
58 * @return void
59 */
60 protected function generateMenu()
61 {
62 $menuItems = [
63 'installedExtensions' => [
64 'controller' => 'List',
65 'action' => 'index',
66 'label' => $this->translate('installedExtensions')
67 ]
68 ];
69
70 if (!$this->settings['offlineMode'] && !$this->settings['composerMode']) {
71 $menuItems['getExtensions'] = [
72 'controller' => 'List',
73 'action' => 'ter',
74 'label' => $this->translate('getExtensions')
75 ];
76 $menuItems['distributions'] = [
77 'controller' => 'List',
78 'action' => 'distributions',
79 'label' => $this->translate('distributions')
80 ];
81
82 if ($this->actionMethodName === 'showAllVersionsAction') {
83 $menuItems['showAllVersions'] = [
84 'controller' => 'List',
85 'action' => 'showAllVersions',
86 'label' => $this->translate('showAllVersions') . ' ' . $this->request->getArgument('extensionKey')
87 ];
88 }
89 }
90
91 $uriBuilder = $this->objectManager->get(UriBuilder::class);
92 $uriBuilder->setRequest($this->request);
93
94 $menu = $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
95 $menu->setIdentifier('ExtensionManagerModuleMenu');
96
97 foreach ($menuItems as $menuItemConfig) {
98 if ($this->request->getControllerName() === $menuItemConfig['controller']) {
99 $isActive = $this->request->getControllerActionName() === $menuItemConfig['action'] ? true : false;
100 } else {
101 $isActive = false;
102 }
103 $menuItem = $menu->makeMenuItem()
104 ->setTitle($menuItemConfig['label'])
105 ->setHref($this->getHref($menuItemConfig['controller'], $menuItemConfig['action']))
106 ->setActive($isActive);
107 $menu->addMenuItem($menuItem);
108 }
109
110 $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
111 $this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
112 }
113
114 /**
115 * Creates te URI for a backend action
116 *
117 * @param string $controller
118 * @param string $action
119 * @param array $parameters
120 * @return string
121 */
122 protected function getHref($controller, $action, $parameters = [])
123 {
124 $uriBuilder = $this->objectManager->get(UriBuilder::class);
125 $uriBuilder->setRequest($this->request);
126 return $uriBuilder->reset()->uriFor($action, $parameters, $controller);
127 }
128 }