[TASK] Decouple adminPanel from frontend
[Packages/TYPO3.CMS.git] / typo3 / sysext / adminpanel / Classes / Hooks / RenderHook.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Adminpanel\Hooks;
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 TYPO3\CMS\Adminpanel\Controller\MainController;
20 use TYPO3\CMS\Backend\FrontendBackendUserAuthentication;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
23
24 /**
25 * Hook used to postProcess output - renders the admin panel
26 */
27 class RenderHook
28 {
29
30 /**
31 * PostProcess output hook to render the admin panel
32 * We use a hook this late in the project to make sure all data is collected and can be displayed
33 *
34 * As the main content is already rendered, we use a string replace on the content to append the adminPanel
35 * to the HTML body.
36 *
37 * @param array $params
38 * @param TypoScriptFrontendController $pObj
39 */
40 public function renderAdminPanel(array $params, TypoScriptFrontendController $pObj)
41 {
42 if ($pObj->isBackendUserLoggedIn() &&
43 $GLOBALS['BE_USER'] instanceof FrontendBackendUserAuthentication &&
44 (
45 !$GLOBALS['BE_USER']->extAdminConfig['hide'] && $pObj->config['config']['admPanel']
46 )
47 ) {
48 $mainController = GeneralUtility::makeInstance(MainController::class);
49 $pObj->content = str_ireplace(
50 '</body>',
51 $mainController->render() . '</body>',
52 $pObj->content
53 );
54 }
55 }
56 }