[BUGFIX] Minor code cleanups
[Packages/TYPO3.CMS.git] / typo3 / sysext / adminpanel / Classes / Utility / StateUtility.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Adminpanel\Utility;
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\Backend\FrontendBackendUserAuthentication;
20
21 /**
22 * Helper class to check if the admin panel is enabled and active from outside
23 *
24 * Useful for initialization, checks in early hooks or middleware implementations
25 */
26 class StateUtility
27 {
28 /**
29 * Checks if adminPanel was configured to be shown
30 *
31 * @return bool
32 */
33 public static function isActivatedForUser(): bool
34 {
35 $beUser = $GLOBALS['BE_USER'] ?? null;
36 if ($beUser instanceof FrontendBackendUserAuthentication) {
37 $adminPanelConfiguration = $beUser->getTSConfig()['admPanel.'] ?? [];
38 if (isset($adminPanelConfiguration['enable.'])) {
39 // only enabled if at least one module is enabled.
40 return (bool)array_filter($adminPanelConfiguration['enable.']);
41 }
42 }
43 return false;
44 }
45
46 /**
47 * Returns true if admin panel was activated
48 * (switched "on" via GUI)
49 *
50 * @return bool
51 */
52 public static function isOpen(): bool
53 {
54 $beUser = $GLOBALS['BE_USER'] ?? null;
55 return (bool)($beUser->uc['AdminPanel']['display_top'] ?? false);
56 }
57
58 public static function isActivatedInTypoScript(): bool
59 {
60 return (bool)($GLOBALS['TSFE']->config['config']['admPanel'] ?? false);
61 }
62
63 public static function isHiddenForUser(): bool
64 {
65 $beUser = $GLOBALS['BE_USER'] ?? null;
66 return $beUser->getTSConfig()['admPanel.']['hide'] ?? false;
67 }
68 }