TYPO3 CMS  TYPO3_7-6
AbstractModuleController.php
Go to the documentation of this file.
1 <?php
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  */
19 
24 {
30  protected $view;
31 
37  protected $defaultViewObjectName = BackendTemplateView::class;
38 
45  protected function resolveView()
46  {
47  $view = parent::resolveView();
48  $view->assignMultiple([
49  'extensionName' => $this->request->getControllerExtensionName(),
50  'controllerName' => $this->request->getControllerName(),
51  'actionName' => $this->request->getControllerActionName()
52  ]);
53  return $view;
54  }
55 
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 
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 }