[BUGFIX] Notify about wrong backend user group setting
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Hooks / BackendUserGroupIntegrityCheck.php
1 <?php
2 namespace TYPO3\CMS\Core\Hooks;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\DataHandling\DataHandler;
19 use TYPO3\CMS\Core\Messaging\FlashMessage;
20 use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
21 use TYPO3\CMS\Core\Messaging\FlashMessageService;
22 use TYPO3\CMS\Core\SingletonInterface;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24 use TYPO3\CMS\Core\Utility\StringUtility;
25 use TYPO3\CMS\Lang\LanguageService;
26
27 /**
28 * DataHandler hook class to check the integrity of submitted be_groups data
29 */
30 class BackendUserGroupIntegrityCheck {
31
32 /**
33 * @param string $status
34 * @param string $table
35 * @param int $id
36 * @param array $fieldArray
37 * @param DataHandler $parentObject
38 */
39 public function processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, $parentObject) {
40 if ($table !== 'be_groups' || $GLOBALS['TYPO3_CONF_VARS']['BE']['explicitADmode'] !== 'explicitAllow') {
41 return;
42 }
43
44 $backendUserGroup = BackendUtility::getRecord($table, $id, 'explicit_allowdeny');
45 $explicitAllowDenyFields = GeneralUtility::trimExplode(',', $backendUserGroup['explicit_allowdeny']);
46 foreach ($explicitAllowDenyFields as $value) {
47 if (StringUtility::beginsWith($value, 'tt_content:list_type:')) {
48 if (!in_array('tt_content:CType:list:ALLOW', $explicitAllowDenyFields, TRUE)) {
49 /** @var $flashMessage FlashMessage */
50 $flashMessage = GeneralUtility::makeInstance(
51 FlashMessage::class,
52 $this->getLanguageService()->sl('LLL:EXT:lang/locallang_core.xlf:error.backendUserGroupListTypeError.message'),
53 $this->getLanguageService()->sl('LLL:EXT:lang/locallang_core.xlf:error.backendUserGroupListTypeError.header'),
54 FlashMessage::WARNING,
55 TRUE
56 );
57 /** @var $flashMessageService FlashMessageService */
58 $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
59 /** @var $defaultFlashMessageQueue FlashMessageQueue */
60 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
61 $defaultFlashMessageQueue->enqueue($flashMessage);
62 }
63 return;
64 }
65 }
66 }
67
68 /**
69 * @return LanguageService
70 */
71 protected function getLanguageService() {
72 return $GLOBALS['LANG'];
73 }
74
75 }