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