[TASK] Decouple adminPanel from frontend
[Packages/TYPO3.CMS.git] / typo3 / sysext / feedit / Classes / Middleware / FrontendEditInitiator.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Feedit\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\Backend\FrontendBackendUserAuthentication;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
26
27 /**
28 * PSR-15 middleware initializing frontend editing
29 */
30 class FrontendEditInitiator implements MiddlewareInterface
31 {
32
33 /**
34 * Process an incoming server request and return a response, optionally delegating
35 * response creation to a handler.
36 *
37 * @param ServerRequestInterface $request
38 * @param RequestHandlerInterface $handler
39 * @return ResponseInterface
40 */
41 public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
42 {
43 if ($GLOBALS['BE_USER'] instanceof FrontendBackendUserAuthentication) {
44 $config = $GLOBALS['BE_USER']->getTSConfigProp('admPanel');
45 $active = (int)$GLOBALS['TSFE']->displayEditIcons === 1 || (int)$GLOBALS['TSFE']->displayFieldEditIcons === 1;
46 if ($active && isset($config['enable.'])) {
47 foreach ($config['enable.'] as $value) {
48 if ($value) {
49 if ($GLOBALS['TSFE'] instanceof TypoScriptFrontendController) {
50 // Grab the Page TSConfig property that determines which controller to use.
51 $pageTSConfig = $GLOBALS['TSFE']->getPagesTSconfig();
52 $controllerKey = $pageTSConfig['TSFE.']['frontendEditingController'] ?? 'default';
53 } else {
54 $controllerKey = 'default';
55 }
56 $controllerClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController'][$controllerKey];
57 if ($controllerClass) {
58 $GLOBALS['BE_USER']->frontendEdit = GeneralUtility::makeInstance($controllerClass);
59 }
60 break;
61 }
62 }
63 }
64 }
65 return $handler->handle($request);
66 }
67 }