‪TYPO3CMS  9.5
AdminIsSystemMaintainer.php
Go to the documentation of this file.
1 <?php
2 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 
21 
28 {
35  public function ‪render(): array
36  {
37  if ($this->data['tableName'] !== 'be_users' || $this->data['fieldName'] !== 'admin') {
38  throw new \RuntimeException(
39  'The adminIsSystemMaintainer field information can be used for admin field in be_users table only',
40  1537273550
41  );
42  }
43 
44  $resultArray = $this->‪initializeResultArray();
45  if ($this->data['command'] === 'new') {
46  // Early return on 'new' records - nothing we can do here
47  return $resultArray;
48  }
49 
50  // False if current user is not in system maintainer list or if switch to user mode is active
51  $isCurrentUserSystemMaintainer = $this->‪getBackendUser()->‪isSystemMaintainer();
52  $systemMaintainers = array_map('intval', ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['systemMaintainers'] ?? []);
53  $isTargetUserInSystemMaintainerList = in_array((int)$this->data['vanillaUid'], $systemMaintainers, true);
54 
55  if ($isTargetUserInSystemMaintainerList) {
56  $languageService = $this->‪getLanguageService();
57  $isTargetUserAdmin = (int)$this->data['databaseRow']['admin'] === 1;
58  if ($isCurrentUserSystemMaintainer) {
59  if ($isTargetUserAdmin) {
60  // User is a system maintainer
61  $fieldInformationText = '<strong>' . htmlspecialchars($languageService->sL(
62  'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:formEngine.beUser.admin.information.userIsSystemMaintainer'
63  )) . '</strong>';
64  } else {
65  // User is currently not an admin, but set as system maintainer (in-effective).
66  // If admin field is set to 1, the user is therefore system maintainer again.
67  $fieldInformationText = '<strong>' . htmlspecialchars($languageService->sL(
68  'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:formEngine.beUser.admin.information.userWillBecomeSystemMaintainer'
69  )) . '</strong>';
70  }
71  } else {
72  // User is in system maintainer list, user can not change admin and password
73  $fieldInformationText = '<strong>' . htmlspecialchars($languageService->sL(
74  'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:formEngine.beUser.admin.information.userAdminAndPasswordChangeNotAllowed'
75  )) . '</strong>';
76  }
77  $resultArray['html'] = $fieldInformationText;
78  }
79  return $resultArray;
80  }
81 
86  {
87  return ‪$GLOBALS['LANG'];
88  }
89 
94  {
95  return ‪$GLOBALS['BE_USER'];
96  }
97 }
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:88
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\isSystemMaintainer
‪bool isSystemMaintainer()
Definition: BackendUserAuthentication.php:472
‪TYPO3\CMS\Backend\Form\FieldInformation\AdminIsSystemMaintainer\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: AdminIsSystemMaintainer.php:93
‪TYPO3\CMS\Backend\Form\FieldInformation\AdminIsSystemMaintainer\render
‪array render()
Definition: AdminIsSystemMaintainer.php:35
‪TYPO3\CMS\Backend\Form\FieldInformation
Definition: AdminIsSystemMaintainer.php:3
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Backend\Form\FieldInformation\AdminIsSystemMaintainer\getLanguageService
‪LanguageService getLanguageService()
Definition: AdminIsSystemMaintainer.php:85
‪TYPO3\CMS\Backend\Form\FieldInformation\AdminIsSystemMaintainer
Definition: AdminIsSystemMaintainer.php:28
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:27