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