TYPO3  7.6
ReviewController.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Workspaces\Controller;
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 
22 
27 {
34  {
35  parent::initializeView($view);
36  $this->registerButtons();
37  $this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
38  }
39 
43  protected function registerButtons()
44  {
45  $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
46  $currentRequest = $this->request;
47  $moduleName = $currentRequest->getPluginName();
48  $getVars = $this->request->getArguments();
49  $extensionName = $currentRequest->getControllerExtensionName();
50  if (count($getVars) === 0) {
51  $modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
52  $getVars = array('id', 'M', $modulePrefix);
53  }
54  $shortcutButton = $buttonBar->makeShortcutButton()
55  ->setModuleName($moduleName)
56  ->setGetVariables($getVars);
57  $buttonBar->addButton($shortcutButton);
58  }
59 
66  public function indexAction()
67  {
69  $wsService = GeneralUtility::makeInstance(WorkspaceService::class);
70  $this->view->assign('showGrid', !($GLOBALS['BE_USER']->workspace === 0 && !$GLOBALS['BE_USER']->isAdmin()));
71  $this->view->assign('showAllWorkspaceTab', true);
72  $this->view->assign('pageUid', GeneralUtility::_GP('id'));
73  if (GeneralUtility::_GP('id')) {
74  $pageRecord = BackendUtility::getRecord('pages', GeneralUtility::_GP('id'));
75  $this->view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation($pageRecord);
76  $this->view->assign('pageTitle', BackendUtility::getRecordTitle('pages', $pageRecord));
77  }
78  $this->view->assign('showLegend', !($GLOBALS['BE_USER']->workspace === 0 && !$GLOBALS['BE_USER']->isAdmin()));
79  $wsList = $wsService->getAvailableWorkspaces();
80  $activeWorkspace = $GLOBALS['BE_USER']->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 (!$GLOBALS['BE_USER']->isAdmin()) {
86  $wsCur = array($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  $GLOBALS['BE_USER']->setWorkspace($activeWorkspace);
94  $performWorkspaceSwitch = true;
95  BackendUtility::setUpdateSignal('updatePageTree');
97  $this->redirect('fullIndex');
98  }
99  }
100  }
101  $this->pageRenderer->addInlineSetting('Workspaces', 'isLiveWorkspace', (int)$GLOBALS['BE_USER']->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  $this->view->assign('performWorkspaceSwitch', $performWorkspaceSwitch);
106  $this->view->assign('workspaceList', $wsList);
107  $this->view->assign('activeWorkspaceUid', $activeWorkspace);
108  $this->view->assign('activeWorkspaceTitle', WorkspaceService::getWorkspaceTitle($activeWorkspace));
109  if ($wsService->canCreatePreviewLink(GeneralUtility::_GP('id'), $activeWorkspace)) {
110  $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
111  $iconFactory = $this->view->getModuleTemplate()->getIconFactory();
112  $showButton = $buttonBar->makeLinkButton()
113  ->setHref('#')
114  ->setOnClick('TYPO3.Workspaces.Actions.generateWorkspacePreviewLinksForAllLanguages();return false;')
115  ->setTitle($this->getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:tooltip.generatePagePreview', true))
116  ->setIcon($iconFactory->getIcon('module-workspaces-action-preview-link', Icon::SIZE_SMALL));
117  $buttonBar->addButton($showButton);
118  }
119  $this->view->assign('showPreviewLink', $wsService->canCreatePreviewLink(GeneralUtility::_GP('id'), $activeWorkspace));
120  $GLOBALS['BE_USER']->setAndSaveSessionData('tx_workspace_activeWorkspace', $activeWorkspace);
121  }
122 
129  public function fullIndexAction()
130  {
131  $wsService = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\WorkspaceService::class);
132  $wsList = $wsService->getAvailableWorkspaces();
133 
134  if (!$GLOBALS['BE_USER']->isAdmin()) {
135  $activeWorkspace = $GLOBALS['BE_USER']->workspace;
136  $wsCur = array($activeWorkspace => true);
137  $wsList = array_intersect_key($wsList, $wsCur);
138  }
139 
140  $this->pageRenderer->addInlineSetting('Workspaces', 'workspaceTabs', $this->prepareWorkspaceTabs($wsList, WorkspaceService::SELECT_ALL_WORKSPACES));
141  $this->pageRenderer->addInlineSetting('Workspaces', 'activeWorkspaceId', WorkspaceService::SELECT_ALL_WORKSPACES);
142  $this->view->assign('pageUid', GeneralUtility::_GP('id'));
143  $this->view->assign('showGrid', true);
144  $this->view->assign('showLegend', true);
145  $this->view->assign('showAllWorkspaceTab', true);
146  $this->view->assign('workspaceList', $wsList);
147  $this->view->assign('activeWorkspaceUid', WorkspaceService::SELECT_ALL_WORKSPACES);
148  $this->view->assign('showPreviewLink', false);
149  $GLOBALS['BE_USER']->setAndSaveSessionData('tx_workspace_activeWorkspace', WorkspaceService::SELECT_ALL_WORKSPACES);
150  // set flag for javascript
151  $this->pageRenderer->addInlineSetting('Workspaces', 'allView', '1');
152  }
153 
160  public function singleIndexAction()
161  {
162  $wsService = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\WorkspaceService::class);
163  $wsList = $wsService->getAvailableWorkspaces();
164  $activeWorkspace = $GLOBALS['BE_USER']->workspace;
165  $wsCur = array($activeWorkspace => true);
166  $wsList = array_intersect_key($wsList, $wsCur);
167  $this->view->assign('pageUid', GeneralUtility::_GP('id'));
168  $this->view->assign('showGrid', true);
169  $this->view->assign('showAllWorkspaceTab', false);
170  $this->view->assign('workspaceList', $wsList);
171  $this->view->assign('backendDomain', GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'));
172  $this->pageRenderer->addInlineSetting('Workspaces', 'singleView', '1');
173  }
174 
180  protected function initializeAction()
181  {
182  parent::initializeAction();
183  $this->pageRenderer->addJsFile('sysext/backend/Resources/Public/JavaScript/ExtDirect.StateProvider.js');
185  $flashMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage::class, $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:warning.oldStyleWorkspaceInUser'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING);
187  $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
189  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
190  $defaultFlashMessageQueue->enqueue($flashMessage);
191  }
192  $this->pageRenderer->loadExtJS();
193  $states = $GLOBALS['BE_USER']->uc['moduleData']['Workspaces']['States'];
194  $this->pageRenderer->addInlineSetting('Workspaces', 'States', $states);
195  // Load JavaScript:
196  $this->pageRenderer->addExtDirectCode(array(
197  'TYPO3.Workspaces'
198  ));
199  $this->pageRenderer->addJsFile('sysext/backend/Resources/Public/JavaScript/extjs/ux/Ext.grid.RowExpander.js');
200  $this->pageRenderer->addJsFile('sysext/backend/Resources/Public/JavaScript/extjs/ux/Ext.app.SearchField.js');
201  $this->pageRenderer->addJsFile('sysext/backend/Resources/Public/JavaScript/extjs/ux/Ext.ux.FitToParent.js');
202  $resourcePath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('workspaces') . 'Resources/Public/JavaScript/';
203 
204  // @todo Integrate additional stylesheet resources
205  $this->pageRenderer->addCssFile($resourcePath . 'gridfilters/css/GridFilters.css');
206  $this->pageRenderer->addCssFile($resourcePath . 'gridfilters/css/RangeMenu.css');
207 
208  $filters = array(
209  $resourcePath . 'gridfilters/menu/RangeMenu.js',
210  $resourcePath . 'gridfilters/menu/ListMenu.js',
211  $resourcePath . 'gridfilters/GridFilters.js',
212  $resourcePath . 'gridfilters/filter/Filter.js',
213  $resourcePath . 'gridfilters/filter/StringFilter.js',
214  $resourcePath . 'gridfilters/filter/DateFilter.js',
215  $resourcePath . 'gridfilters/filter/ListFilter.js',
216  $resourcePath . 'gridfilters/filter/NumericFilter.js',
217  $resourcePath . 'gridfilters/filter/BooleanFilter.js',
218  $resourcePath . 'gridfilters/filter/BooleanFilter.js',
219  );
220 
221  $custom = $this->getAdditionalResourceService()->getJavaScriptResources();
222 
223  $resources = array(
224  $resourcePath . 'Component/RowDetailTemplate.js',
225  $resourcePath . 'Component/RowExpander.js',
226  $resourcePath . 'Component/TabPanel.js',
227  $resourcePath . 'Store/mainstore.js',
228  $resourcePath . 'configuration.js',
229  $resourcePath . 'helpers.js',
230  $resourcePath . 'actions.js',
231  $resourcePath . 'component.js',
232  $resourcePath . 'toolbar.js',
233  $resourcePath . 'grid.js',
234  $resourcePath . 'workspaces.js'
235  );
236 
237  $javaScriptFiles = array_merge($filters, $custom, $resources);
238 
239  foreach ($javaScriptFiles as $javaScriptFile) {
240  $this->pageRenderer->addJsFile($javaScriptFile);
241  }
242  foreach ($this->getAdditionalResourceService()->getLocalizationResources() as $localizationResource) {
243  $this->pageRenderer->addInlineLanguageLabelFile($localizationResource);
244  }
245  $this->pageRenderer->addInlineSetting('RecordHistory', 'moduleUrl', BackendUtility::getModuleUrl('record_history'));
246  }
247 
255  protected function prepareWorkspaceTabs(array $workspaceList, $activeWorkspace)
256  {
257  $tabs = array();
258 
259  if ($activeWorkspace !== WorkspaceService::SELECT_ALL_WORKSPACES) {
260  $tabs[] = array(
261  'title' => $workspaceList[$activeWorkspace],
262  'itemId' => 'workspace-' . $activeWorkspace,
263  'workspaceId' => $activeWorkspace,
264  'triggerUrl' => $this->getModuleUri($activeWorkspace),
265  );
266  }
267 
268  $tabs[] = array(
269  'title' => 'All workspaces',
270  'itemId' => 'workspace-' . WorkspaceService::SELECT_ALL_WORKSPACES,
273  );
274 
275  foreach ($workspaceList as $workspaceId => $workspaceTitle) {
276  if ($workspaceId === $activeWorkspace) {
277  continue;
278  }
279  $tabs[] = array(
280  'title' => $workspaceTitle,
281  'itemId' => 'workspace-' . $workspaceId,
282  'workspaceId' => $workspaceId,
283  'triggerUrl' => $this->getModuleUri($workspaceId),
284  );
285  }
286 
287  return $tabs;
288  }
289 
296  protected function getModuleUri($workspaceId)
297  {
298  $parameters = array(
299  'id' => (int)$this->pageId,
300  'workspace' => (int)$workspaceId,
301  );
302  // The "all workspaces" tab is handled in fullIndexAction
303  // which is required as additional GET parameter in the URI then
304  if ($workspaceId === WorkspaceService::SELECT_ALL_WORKSPACES) {
305  $this->uriBuilder->reset()->uriFor('fullIndex');
306  $parameters = array_merge($parameters, $this->uriBuilder->getArguments());
307  }
308  return BackendUtility::getModuleUrl('web_WorkspacesWorkspaces', $parameters);
309  }
310 
314  protected function getLanguageService()
315  {
316  return $GLOBALS['LANG'];
317  }
318 }