3 declare(strict_types
=1);
6 * This file is part of the TYPO3 CMS project.
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.
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
15 * The TYPO3 project - inspiring people to share!
18 namespace TYPO3\CMS\Workspaces\Hook
;
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
;
30 * @internal This is a specific hook implementation and is not considered part of the Public TYPO3 API.
32 class BackendUtilityHook
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.
39 * @param string $backPath
40 * @param array $rootLine
41 * @param string $anchorSection
42 * @param string $viewScript
43 * @param string $additionalGetVars
44 * @param bool $switchFocus
46 public function preProcess(&$pageUid, $backPath, $rootLine, $anchorSection, &$viewScript, $additionalGetVars, $switchFocus)
48 if ($GLOBALS['BE_USER']->workspace
!== 0) {
49 $viewScript = (string)GeneralUtility
::makeInstance(PreviewUriBuilder
::class)->buildUriForWorkspaceSplitPreview((int)$pageUid);
50 $viewScript .= $additionalGetVars ?
: '';
55 * Use that hook to show an info message in case someone starts editing
58 * @param array $params
61 public function makeEditForm_accessCheck($params)
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);
78 return $params['hasAccess'];
82 * @return LanguageService|null
84 protected function getLanguageService(): ?LanguageService
86 return $GLOBALS['LANG'] ??
null;