19f0f73b0b050e858f3c50f5ab99c2d99fe98063
[Packages/TYPO3.CMS.git] / typo3 / sysext / adminpanel / Classes / Middleware / AdminPanelInitiator.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Adminpanel\Middleware;
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\ResponseInterface;
20 use Psr\Http\Message\ServerRequestInterface;
21 use Psr\Http\Server\MiddlewareInterface;
22 use Psr\Http\Server\RequestHandlerInterface;
23 use TYPO3\CMS\Adminpanel\Controller\MainController;
24 use TYPO3\CMS\Adminpanel\View\AdminPanelView;
25 use TYPO3\CMS\Backend\FrontendBackendUserAuthentication;
26 use TYPO3\CMS\Core\Utility\GeneralUtility;
27
28 /**
29 * PSR-15 Middleware to initialize the admin panel
30 */
31 class AdminPanelInitiator implements MiddlewareInterface
32 {
33 /**
34 * Initialize the adminPanel if
35 * - backend user is logged in
36 * - at least one adminpanel functionality is enabled
37 *
38 * @param ServerRequestInterface $request
39 * @param RequestHandlerInterface $handler
40 * @return ResponseInterface
41 */
42 public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
43 {
44 if ($GLOBALS['BE_USER'] instanceof FrontendBackendUserAuthentication) {
45 $beUser = $GLOBALS['BE_USER'];
46 // set legacy config
47 $beUser->extAdminConfig = $beUser->getTSConfig()['admPanel.'] ?? [];
48 $adminPanelConfiguration = $beUser->extAdminConfig;
49 if (isset($adminPanelConfiguration['enable.']) &&
50 ($beUser->uc['TSFE_adminConfig']['display_top'] ?? false)
51 ) {
52 // only initialize if at least one module is enabled.
53 foreach ($adminPanelConfiguration['enable.'] as $value) {
54 if ($value) {
55 $adminPanelController = GeneralUtility::makeInstance(
56 MainController::class
57 );
58 $adminPanelController->initialize($request);
59 // legacy handling
60 $beUser->adminPanel = GeneralUtility::makeInstance(AdminPanelView::class);
61 $beUser->extAdmEnabled = true;
62 break;
63 }
64 }
65 }
66 }
67 return $handler->handle($request);
68 }
69 }