TYPO3 CMS  TYPO3_7-6
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 
67  public function indexAction()
68  {
70  $wsService = GeneralUtility::makeInstance(WorkspaceService::class);
71  $this->view->assign('showGrid', !($GLOBALS['BE_USER']->workspace === 0 && !$GLOBALS['BE_USER']->isAdmin()));
72  $this->view->assign('showAllWorkspaceTab', true);
73  $this->view->assign('pageUid', GeneralUtility::_GP('id'));
74  if (GeneralUtility::_GP('id')) {
75  $pageRecord = BackendUtility::getRecord('pages', GeneralUtility::_GP('id'));
76  if ($pageRecord) {
77  $this->view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation($pageRecord);
78  $this->view->assign('pageTitle', BackendUtility::getRecordTitle('pages', $pageRecord));
79  }
80  }
81  $this->view->assign('showLegend', !($GLOBALS['BE_USER']->workspace === 0 && !$GLOBALS['BE_USER']->isAdmin()));
82  $wsList = $wsService->getAvailableWorkspaces();
83  $activeWorkspace = $GLOBALS['BE_USER']->workspace;
84  $performWorkspaceSwitch = false;
85  // Only admins see multiple tabs, we decided to use it this
86  // way for usability reasons. Regular users might be confused
87  // by switching workspaces with the tabs in a module.
88  if (!$GLOBALS['BE_USER']->isAdmin()) {
89  $wsCur = [$activeWorkspace => true];
90  $wsList = array_intersect_key($wsList, $wsCur);
91  } else {
92  if ((string)GeneralUtility::_GP('workspace') !== '') {
93  $switchWs = (int)GeneralUtility::_GP('workspace');
94  if (in_array($switchWs, array_keys($wsList)) && $activeWorkspace != $switchWs) {
95  $activeWorkspace = $switchWs;
96  $GLOBALS['BE_USER']->setWorkspace($activeWorkspace);
97  $performWorkspaceSwitch = true;
98  BackendUtility::setUpdateSignal('updatePageTree');
99  } elseif ($switchWs == WorkspaceService::SELECT_ALL_WORKSPACES) {
100  $this->redirect('fullIndex');
101  }
102  }
103  }
104  $this->pageRenderer->addInlineSetting('Workspaces', 'isLiveWorkspace', (int)$GLOBALS['BE_USER']->workspace === 0);
105  $this->pageRenderer->addInlineSetting('Workspaces', 'workspaceTabs', $this->prepareWorkspaceTabs($wsList, $activeWorkspace));
106  $this->pageRenderer->addInlineSetting('Workspaces', 'activeWorkspaceId', $activeWorkspace);
107  $this->pageRenderer->addInlineSetting('FormEngine', 'moduleUrl', BackendUtility::getModuleUrl('record_edit'));
108  $this->view->assign('performWorkspaceSwitch', $performWorkspaceSwitch);
109  $this->view->assign('workspaceList', $wsList);
110  $this->view->assign('activeWorkspaceUid', $activeWorkspace);
111  $this->view->assign('activeWorkspaceTitle', WorkspaceService::getWorkspaceTitle($activeWorkspace));
112  if ($wsService->canCreatePreviewLink(GeneralUtility::_GP('id'), $activeWorkspace)) {
113  $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
114  $iconFactory = $this->view->getModuleTemplate()->getIconFactory();
115  $showButton = $buttonBar->makeLinkButton()
116  ->setHref('#')
117  ->setOnClick('TYPO3.Workspaces.Actions.generateWorkspacePreviewLinksForAllLanguages();return false;')
118  ->setTitle($this->getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:tooltip.generatePagePreview'))
119  ->setIcon($iconFactory->getIcon('module-workspaces-action-preview-link', Icon::SIZE_SMALL));
120  $buttonBar->addButton($showButton);
121  }
122  $this->view->assign('showPreviewLink', $wsService->canCreatePreviewLink(GeneralUtility::_GP('id'), $activeWorkspace));
123  $GLOBALS['BE_USER']->setAndSaveSessionData('tx_workspace_activeWorkspace', $activeWorkspace);
124  }
125 
132  public function fullIndexAction()
133  {
134  $wsService = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\WorkspaceService::class);
135  $wsList = $wsService->getAvailableWorkspaces();
136 
137  if (!$GLOBALS['BE_USER']->isAdmin()) {
138  $activeWorkspace = $GLOBALS['BE_USER']->workspace;
139  $wsCur = [$activeWorkspace => true];
140  $wsList = array_intersect_key($wsList, $wsCur);
141  }
142 
143  $this->pageRenderer->addInlineSetting('Workspaces', 'workspaceTabs', $this->prepareWorkspaceTabs($wsList, WorkspaceService::SELECT_ALL_WORKSPACES));
144  $this->pageRenderer->addInlineSetting('Workspaces', 'activeWorkspaceId', WorkspaceService::SELECT_ALL_WORKSPACES);
145  $this->view->assign('pageUid', GeneralUtility::_GP('id'));
146  $this->view->assign('showGrid', true);
147  $this->view->assign('showLegend', true);
148  $this->view->assign('showAllWorkspaceTab', true);
149  $this->view->assign('workspaceList', $wsList);
150  $this->view->assign('activeWorkspaceUid', WorkspaceService::SELECT_ALL_WORKSPACES);
151  $this->view->assign('showPreviewLink', false);
152  $GLOBALS['BE_USER']->setAndSaveSessionData('tx_workspace_activeWorkspace', WorkspaceService::SELECT_ALL_WORKSPACES);
153  // set flag for javascript
154  $this->pageRenderer->addInlineSetting('Workspaces', 'allView', '1');
155  }
156 
163  public function singleIndexAction()
164  {
165  $wsService = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\WorkspaceService::class);
166  $wsList = $wsService->getAvailableWorkspaces();
167  $activeWorkspace = $GLOBALS['BE_USER']->workspace;
168  $wsCur = [$activeWorkspace => true];
169  $wsList = array_intersect_key($wsList, $wsCur);
170  $backendDomain = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY');
171  $this->view->assign('pageUid', GeneralUtility::_GP('id'));
172  $this->view->assign('showGrid', true);
173  $this->view->assign('showAllWorkspaceTab', false);
174  $this->view->assign('workspaceList', $wsList);
175  $this->view->assign('backendDomain', $backendDomain);
176  // Setting the document.domain early before JavScript
177  // libraries are loaded, try to access top frame reference
178  // and possibly run into some CORS issue
179  $this->pageRenderer->setMetaCharsetTag(
180  $this->pageRenderer->getMetaCharsetTag() . LF
181  . GeneralUtility::wrapJS('document.domain = ' . GeneralUtility::quoteJSvalue($backendDomain) . ';')
182  );
183  $this->pageRenderer->addInlineSetting('Workspaces', 'singleView', '1');
184  }
185 
191  protected function initializeAction()
192  {
193  parent::initializeAction();
194  $backendRelPath = ExtensionManagementUtility::extRelPath('backend');
195  $this->pageRenderer->addJsFile($backendRelPath . 'Resources/Public/JavaScript/ExtDirect.StateProvider.js');
197  $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);
199  $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
201  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
202  $defaultFlashMessageQueue->enqueue($flashMessage);
203  }
204  $this->pageRenderer->loadExtJS();
205  $states = $GLOBALS['BE_USER']->uc['moduleData']['Workspaces']['States'];
206  $this->pageRenderer->addInlineSetting('Workspaces', 'States', $states);
207  // Load JavaScript:
208  $this->pageRenderer->addExtDirectCode([
209  'TYPO3.Workspaces'
210  ]);
211  $this->pageRenderer->addJsFile($backendRelPath . 'Resources/Public/JavaScript/extjs/ux/Ext.grid.RowExpander.js');
212  $this->pageRenderer->addJsFile($backendRelPath . 'Resources/Public/JavaScript/extjs/ux/Ext.app.SearchField.js');
213  $this->pageRenderer->addJsFile($backendRelPath . 'Resources/Public/JavaScript/extjs/ux/Ext.ux.FitToParent.js');
214  $resourcePath = ExtensionManagementUtility::extRelPath('workspaces') . 'Resources/Public/JavaScript/';
215 
216  // @todo Integrate additional stylesheet resources
217  $this->pageRenderer->addCssFile($resourcePath . 'gridfilters/css/GridFilters.css');
218  $this->pageRenderer->addCssFile($resourcePath . 'gridfilters/css/RangeMenu.css');
219 
220  $filters = [
221  $resourcePath . 'gridfilters/menu/RangeMenu.js',
222  $resourcePath . 'gridfilters/menu/ListMenu.js',
223  $resourcePath . 'gridfilters/GridFilters.js',
224  $resourcePath . 'gridfilters/filter/Filter.js',
225  $resourcePath . 'gridfilters/filter/StringFilter.js',
226  $resourcePath . 'gridfilters/filter/DateFilter.js',
227  $resourcePath . 'gridfilters/filter/ListFilter.js',
228  $resourcePath . 'gridfilters/filter/NumericFilter.js',
229  $resourcePath . 'gridfilters/filter/BooleanFilter.js',
230  $resourcePath . 'gridfilters/filter/BooleanFilter.js',
231  ];
232 
233  $custom = $this->getAdditionalResourceService()->getJavaScriptResources();
234 
235  $resources = [
236  $resourcePath . 'Component/RowDetailTemplate.js',
237  $resourcePath . 'Component/RowExpander.js',
238  $resourcePath . 'Component/TabPanel.js',
239  $resourcePath . 'Store/mainstore.js',
240  $resourcePath . 'configuration.js',
241  $resourcePath . 'helpers.js',
242  $resourcePath . 'actions.js',
243  $resourcePath . 'component.js',
244  $resourcePath . 'toolbar.js',
245  $resourcePath . 'grid.js',
246  $resourcePath . 'workspaces.js'
247  ];
248 
249  $javaScriptFiles = array_merge($filters, $custom, $resources);
250 
251  foreach ($javaScriptFiles as $javaScriptFile) {
252  $this->pageRenderer->addJsFile($javaScriptFile);
253  }
254  foreach ($this->getAdditionalResourceService()->getLocalizationResources() as $localizationResource) {
255  $this->pageRenderer->addInlineLanguageLabelFile($localizationResource);
256  }
257  $this->pageRenderer->addInlineSetting('FormEngine', 'moduleUrl', BackendUtility::getModuleUrl('record_edit'));
258  $this->pageRenderer->addInlineSetting('RecordHistory', 'moduleUrl', BackendUtility::getModuleUrl('record_history'));
259  }
260 
268  protected function prepareWorkspaceTabs(array $workspaceList, $activeWorkspace)
269  {
270  $tabs = [];
271 
272  if ($activeWorkspace !== WorkspaceService::SELECT_ALL_WORKSPACES) {
273  $tabs[] = [
274  'title' => $workspaceList[$activeWorkspace],
275  'itemId' => 'workspace-' . $activeWorkspace,
276  'workspaceId' => $activeWorkspace,
277  'triggerUrl' => $this->getModuleUri($activeWorkspace),
278  ];
279  }
280 
281  $tabs[] = [
282  'title' => 'All workspaces',
283  'itemId' => 'workspace-' . WorkspaceService::SELECT_ALL_WORKSPACES,
286  ];
287 
288  foreach ($workspaceList as $workspaceId => $workspaceTitle) {
289  if ($workspaceId === $activeWorkspace) {
290  continue;
291  }
292  $tabs[] = [
293  'title' => $workspaceTitle,
294  'itemId' => 'workspace-' . $workspaceId,
295  'workspaceId' => $workspaceId,
296  'triggerUrl' => $this->getModuleUri($workspaceId),
297  ];
298  }
299 
300  return $tabs;
301  }
302 
309  protected function getModuleUri($workspaceId)
310  {
311  $parameters = [
312  'id' => (int)$this->pageId,
313  'workspace' => (int)$workspaceId,
314  ];
315  // The "all workspaces" tab is handled in fullIndexAction
316  // which is required as additional GET parameter in the URI then
317  if ($workspaceId === WorkspaceService::SELECT_ALL_WORKSPACES) {
318  $this->uriBuilder->reset()->uriFor('fullIndex');
319  $parameters = array_merge($parameters, $this->uriBuilder->getArguments());
320  }
321  return BackendUtility::getModuleUrl('web_WorkspacesWorkspaces', $parameters);
322  }
323 
327  protected function getLanguageService()
328  {
329  return $GLOBALS['LANG'];
330  }
331 }
prepareWorkspaceTabs(array $workspaceList, $activeWorkspace)
redirect($actionName, $controllerName=null, $extensionName=null, array $arguments=null, $pageUid=null, $delay=0, $statusCode=303)
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']
static wrapJS($string, $linebreak=true)