217c6ad84a0a8e555924b298e5207df3ca8231d2
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / Hook / BackendUtilityHook.php
1 <?php
2 namespace TYPO3\CMS\Workspaces\Hook;
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\Core\Utility\GeneralUtility;
18
19 /**
20 * Befunc service
21 */
22 class BackendUtilityHook implements \TYPO3\CMS\Core\SingletonInterface
23 {
24 /**
25 * Gets a singleton instance of this object.
26 *
27 * @return \TYPO3\CMS\Workspaces\Hook\BackendUtilityHook
28 */
29 public static function getInstance()
30 {
31 return GeneralUtility::makeInstance(__CLASS__);
32 }
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 = $this->getWorkspaceService()->generateWorkspaceSplittedPreviewLink($pageUid);
50 }
51 }
52
53 /**
54 * Gets an instance of the workspaces service.
55 *
56 * @return \TYPO3\CMS\Workspaces\Service\WorkspaceService
57 */
58 protected function getWorkspaceService()
59 {
60 return GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\WorkspaceService::class);
61 }
62
63 /**
64 * Use that hook to show an info message in case someone starts editing
65 * a staged element
66 *
67 * @param array $params
68 * @return bool
69 */
70 public function makeEditForm_accessCheck($params)
71 {
72 if ($GLOBALS['BE_USER']->workspace !== 0 && $GLOBALS['TCA'][$params['table']]['ctrl']['versioningWS']) {
73 $record = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordWSOL($params['table'], $params['uid']);
74 if (abs($record['t3ver_stage']) > \TYPO3\CMS\Workspaces\Service\StagesService::STAGE_EDIT_ID) {
75 $stages = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\StagesService::class);
76 $stageName = $stages->getStageTitle($record['t3ver_stage']);
77 $editingName = $stages->getStageTitle(\TYPO3\CMS\Workspaces\Service\StagesService::STAGE_EDIT_ID);
78 $message = $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:info.elementAlreadyModified');
79 $flashMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage::class, sprintf($message, $stageName, $editingName), '', \TYPO3\CMS\Core\Messaging\FlashMessage::INFO, true);
80 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
81 $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
82 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
83 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
84 $defaultFlashMessageQueue->enqueue($flashMessage);
85 }
86 }
87 return $params['hasAccess'];
88 }
89 }