TYPO3 CMS  TYPO3_8-7
ReviewController.php
Go to the documentation of this file.
1 <?php
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 
23 
28 {
34  protected function initializeView(ViewInterface $view)
35  {
36  parent::initializeView($view);
37  $this->registerButtons();
38  $this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
39  }
40 
44  protected function registerButtons()
45  {
46  $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
47  $currentRequest = $this->request;
48  $moduleName = $currentRequest->getPluginName();
49  $getVars = $this->request->getArguments();
50  $extensionName = $currentRequest->getControllerExtensionName();
51  if (count($getVars) === 0) {
52  $modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
53  $getVars = ['id', 'M', $modulePrefix];
54  }
55  $shortcutButton = $buttonBar->makeShortcutButton()
56  ->setModuleName($moduleName)
57  ->setGetVariables($getVars);
58  $buttonBar->addButton($shortcutButton);
59  }
60 
65  public function indexAction()
66  {
67  $backendUser = $this->getBackendUser();
68  $moduleTemplate = $this->view->getModuleTemplate();
69 
71  $wsService = GeneralUtility::makeInstance(WorkspaceService::class);
72  if (GeneralUtility::_GP('id')) {
73  $pageRecord = BackendUtility::getRecord('pages', GeneralUtility::_GP('id'));
74  if ($pageRecord) {
75  $moduleTemplate->getDocHeaderComponent()->setMetaInformation($pageRecord);
76  $this->view->assign('pageTitle', BackendUtility::getRecordTitle('pages', $pageRecord));
77  }
78  }
79  $wsList = $wsService->getAvailableWorkspaces();
80  $activeWorkspace = $backendUser->workspace;
81  $performWorkspaceSwitch = false;
82  // Only admins see multiple tabs, we decided to use it this
83  // way for usability reasons. Regular users might be confused
84  // by switching workspaces with the tabs in a module.
85  if (!$backendUser->isAdmin()) {
86  $wsCur = [$activeWorkspace => true];
87  $wsList = array_intersect_key($wsList, $wsCur);
88  } else {
89  if ((string)GeneralUtility::_GP('workspace') !== '') {
90  $switchWs = (int)GeneralUtility::_GP('workspace');
91  if (in_array($switchWs, array_keys($wsList)) && $activeWorkspace != $switchWs) {
92  $activeWorkspace = $switchWs;
93  $backendUser->setWorkspace($activeWorkspace);
94  $performWorkspaceSwitch = true;
95  BackendUtility::setUpdateSignal('updatePageTree');
96  } elseif ($switchWs == WorkspaceService::SELECT_ALL_WORKSPACES) {
97  $this->redirect('fullIndex');
98  }
99  }
100  }
101  $this->pageRenderer->addInlineSetting('Workspaces', 'isLiveWorkspace', (int)$backendUser->workspace === 0);
102  $this->pageRenderer->addInlineSetting('Workspaces', 'workspaceTabs', $this->prepareWorkspaceTabs($wsList, $activeWorkspace));
103  $this->pageRenderer->addInlineSetting('Workspaces', 'activeWorkspaceId', $activeWorkspace);
104  $this->pageRenderer->addInlineSetting('FormEngine', 'moduleUrl', BackendUtility::getModuleUrl('record_edit'));
105  $workspaceIsAccessible = !($backendUser->workspace === 0 && !$backendUser->isAdmin());
106  $this->view->assignMultiple([
107  'showGrid' => $workspaceIsAccessible,
108  'showLegend' => $workspaceIsAccessible,
109  'pageUid' => (int)GeneralUtility::_GP('id'),
110  'performWorkspaceSwitch' => $performWorkspaceSwitch,
111  'workspaceList' => $this->prepareWorkspaceTabs($wsList, $activeWorkspace),
112  'activeWorkspaceUid' => $activeWorkspace,
113  'activeWorkspaceTitle' => WorkspaceService::getWorkspaceTitle($activeWorkspace),
114  'showPreviewLink' => $wsService->canCreatePreviewLink(GeneralUtility::_GP('id'), $activeWorkspace)
115  ]);
116 
117  if ($wsService->canCreatePreviewLink(GeneralUtility::_GP('id'), $activeWorkspace)) {
118  $buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();
119  $iconFactory = $moduleTemplate->getIconFactory();
120  $showButton = $buttonBar->makeLinkButton()
121  ->setHref('#')
122  ->setClasses('t3js-preview-link')
123  ->setTitle($this->getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:tooltip.generatePagePreview'))
124  ->setIcon($iconFactory->getIcon('module-workspaces-action-preview-link', Icon::SIZE_SMALL));
125  $buttonBar->addButton($showButton);
126  }
127  $backendUser->setAndSaveSessionData('tx_workspace_activeWorkspace', $activeWorkspace);
128  }
129 
134  public function fullIndexAction()
135  {
136  $wsService = GeneralUtility::makeInstance(WorkspaceService::class);
137  $wsList = $wsService->getAvailableWorkspaces();
138 
139  $activeWorkspace = $this->getBackendUser()->workspace;
140  if (!$this->getBackendUser()->isAdmin()) {
141  $wsCur = [$activeWorkspace => true];
142  $wsList = array_intersect_key($wsList, $wsCur);
143  }
144 
145  $this->pageRenderer->addInlineSetting('Workspaces', 'workspaceTabs', $this->prepareWorkspaceTabs($wsList, WorkspaceService::SELECT_ALL_WORKSPACES));
146  $this->pageRenderer->addInlineSetting('Workspaces', 'activeWorkspaceId', WorkspaceService::SELECT_ALL_WORKSPACES);
147  $this->view->assignMultiple([
148  'pageUid' => (int)GeneralUtility::_GP('id'),
149  'showGrid' => true,
150  'showLegend' => true,
151  'workspaceList' => $this->prepareWorkspaceTabs($wsList, $activeWorkspace),
152  'activeWorkspaceUid' => WorkspaceService::SELECT_ALL_WORKSPACES,
153  'showPreviewLink', false
154  ]);
155  $this->getBackendUser()->setAndSaveSessionData('tx_workspace_activeWorkspace', WorkspaceService::SELECT_ALL_WORKSPACES);
156  // set flag for javascript
157  $this->pageRenderer->addInlineSetting('Workspaces', 'allView', '1');
158  }
159 
164  public function singleIndexAction()
165  {
166  $wsService = GeneralUtility::makeInstance(WorkspaceService::class);
167  $wsList = $wsService->getAvailableWorkspaces();
168  $activeWorkspace = $this->getBackendUser()->workspace;
169  $wsCur = [$activeWorkspace => true];
170  $wsList = array_intersect_key($wsList, $wsCur);
171  $this->view->assignMultiple([
172  'pageUid' => (int)GeneralUtility::_GP('id'),
173  'showGrid' => true,
174  'workspaceList' => $this->prepareWorkspaceTabs($wsList, $activeWorkspace, false),
175  'activeWorkspaceUid' => $activeWorkspace
176  ]);
177  $this->pageRenderer->addInlineSetting('Workspaces', 'singleView', '1');
178  }
179 
183  protected function initializeAction()
184  {
185  parent::initializeAction();
186  $states = $this->getBackendUser()->uc['moduleData']['Workspaces']['States'];
187  $this->pageRenderer->addInlineSetting('Workspaces', 'States', $states);
188 
189  foreach ($this->getAdditionalResourceService()->getLocalizationResources() as $localizationResource) {
190  $this->pageRenderer->addInlineLanguageLabelFile($localizationResource);
191  }
192  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Workspaces/Backend');
193  $this->pageRenderer->addInlineSetting('FormEngine', 'moduleUrl', BackendUtility::getModuleUrl('record_edit'));
194  $this->pageRenderer->addInlineSetting('RecordHistory', 'moduleUrl', BackendUtility::getModuleUrl('record_history'));
195  $this->pageRenderer->addInlineSetting('Workspaces', 'id', (int)GeneralUtility::_GP('id'));
196  }
197 
206  protected function prepareWorkspaceTabs(array $workspaceList, $activeWorkspace, $showAllWorkspaceTab = true)
207  {
208  $tabs = [];
209 
210  if ($activeWorkspace !== WorkspaceService::SELECT_ALL_WORKSPACES) {
211  $tabs[] = [
212  'title' => $workspaceList[$activeWorkspace],
213  'itemId' => 'workspace-' . $activeWorkspace,
214  'workspaceId' => $activeWorkspace,
215  'triggerUrl' => $this->getModuleUri($activeWorkspace),
216  ];
217  }
218 
219  if ($showAllWorkspaceTab) {
220  $tabs[] = [
221  'title' => 'All workspaces',
222  'itemId' => 'workspace-' . WorkspaceService::SELECT_ALL_WORKSPACES,
225  ];
226  }
227 
228  foreach ($workspaceList as $workspaceId => $workspaceTitle) {
229  if ($workspaceId === $activeWorkspace) {
230  continue;
231  }
232  $tabs[] = [
233  'title' => $workspaceTitle,
234  'itemId' => 'workspace-' . $workspaceId,
235  'workspaceId' => $workspaceId,
236  'triggerUrl' => $this->getModuleUri($workspaceId),
237  ];
238  }
239 
240  return $tabs;
241  }
242 
249  protected function getModuleUri($workspaceId)
250  {
251  $parameters = [
252  'id' => (int)$this->pageId,
253  'workspace' => (int)$workspaceId,
254  ];
255  // The "all workspaces" tab is handled in fullIndexAction
256  // which is required as additional GET parameter in the URI then
257  if ($workspaceId === WorkspaceService::SELECT_ALL_WORKSPACES) {
258  $this->uriBuilder->reset()->uriFor('fullIndex');
259  $parameters = array_merge($parameters, $this->uriBuilder->getArguments());
260  }
261  return BackendUtility::getModuleUrl('web_WorkspacesWorkspaces', $parameters);
262  }
263 
267  protected function getLanguageService()
268  {
269  return $GLOBALS['LANG'];
270  }
271 
275  protected function getBackendUser()
276  {
277  return $GLOBALS['BE_USER'];
278  }
279 }
redirect($actionName, $controllerName=null, $extensionName=null, array $arguments=null, $pageUid=null, $delay=0, $statusCode=303)
static makeInstance($className,... $constructorArguments)
prepareWorkspaceTabs(array $workspaceList, $activeWorkspace, $showAllWorkspaceTab=true)
static setUpdateSignal($set='', $params='')
static getRecordTitle($table, $row, $prep=false, $forceResult=true)
static getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']