‪TYPO3CMS  9.5
MainController.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
19 use Psr\Http\Message\ServerRequestInterface;
38 
45 {
49  protected ‪$modules = [];
50 
54  protected ‪$moduleLoader;
55 
59  protected ‪$uriBuilder;
60 
65 
70 
76  public function ‪__construct(
80  ) {
81  $this->moduleLoader = ‪$moduleLoader ?? GeneralUtility::makeInstance(ModuleLoader::class);
82  $this->uriBuilder = ‪$uriBuilder ?? GeneralUtility::makeInstance(UriBuilder::class);
83  $this->configurationService = ‪$configurationService
84  ??
85  GeneralUtility::makeInstance(ConfigurationService::class);
86  $this->adminPanelModuleConfiguration = ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules'] ?? [];
87  }
88 
94  public function ‪initialize(ServerRequestInterface $request): void
95  {
96  $this->modules = $this->moduleLoader->validateSortAndInitializeModules(
97  $this->adminPanelModuleConfiguration
98  );
99 
101  $this->‪initializeModules($request, $this->modules);
102  }
103  }
104 
112  public function ‪render(ServerRequestInterface $request): string
113  {
114  // legacy handling, deprecated, will be removed in TYPO3 v10.0.
115  $adminPanelView = GeneralUtility::makeInstance(AdminPanelView::class);
116  $hookObjectContent = $adminPanelView->callDeprecatedHookObject();
117  // end legacy handling
118 
119  $resources = ‪ResourceUtility::getResources();
120 
121  $view = GeneralUtility::makeInstance(StandaloneView::class);
122  $templateNameAndPath = 'EXT:adminpanel/Resources/Private/Templates/Main.html';
123  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
124  $view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
125  $view->setLayoutRootPaths(['EXT:adminpanel/Resources/Private/Layouts']);
126 
127  $view->assignMultiple(
128  [
129  'toggleActiveUrl' => $this->‪generateBackendUrl('ajax_adminPanel_toggle'),
130  'resources' => $resources,
131  'adminPanelActive' => ‪StateUtility::isOpen(),
132  ]
133  );
134  if (‪StateUtility::isOpen()) {
135  $cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('adminpanel_requestcache');
136  $requestId = $request->getAttribute('adminPanelRequestId');
137  $data = $cache->get($requestId);
138  $moduleResources = ‪ResourceUtility::getAdditionalResourcesForModules($this->modules);
139  $settingsModules = array_filter($this->modules, function (ModuleInterface $module) {
140  return $module instanceof PageSettingsProviderInterface;
141  });
142  $parentModules = array_filter(
143  $this->modules,
144  function (ModuleInterface $module) {
145  return $module instanceof SubmoduleProviderInterface && $module instanceof ShortInfoProviderInterface;
146  }
147  );
148  $view->assignMultiple(
149  [
150  'modules' => $this->modules,
151  'settingsModules' => $settingsModules,
152  'parentModules' => $parentModules,
153  'hookObjectContent' => $hookObjectContent,
154  'saveUrl' => $this->‪generateBackendUrl('ajax_adminPanel_saveForm'),
155  'moduleResources' => $moduleResources,
156  'requestId' => $requestId,
157  'data' => $data ?? [],
158  ]
159  );
160  }
161  return $view->render();
162  }
163 
171  public function ‪storeData(ServerRequestInterface $request): void
172  {
173  if (‪StateUtility::isOpen()) {
174  $data = $this->‪storeDataPerModule(
175  $request,
176  $this->modules,
177  GeneralUtility::makeInstance(ModuleDataStorageCollection::class)
178  );
179  $cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('adminpanel_requestcache');
180  $cache->set($request->getAttribute('adminPanelRequestId'), $data);
181  $cache->collectGarbage();
182  }
183  }
184 
191  protected function ‪generateBackendUrl(string $route): string
192  {
193  return (string)$this->uriBuilder->buildUriFromRoute($route);
194  }
195 
200  protected function ‪initializeModules(ServerRequestInterface $request, array ‪$modules): void
201  {
202  foreach (‪$modules as $module) {
203  if (
204  ($module instanceof ‪InitializableInterface)
205  && (
206  (($module instanceof ‪ConfigurableInterface) && $module->isEnabled())
207  || (!($module instanceof ‪ConfigurableInterface))
208  )
209  ) {
210  $module->initializeModule($request);
211  }
212  if ($module instanceof ‪SubmoduleProviderInterface) {
213  $this->‪initializeModules($request, $module->getSubModules());
214  }
215  }
216  }
217 
224  protected function ‪storeDataPerModule(ServerRequestInterface $request, array ‪$modules, ‪ModuleDataStorageCollection $data): ‪ModuleDataStorageCollection
225  {
226  foreach (‪$modules as $module) {
227  if (
228  ($module instanceof ‪DataProviderInterface)
229  && (
230  (($module instanceof ‪ConfigurableInterface) && $module->isEnabled())
231  || (!($module instanceof ‪ConfigurableInterface))
232  )
233  ) {
234  $data->‪addModuleData($module, $module->getDataToStore($request));
235  }
236 
237  if ($module instanceof SubmoduleProviderInterface) {
238  $this->‪storeDataPerModule($request, $module->getSubModules(), $data);
239  }
240  }
241  return $data;
242  }
243 }
‪TYPO3\CMS\Adminpanel\Controller\MainController
Definition: MainController.php:45
‪TYPO3\CMS\Adminpanel\ModuleApi\ModuleDataStorageCollection\addModuleData
‪addModuleData(DataProviderInterface $module, ModuleData $moduleData)
Definition: ModuleDataStorageCollection.php:24
‪TYPO3\CMS\Adminpanel\Controller\MainController\$moduleLoader
‪ModuleLoader $moduleLoader
Definition: MainController.php:52
‪TYPO3\CMS\Adminpanel\ModuleApi\ModuleDataStorageCollection
Definition: ModuleDataStorageCollection.php:23
‪TYPO3\CMS\Adminpanel\Controller\MainController\$uriBuilder
‪UriBuilder $uriBuilder
Definition: MainController.php:56
‪TYPO3\CMS\Adminpanel\Utility\StateUtility\isActivatedForUser
‪static bool isActivatedForUser()
Definition: StateUtility.php:33
‪TYPO3\CMS\Adminpanel\Utility\ResourceUtility\getResources
‪static array getResources()
Definition: ResourceUtility.php:128
‪TYPO3\CMS\Adminpanel\Controller
Definition: AjaxController.php:4
‪TYPO3\CMS\Adminpanel\Service\ModuleLoader
Definition: ModuleLoader.php:32
‪TYPO3\CMS\Adminpanel\View\AdminPanelView
Definition: AdminPanelView.php:34
‪TYPO3\CMS\Adminpanel\ModuleApi\InitializableInterface
Definition: InitializableInterface.php:34
‪TYPO3\CMS\Adminpanel\ModuleApi\ConfigurableInterface
Definition: ConfigurableInterface.php:28
‪TYPO3\CMS\Adminpanel\ModuleApi\DataProviderInterface
Definition: DataProviderInterface.php:29
‪TYPO3\CMS\Adminpanel\Controller\MainController\__construct
‪__construct(ModuleLoader $moduleLoader=null, UriBuilder $uriBuilder=null, ConfigurationService $configurationService=null)
Definition: MainController.php:71
‪TYPO3\CMS\Adminpanel\Controller\MainController\render
‪string render(ServerRequestInterface $request)
Definition: MainController.php:107
‪TYPO3\CMS\Adminpanel\Utility\StateUtility
Definition: StateUtility.php:27
‪TYPO3\CMS\Adminpanel\ModuleApi\ShortInfoProviderInterface
Definition: ShortInfoProviderInterface.php:29
‪TYPO3\CMS\Adminpanel\Controller\MainController\$configurationService
‪ConfigurationService $configurationService
Definition: MainController.php:60
‪TYPO3\CMS\Adminpanel\Controller\MainController\initializeModules
‪initializeModules(ServerRequestInterface $request, array $modules)
Definition: MainController.php:195
‪TYPO3\CMS\Adminpanel\Service\ConfigurationService
Definition: ConfigurationService.php:33
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:35
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:34
‪TYPO3\CMS\Adminpanel\ModuleApi\ModuleInterface
Definition: ModuleInterface.php:25
‪TYPO3\CMS\Adminpanel\Controller\MainController\$adminPanelModuleConfiguration
‪array $adminPanelModuleConfiguration
Definition: MainController.php:64
‪TYPO3\CMS\Adminpanel\Controller\MainController\storeDataPerModule
‪ModuleDataStorageCollection storeDataPerModule(ServerRequestInterface $request, array $modules, ModuleDataStorageCollection $data)
Definition: MainController.php:219
‪TYPO3\CMS\Adminpanel\Controller\MainController\$modules
‪TYPO3 CMS Adminpanel ModuleApi ModuleInterface[] $modules
Definition: MainController.php:48
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:32
‪TYPO3\CMS\Adminpanel\ModuleApi\PageSettingsProviderInterface
Definition: PageSettingsProviderInterface.php:31
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Adminpanel\Controller\MainController\generateBackendUrl
‪string generateBackendUrl(string $route)
Definition: MainController.php:186
‪TYPO3\CMS\Adminpanel\Utility\StateUtility\isOpen
‪static bool isOpen()
Definition: StateUtility.php:54
‪TYPO3\CMS\Adminpanel\Utility\ResourceUtility\getAdditionalResourcesForModules
‪static array getAdditionalResourcesForModules(array $modules)
Definition: ResourceUtility.php:33
‪TYPO3\CMS\Adminpanel\Utility\ResourceUtility
Definition: ResourceUtility.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Adminpanel\ModuleApi\SubmoduleProviderInterface
Definition: SubmoduleProviderInterface.php:29
‪TYPO3\CMS\Adminpanel\Controller\MainController\storeData
‪storeData(ServerRequestInterface $request)
Definition: MainController.php:166
‪TYPO3\CMS\Adminpanel\Controller\MainController\initialize
‪initialize(ServerRequestInterface $request)
Definition: MainController.php:89