TYPO3 CMS  TYPO3_8-7
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 
59  protected function generateMenu()
60  {
61  $menuItems = [
62  'installedExtensions' => [
63  'controller' => 'List',
64  'action' => 'index',
65  'label' => $this->translate('installedExtensions')
66  ]
67  ];
68 
69  if (!$this->settings['offlineMode'] && !Bootstrap::usesComposerClassLoading()) {
70  $menuItems['getExtensions'] = [
71  'controller' => 'List',
72  'action' => 'ter',
73  'label' => $this->translate('getExtensions')
74  ];
75  $menuItems['distributions'] = [
76  'controller' => 'List',
77  'action' => 'distributions',
78  'label' => $this->translate('distributions')
79  ];
80 
81  if ($this->actionMethodName === 'showAllVersionsAction') {
82  $menuItems['showAllVersions'] = [
83  'controller' => 'List',
84  'action' => 'showAllVersions',
85  'label' => $this->translate('showAllVersions') . ' ' . $this->request->getArgument('extensionKey')
86  ];
87  }
88  }
89 
90  $uriBuilder = $this->objectManager->get(UriBuilder::class);
91  $uriBuilder->setRequest($this->request);
92 
93  $menu = $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
94  $menu->setIdentifier('ExtensionManagerModuleMenu');
95 
96  foreach ($menuItems as $menuItemConfig) {
97  if ($this->request->getControllerName() === $menuItemConfig['controller']) {
98  $isActive = $this->request->getControllerActionName() === $menuItemConfig['action'] ? true : false;
99  } else {
100  $isActive = false;
101  }
102  $menuItem = $menu->makeMenuItem()
103  ->setTitle($menuItemConfig['label'])
104  ->setHref($this->getHref($menuItemConfig['controller'], $menuItemConfig['action']))
105  ->setActive($isActive);
106  $menu->addMenuItem($menuItem);
107  }
108 
109  $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
110  $this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
111  }
112 
121  protected function getHref($controller, $action, $parameters = [])
122  {
123  $uriBuilder = $this->objectManager->get(UriBuilder::class);
124  $uriBuilder->setRequest($this->request);
125  return $uriBuilder->reset()->uriFor($action, $parameters, $controller);
126  }
127 }