‪TYPO3CMS  9.5
ConfigurationController.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
28 use TYPO3\CMS\Core\Package\PackageManager;
34 
40 {
49  protected ‪$treeSetup = [
50  'confVars' => [
51  'label' => 'typo3ConfVars',
52  'type' => 'global',
53  'globalKey' => 'TYPO3_CONF_VARS',
54  ],
55  'tca' => [
56  'label' => 'tca',
57  'type' => 'global',
58  'globalKey' => 'TCA',
59  ],
60  'tcaDescr' => [
61  'label' => 'tcaDescr',
62  'type' => 'global',
63  'globalKey' => 'TCA_DESCR',
64  ],
65  // @deprecated will be removed in TYPO3 v10.0
66  'loadedExt' => [
67  'label' => 'loadedExt',
68  'type' => 'global',
69  'globalKey' => 'TYPO3_LOADED_EXT',
70  ],
71  'services' => [
72  'label' => 't3services',
73  'key' => 'services',
74  'type' => 'global',
75  'globalKey' => 'T3_SERVICES',
76  ],
77  'tbeModules' => [
78  'label' => 'tbemodules',
79  'type' => 'global',
80  'globalKey' => 'TBE_MODULES',
81  ],
82  'tbeModulesExt' => [
83  'label' => 'tbemodulesext',
84  'type' => 'global',
85  'globalKey' => 'TBE_MODULES_EXT',
86  ],
87  'tbeStyles' => [
88  'label' => 'tbeStyles',
89  'type' => 'global',
90  'globalKey' => 'TBE_STYLES',
91  ],
92  'userSettings' => [
93  'label' => 'usersettings',
94  'type' => 'global',
95  'globalKey' => 'TYPO3_USER_SETTINGS',
96  ],
97  'pagesTypes' => [
98  'label' => 'pagesTypes',
99  'type' => 'global',
100  'globalKey' => 'PAGES_TYPES',
101  ],
102  'beUserUc' => [
103  'label' => 'beUser',
104  'type' => 'uc',
105  ],
106  'beUserTsConfig' => [
107  'label' => 'beUserTsConfig',
108  'type' => 'beUserTsConfig',
109  ],
110  'beRoutes' => [
111  'label' => 'routes',
112  'type' => 'routes',
113  ],
114  'httpMiddlewareStacks' => [
115  'label' => 'httpMiddlewareStacks',
116  'type' => 'httpMiddlewareStacks',
117  ],
118  'siteConfiguration' => [
119  'label' => 'siteConfiguration',
120  'type' => 'siteConfiguration',
121  ],
122  ];
123 
129  protected ‪$blindedConfigurationOptions = [
130  'TYPO3_CONF_VARS' => [
131  'DB' => [
132  'database' => '******',
133  'host' => '******',
134  'password' => '******',
135  'port' => '******',
136  'socket' => '******',
137  'username' => '******',
138  'Connections' => [
139  'Default' => [
140  'dbname' => '******',
141  'host' => '******',
142  'password' => '******',
143  'port' => '******',
144  'user' => '******',
145  'unix_socket' => '******',
146  ],
147  ],
148  ],
149  'SYS' => [
150  'encryptionKey' => '******'
151  ],
152  ],
153  ];
154 
164  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
165  {
166  $backendUser = $this->‪getBackendUser();
167  $languageService = $this->‪getLanguageService();
168 
169  $queryParams = $request->getQueryParams();
170  $postValues = $request->getParsedBody();
171 
172  $moduleState = $backendUser->uc['moduleData']['system_config'] ?? [];
173 
174  // Determine validated tree key and tree detail setup
175  $selectedTreeKey = $this->treeSetup[$queryParams['tree']] ? $queryParams['tree']
176  : ($this->treeSetup[$moduleState['tree']] ? $moduleState['tree'] : key($this->treeSetup));
177  $selectedTreeDetails = $this->treeSetup[$selectedTreeKey];
178  $moduleState['tree'] = $selectedTreeKey;
179 
180  // Search string given or regex search enabled?
181  $searchString = (string)($postValues['searchString'] ? trim($postValues['searchString']) : '');
182  $moduleState['regexSearch'] = (bool)($postValues['regexSearch'] ?? $moduleState['regexSearch'] ?? false);
183 
184  // Prepare main array
185  $sortKeysByName = true;
186  if ($selectedTreeDetails['type'] === 'global') {
187  $globalArrayKey = $selectedTreeDetails['globalKey'];
188  $renderArray = ‪$GLOBALS[$globalArrayKey];
189 
190  // Hook for Processing blindedConfigurationOptions
192 
193  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][self::class]['modifyBlindedConfigurationOptions'] ?? [] as $classReference) {
194  $processingObject = GeneralUtility::makeInstance($classReference);
195  ‪$blindedConfigurationOptions = $processingObject->modifyBlindedConfigurationOptions(‪$blindedConfigurationOptions, $this);
196  }
197 
198  if (isset(‪$blindedConfigurationOptions[$globalArrayKey])) {
199  // Prepare blinding for all database connection types
200  foreach (array_keys(‪$GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']) as $connectionName) {
201  if ($connectionName !== 'Default') {
202  ‪$blindedConfigurationOptions['TYPO3_CONF_VARS']['DB']['Connections'][$connectionName] =
203  ‪$blindedConfigurationOptions['TYPO3_CONF_VARS']['DB']['Connections']['Default'];
204  }
205  }
207  $renderArray,
209  );
210  }
211  } elseif ($selectedTreeDetails['type'] === 'beUserTsConfig') {
212  $renderArray = $backendUser->getTSConfig();
213  } elseif ($selectedTreeDetails['type'] === 'uc') {
214  $renderArray = $backendUser->uc;
215  } elseif ($selectedTreeDetails['type'] === 'routes') {
216  $router = GeneralUtility::makeInstance(Router::class);
217  $routes = $router->getRoutes();
218  $renderArray = [];
219  foreach ($routes as $identifier => $route) {
221  $renderArray[$identifier] = [
222  'path' => $route->getPath(),
223  'options' => $route->getOptions()
224  ];
225  }
226  } elseif ($selectedTreeDetails['type'] === 'httpMiddlewareStacks') {
227  // Keep the order of the keys
228  $sortKeysByName = false;
229  $stackResolver = GeneralUtility::makeInstance(
230  MiddlewareStackResolver::class,
231  GeneralUtility::makeInstance(PackageManager::class),
232  GeneralUtility::makeInstance(DependencyOrderingService::class),
233  GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_core')
234  );
235  $renderArray = [];
236  foreach (['frontend', 'backend'] as $stackName) {
237  // reversing the array allows the admin to read the stack from top to bottom
238  $renderArray[$stackName] = array_reverse($stackResolver->resolve($stackName));
239  }
240  } elseif ($selectedTreeDetails['type'] === 'siteConfiguration') {
241  $renderArray = GeneralUtility::makeInstance(SiteTcaConfiguration::class)->getTca();
242  } else {
243  throw new \RuntimeException('Unknown array type "' . $selectedTreeDetails['type'] . '"', 1507845662);
244  }
245  if ($sortKeysByName) {
247  }
248 
249  // Prepare array renderer class, apply search and expand / collapse states
250  $arrayBrowser = GeneralUtility::makeInstance(ArrayBrowser::class);
251  $arrayBrowser->dontLinkVar = true;
252  $arrayBrowser->searchKeysToo = true;
253  $arrayBrowser->regexMode = $moduleState['regexSearch'];
254  $node = $queryParams['node'];
255  if ($searchString) {
256  $arrayBrowser->depthKeys = $arrayBrowser->getSearchKeys($renderArray, '', $searchString, []);
257  } elseif (is_array($node)) {
258  $newExpandCollapse = $arrayBrowser->depthKeys($node, $moduleState['node_' . $selectedTreeKey]);
259  $arrayBrowser->depthKeys = $newExpandCollapse;
260  $moduleState['node_' . $selectedTreeKey] = $newExpandCollapse;
261  } else {
262  $arrayBrowser->depthKeys = $moduleState['node_' . $selectedTreeKey] ?? [];
263  }
264 
265  // Store new state
266  $backendUser->uc['moduleData']['system_config'] = $moduleState;
267  $backendUser->writeUC();
268 
269  // Render main body
270  $view = GeneralUtility::makeInstance(StandaloneView::class);
271  $view->getRequest()->setControllerExtensionName('lowlevel');
272  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
273  'EXT:lowlevel/Resources/Private/Templates/Backend/Configuration.html'
274  ));
275  $view->assignMultiple([
276  'treeName' => $selectedTreeDetails['label'],
277  'searchString' => $searchString,
278  'regexSearch' => $moduleState['regexSearch'],
279  'tree' => $arrayBrowser->tree($renderArray, ''),
280  ]);
281 
282  // Prepare module setup
283  $moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
284  $moduleTemplate->setContent($view->render());
285  $moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Lowlevel/ConfigurationView');
286 
287  // Shortcut in doc header
288  $shortcutButton = $moduleTemplate->getDocHeaderComponent()->getButtonBar()->makeShortcutButton();
289  $shortcutButton->setModuleName('system_config')
290  ->setDisplayName($languageService->sL(
291  'LLL:EXT:lowlevel/Resources/Private/Language/locallang.xlf:' . $selectedTreeDetails['label']
292  ))
293  ->setSetVariables(['tree']);
294  $moduleTemplate->getDocHeaderComponent()->getButtonBar()->addButton($shortcutButton);
295 
296  // Main drop down in doc header
297  $menu = $moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
298  $menu->setIdentifier('tree');
299  foreach ($this->treeSetup as $treeKey => $treeDetails) {
300  $menuItem = $menu->makeMenuItem();
302  $uriBuilder = GeneralUtility::makeInstance(\‪TYPO3\CMS\Backend\Routing\UriBuilder::class);
303  $menuItem->setHref((string)$uriBuilder->buildUriFromRoute('system_config', ['tree' => $treeKey]))
304  ->setTitle($languageService->sL(
305  'LLL:EXT:lowlevel/Resources/Private/Language/locallang.xlf:' . $treeDetails['label']
306  ));
307  if ($selectedTreeKey === $treeKey) {
308  $menuItem->setActive(true);
309  }
310  $menu->addMenuItem($menuItem);
311  }
312  $moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
313 
314  return new ‪HtmlResponse($moduleTemplate->renderContent());
315  }
316 
321  protected function ‪getBackendUser()
322  {
323  return ‪$GLOBALS['BE_USER'];
324  }
325 
329  protected function ‪getLanguageService()
330  {
331  return ‪$GLOBALS['LANG'];
332  }
333 }
‪TYPO3\CMS\Backend\Configuration\SiteTcaConfiguration
Definition: SiteTcaConfiguration.php:32
‪TYPO3\CMS\Lowlevel\Utility\ArrayBrowser
Definition: ArrayBrowser.php:26
‪TYPO3
‪TYPO3\CMS\Core\Http\MiddlewareStackResolver
Definition: MiddlewareStackResolver.php:29
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:614
‪TYPO3\CMS\Lowlevel\Controller\ConfigurationController\$treeSetup
‪array $treeSetup
Definition: ConfigurationController.php:48
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:40
‪TYPO3\CMS\Lowlevel\Controller\ConfigurationController\$blindedConfigurationOptions
‪array $blindedConfigurationOptions
Definition: ConfigurationController.php:127
‪TYPO3\CMS\Core\Utility\ArrayUtility\intersectRecursive
‪static array intersectRecursive(array $source, array $mask=[])
Definition: ArrayUtility.php:529
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:34
‪TYPO3\CMS\Core\Service\DependencyOrderingService
Definition: DependencyOrderingService.php:31
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Lowlevel\Controller
Definition: ConfigurationController.php:3
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:32
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:23
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Lowlevel\Controller\ConfigurationController\getLanguageService
‪LanguageService getLanguageService()
Definition: ConfigurationController.php:327
‪TYPO3\CMS\Lowlevel\Controller\ConfigurationController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: ConfigurationController.php:162
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Core\Utility\ArrayUtility\naturalKeySortRecursive
‪static bool naturalKeySortRecursive(array &$array)
Definition: ArrayUtility.php:752
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Routing\Router
Definition: Router.php:32
‪TYPO3\CMS\Lowlevel\Controller\ConfigurationController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: ConfigurationController.php:319
‪TYPO3\CMS\Lowlevel\Controller\ConfigurationController
Definition: ConfigurationController.php:40
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:25