[TASK] Replace static calls to FlashMessageQueue to the new service
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / Hook / BackendUtilityHook.php
1 <?php
2 namespace TYPO3\CMS\Workspaces\Hook;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Befunc service
31 *
32 * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
33 */
34 class BackendUtilityHook implements \TYPO3\CMS\Core\SingletonInterface {
35
36 /**
37 * Gets a singleton instance of this object.
38 *
39 * @return \TYPO3\CMS\Workspaces\Hook\BackendUtilityHook
40 */
41 static public function getInstance() {
42 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Hook\\BackendUtilityHook');
43 }
44
45 /**
46 * Hooks into the t3lib_beFunc::viewOnClick and redirects to the workspace preview
47 * only if we're in a workspace and if the frontend-preview is disabled.
48 *
49 * @param $pageUid
50 * @param $backPath
51 * @param $rootLine
52 * @param $anchorSection
53 * @param $viewScript
54 * @param $additionalGetVars
55 * @param $switchFocus
56 * @return void
57 */
58 public function preProcess(&$pageUid, $backPath, $rootLine, $anchorSection, &$viewScript, $additionalGetVars, $switchFocus) {
59 if ($GLOBALS['BE_USER']->workspace !== 0) {
60 $viewScript = $this->getWorkspaceService()->generateWorkspaceSplittedPreviewLink($pageUid);
61 }
62 }
63
64 /**
65 * Gets an instance of the workspaces service.
66 *
67 * @return \TYPO3\CMS\Workspaces\Service\WorkspaceService
68 */
69 protected function getWorkspaceService() {
70 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\WorkspaceService');
71 }
72
73 /**
74 * Use that hook to show a info message in case someone starts editing
75 * a staged element
76 *
77 * @param $params
78 * @param $form
79 * @return boolean
80 */
81 public function makeEditForm_accessCheck($params, &$form) {
82 if ($GLOBALS['BE_USER']->workspace !== 0 && $GLOBALS['TCA'][$params['table']]['ctrl']['versioningWS']) {
83 $record = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordWSOL($params['table'], $params['uid']);
84 if (abs($record['t3ver_stage']) > \TYPO3\CMS\Workspaces\Service\StagesService::STAGE_EDIT_ID) {
85 $stages = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\StagesService');
86 $stageName = $stages->getStageTitle($record['t3ver_stage']);
87 $editingName = $stages->getStageTitle(\TYPO3\CMS\Workspaces\Service\StagesService::STAGE_EDIT_ID);
88 $message = $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:info.elementAlreadyModified');
89 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', sprintf($message, $stageName, $editingName), '', \TYPO3\CMS\Core\Messaging\FlashMessage::INFO, TRUE);
90 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
91 $flashMessageService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService');
92 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
93 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
94 $defaultFlashMessageQueue->enqueue($flashMessage);
95 }
96 }
97 return $params['hasAccess'];
98 }
99
100 }
101
102
103 ?>