[BUGFIX] Fix TypeError in workspace module
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / Hook / BackendUtilityHook.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\Workspaces\Hook;
19
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
21 use TYPO3\CMS\Core\Localization\LanguageService;
22 use TYPO3\CMS\Core\Messaging\FlashMessage;
23 use TYPO3\CMS\Core\Messaging\FlashMessageService;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25 use TYPO3\CMS\Workspaces\Preview\PreviewUriBuilder;
26 use TYPO3\CMS\Workspaces\Service\StagesService;
27
28 /**
29 * Befunc service
30 * @internal This is a specific hook implementation and is not considered part of the Public TYPO3 API.
31 */
32 class BackendUtilityHook
33 {
34 /**
35 * Hooks into the \TYPO3\CMS\Backend\Utility\BackendUtility::viewOnClick and redirects to the workspace preview
36 * only if we're in a workspace and if the frontend-preview is disabled.
37 *
38 * @param int $pageUid
39 * @param string $backPath
40 * @param array $rootLine
41 * @param string $anchorSection
42 * @param string $viewScript
43 * @param string $additionalGetVars
44 * @param bool $switchFocus
45 */
46 public function preProcess(&$pageUid, $backPath, $rootLine, $anchorSection, &$viewScript, $additionalGetVars, $switchFocus)
47 {
48 if ($GLOBALS['BE_USER']->workspace !== 0) {
49 $viewScript = (string)GeneralUtility::makeInstance(PreviewUriBuilder::class)->buildUriForWorkspaceSplitPreview((int)$pageUid);
50 $viewScript .= $additionalGetVars ?: '';
51 }
52 }
53
54 /**
55 * Use that hook to show an info message in case someone starts editing
56 * a staged element
57 *
58 * @param array $params
59 * @return bool
60 */
61 public function makeEditForm_accessCheck($params)
62 {
63 if ($GLOBALS['BE_USER']->workspace !== 0 && BackendUtility::isTableWorkspaceEnabled($params['table'])) {
64 $record = BackendUtility::getRecordWSOL($params['table'], $params['uid']);
65 if (abs($record['t3ver_stage']) > StagesService::STAGE_EDIT_ID) {
66 $stages = GeneralUtility::makeInstance(StagesService::class);
67 $stageName = $stages->getStageTitle($record['t3ver_stage']);
68 $editingName = $stages->getStageTitle(StagesService::STAGE_EDIT_ID);
69 $message = $this->getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:info.elementAlreadyModified');
70 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, sprintf($message, $stageName, $editingName), '', FlashMessage::INFO, true);
71 /** @var FlashMessageService $flashMessageService */
72 $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
73 /** @var \TYPO3\CMS\Core\Messaging\FlashMessageQueue $defaultFlashMessageQueue */
74 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
75 $defaultFlashMessageQueue->enqueue($flashMessage);
76 }
77 }
78 return $params['hasAccess'];
79 }
80
81 /**
82 * @return LanguageService|null
83 */
84 protected function getLanguageService(): ?LanguageService
85 {
86 return $GLOBALS['LANG'] ?? null;
87 }
88 }