‪TYPO3CMS  9.5
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 
32 
37 {
41  protected ‪$defaultViewObjectName = BackendTemplateView::class;
42 
46  protected ‪$view;
47 
51  protected ‪$pageRenderer;
52 
56  protected ‪$pageId;
57 
63  protected function ‪initializeView(‪ViewInterface ‪$view)
64  {
65  parent::initializeView(‪$view);
66  $this->‪registerButtons();
67  $this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
68  }
69 
73  protected function ‪registerButtons()
74  {
75  $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
76  $currentRequest = ‪$this->request;
77  $moduleName = $currentRequest->getPluginName();
78  $getVars = $this->request->‪getArguments();
79  ‪$extensionName = $currentRequest->getControllerExtensionName();
80  if (count($getVars) === 0) {
81  $modulePrefix = strtolower('tx_' . ‪$extensionName . '_' . $moduleName);
82  $getVars = ['id', 'route', $modulePrefix];
83  }
84  $shortcutButton = $buttonBar->makeShortcutButton()
85  ->setModuleName($moduleName)
86  ->setGetVariables($getVars);
87  $buttonBar->addButton($shortcutButton);
88  }
89 
93  protected function ‪initializeAction()
94  {
95  $this->pageRenderer = $this->‪getPageRenderer();
96  // @todo Evaluate how the (int) typecast can be used with Extbase validators/filters
97  $this->pageId = (int)GeneralUtility::_GP('id');
98  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
99  $lang = $this->‪getLanguageService();
100  ‪$icons = [
101  'language' => $iconFactory->getIcon('flags-multiple', ‪Icon::SIZE_SMALL)->render(),
102  'integrity' => $iconFactory->getIcon('status-dialog-information', ‪Icon::SIZE_SMALL)->render(),
103  'success' => $iconFactory->getIcon('status-dialog-ok', ‪Icon::SIZE_SMALL)->render(),
104  'info' => $iconFactory->getIcon('status-dialog-information', ‪Icon::SIZE_SMALL)->render(),
105  'warning' => $iconFactory->getIcon('status-dialog-warning', ‪Icon::SIZE_SMALL)->render(),
106  'error' => $iconFactory->getIcon('status-dialog-error', ‪Icon::SIZE_SMALL)->render()
107  ];
108  $this->pageRenderer->addInlineSetting('Workspaces', 'icons', ‪$icons);
109  $this->pageRenderer->addInlineSetting('Workspaces', 'id', $this->pageId);
110  $this->pageRenderer->addInlineSetting('Workspaces', 'depth', $this->pageId === 0 ? 999 : 1);
111  $this->pageRenderer->addInlineSetting('Workspaces', 'language', $this->‪getLanguageSelection());
112  $this->pageRenderer->addInlineLanguageLabelArray([
113  'title' => $lang->getLL('title'),
114  'path' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.path'),
115  'table' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.table'),
116  'depth' => $lang->sL('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:Depth'),
117  'depth_0' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_0'),
118  'depth_1' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_1'),
119  'depth_2' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_2'),
120  'depth_3' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_3'),
121  'depth_4' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_4'),
122  'depth_infi' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_infi')
123  ]);
124  $this->pageRenderer->addInlineLanguageLabelFile('EXT:workspaces/Resources/Private/Language/locallang.xlf');
125  $states = $this->‪getBackendUser()->uc['moduleData']['Workspaces']['States'];
126  $this->pageRenderer->addInlineSetting('Workspaces', 'States', $states);
127 
128  foreach ($this->‪getAdditionalResourceService()->getLocalizationResources() as $localizationResource) {
129  $this->pageRenderer->addInlineLanguageLabelFile($localizationResource);
130  }
131  ‪$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
132  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Workspaces/Backend');
133  $this->pageRenderer->addInlineSetting('FormEngine', 'moduleUrl', (string)‪$uriBuilder->buildUriFromRoute('record_edit'));
134  $this->pageRenderer->addInlineSetting('RecordHistory', 'moduleUrl', (string)‪$uriBuilder->buildUriFromRoute('record_history'));
135  $this->pageRenderer->addInlineSetting('Workspaces', 'id', (int)GeneralUtility::_GP('id'));
136 
138  }
139 
144  public function ‪indexAction()
145  {
146  $backendUser = $this->‪getBackendUser();
147  $moduleTemplate = $this->view->getModuleTemplate();
148 
149  if (GeneralUtility::_GP('id')) {
150  $pageRecord = ‪BackendUtility::getRecord('pages', GeneralUtility::_GP('id'));
151  if ($pageRecord) {
152  $moduleTemplate->getDocHeaderComponent()->setMetaInformation($pageRecord);
153  $this->view->assign('pageTitle', ‪BackendUtility::getRecordTitle('pages', $pageRecord));
154  }
155  }
156  $wsList = GeneralUtility::makeInstance(WorkspaceService::class)->getAvailableWorkspaces();
157  $activeWorkspace = $backendUser->workspace;
158  $performWorkspaceSwitch = false;
159  // Only admins see multiple tabs, we decided to use it this
160  // way for usability reasons. Regular users might be confused
161  // by switching workspaces with the tabs in a module.
162  if (!$backendUser->isAdmin()) {
163  $wsCur = [$activeWorkspace => true];
164  $wsList = array_intersect_key($wsList, $wsCur);
165  } else {
166  if ((string)GeneralUtility::_GP('workspace') !== '') {
167  $switchWs = (int)GeneralUtility::_GP('workspace');
168  if (array_key_exists($switchWs, $wsList) && $activeWorkspace != $switchWs) {
169  $activeWorkspace = $switchWs;
170  $backendUser->setWorkspace($activeWorkspace);
171  $performWorkspaceSwitch = true;
172  ‪BackendUtility::setUpdateSignal('updatePageTree');
173  } elseif ($switchWs == ‪WorkspaceService::SELECT_ALL_WORKSPACES) {
174  $this->‪redirect('fullIndex');
175  }
176  }
177  }
178  $this->pageRenderer->addInlineSetting('Workspaces', 'isLiveWorkspace', (int)$backendUser->workspace === 0);
179  $this->pageRenderer->addInlineSetting('Workspaces', 'workspaceTabs', $this->‪prepareWorkspaceTabs($wsList, $activeWorkspace));
180  $this->pageRenderer->addInlineSetting('Workspaces', 'activeWorkspaceId', $activeWorkspace);
181  $workspaceIsAccessible = !($backendUser->workspace === 0 && !$backendUser->isAdmin());
182  $this->view->assignMultiple([
183  'showGrid' => $workspaceIsAccessible,
184  'showLegend' => $workspaceIsAccessible,
185  'pageUid' => (int)GeneralUtility::_GP('id'),
186  'performWorkspaceSwitch' => $performWorkspaceSwitch,
187  'workspaceList' => $this->‪prepareWorkspaceTabs($wsList, $activeWorkspace),
188  'activeWorkspaceUid' => $activeWorkspace,
189  'activeWorkspaceTitle' => ‪WorkspaceService::getWorkspaceTitle($activeWorkspace),
190  ]);
191 
192  if ($this->‪canCreatePreviewLink((int)GeneralUtility::_GP('id'), (int)$activeWorkspace)) {
193  $buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();
194  $iconFactory = $moduleTemplate->getIconFactory();
195  $showButton = $buttonBar->makeLinkButton()
196  ->setHref('#')
197  ->setClasses('t3js-preview-link')
198  ->setShowLabelText(true)
199  ->setTitle($this->‪getLanguageService()->‪sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:tooltip.generatePagePreview'))
200  ->setIcon($iconFactory->getIcon('actions-version-workspaces-preview-link', ‪Icon::SIZE_SMALL));
201  $buttonBar->addButton($showButton);
202  }
203  $backendUser->setAndSaveSessionData('tx_workspace_activeWorkspace', $activeWorkspace);
204  }
205 
210  public function ‪fullIndexAction()
211  {
212  $wsService = GeneralUtility::makeInstance(WorkspaceService::class);
213  $wsList = $wsService->getAvailableWorkspaces();
214 
215  $activeWorkspace = $this->‪getBackendUser()->workspace;
216  if (!$this->‪getBackendUser()->isAdmin()) {
217  $wsCur = [$activeWorkspace => true];
218  $wsList = array_intersect_key($wsList, $wsCur);
219  }
220 
221  $this->pageRenderer->addInlineSetting('Workspaces', 'workspaceTabs', $this->‪prepareWorkspaceTabs($wsList, ‪WorkspaceService::SELECT_ALL_WORKSPACES));
222  $this->pageRenderer->addInlineSetting('Workspaces', 'activeWorkspaceId', ‪WorkspaceService::SELECT_ALL_WORKSPACES);
223  $this->view->assignMultiple([
224  'pageUid' => (int)GeneralUtility::_GP('id'),
225  'showGrid' => true,
226  'showLegend' => true,
227  'workspaceList' => $this->‪prepareWorkspaceTabs($wsList, $activeWorkspace),
228  'activeWorkspaceUid' => ‪WorkspaceService::SELECT_ALL_WORKSPACES
229  ]);
231  // set flag for javascript
232  $this->pageRenderer->addInlineSetting('Workspaces', 'allView', '1');
233  }
234 
239  public function ‪singleIndexAction()
240  {
241  $wsService = GeneralUtility::makeInstance(WorkspaceService::class);
242  $wsList = $wsService->getAvailableWorkspaces();
243  $activeWorkspace = $this->‪getBackendUser()->workspace;
244  $wsCur = [$activeWorkspace => true];
245  $wsList = array_intersect_key($wsList, $wsCur);
246  $this->view->assignMultiple([
247  'pageUid' => (int)GeneralUtility::_GP('id'),
248  'showGrid' => true,
249  'workspaceList' => $this->‪prepareWorkspaceTabs($wsList, (int)$activeWorkspace, false),
250  'activeWorkspaceUid' => $activeWorkspace,
251  ]);
252  $this->pageRenderer->addInlineSetting('Workspaces', 'singleView', '1');
253  }
254 
263  protected function ‪prepareWorkspaceTabs(array $workspaceList, int $activeWorkspace, bool $showAllWorkspaceTab = true)
264  {
265  $tabs = [];
266 
267  if ($activeWorkspace !== ‪WorkspaceService::SELECT_ALL_WORKSPACES) {
268  $tabs[] = [
269  'title' => $workspaceList[$activeWorkspace],
270  'itemId' => 'workspace-' . $activeWorkspace,
271  'workspaceId' => $activeWorkspace,
272  'triggerUrl' => $this->‪getModuleUri($activeWorkspace),
273  ];
274  }
275 
276  if ($showAllWorkspaceTab) {
277  $tabs[] = [
278  'title' => 'All workspaces',
279  'itemId' => 'workspace-' . ‪WorkspaceService::SELECT_ALL_WORKSPACES,
282  ];
283  }
284 
285  foreach ($workspaceList as $workspaceId => $workspaceTitle) {
286  if ($workspaceId === $activeWorkspace) {
287  continue;
288  }
289  $tabs[] = [
290  'title' => $workspaceTitle,
291  'itemId' => 'workspace-' . $workspaceId,
292  'workspaceId' => $workspaceId,
293  'triggerUrl' => $this->‪getModuleUri($workspaceId),
294  ];
295  }
296 
297  return $tabs;
298  }
299 
306  protected function ‪getModuleUri(int $workspaceId): string
307  {
308  $parameters = [
309  'id' => ‪$this->pageId,
310  'workspace' => $workspaceId,
311  ];
312  // The "all workspaces" tab is handled in fullIndexAction
313  // which is required as additional GET parameter in the URI then
314  if ($workspaceId === ‪WorkspaceService::SELECT_ALL_WORKSPACES) {
315  $this->uriBuilder->reset()->uriFor('fullIndex');
316  $parameters = array_merge($parameters, $this->uriBuilder->getArguments());
317  }
318  ‪$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
319  return (string)‪$uriBuilder->buildUriFromRoute('web_WorkspacesWorkspaces', $parameters);
320  }
321 
325  protected function ‪assignExtensionSettings()
326  {
327  $extension = [
328  'AdditionalColumn' => [
329  'Definition' => [],
330  'Handler' => [],
331  ],
332  ];
333 
334  $extension['AdditionalColumn']['Definition'] = $this->‪getAdditionalColumnService()->‪getDefinition();
335  $extension['AdditionalColumn']['Handler'] = $this->‪getAdditionalColumnService()->‪getHandler();
336  $this->pageRenderer->addInlineSetting('Workspaces', 'extension', $extension);
337  }
338 
346  protected function ‪canCreatePreviewLink(int $pageUid, int $workspaceUid): bool
347  {
348  if ($pageUid > 0 && $workspaceUid > 0) {
349  $pageRecord = ‪BackendUtility::getRecord('pages', $pageUid);
350  ‪BackendUtility::workspaceOL('pages', $pageRecord, $workspaceUid);
351  if (‪VersionState::cast($pageRecord['t3ver_state'])->equals(‪VersionState::DELETE_PLACEHOLDER)) {
352  return false;
353  }
354  return true;
355  }
356  return false;
357  }
358 
364  protected function ‪getLanguageSelection(): string
365  {
366  $language = 'all';
367  $backendUser = $this->‪getBackendUser();
368  if (isset($backendUser->uc['moduleData']['Workspaces'][$backendUser->workspace]['language'])) {
369  $language = $backendUser->uc['moduleData']['Workspaces'][$backendUser->workspace]['language'];
370  }
371  return $language;
372  }
373 
378  {
379  return $this->objectManager->get(AdditionalColumnService::class);
380  }
381 
386  {
387  return $this->objectManager->get(AdditionalResourceService::class);
388  }
389 
393  protected function ‪getPageRenderer(): ‪PageRenderer
394  {
395  return GeneralUtility::makeInstance(PageRenderer::class);
396  }
397 
401  protected function ‪getLanguageService(): ‪LanguageService
402  {
403  return ‪$GLOBALS['LANG'];
404  }
405 
409  protected function ‪getBackendUser(): ‪BackendUserAuthentication
410  {
411  return ‪$GLOBALS['BE_USER'];
412  }
413 }
‪TYPO3\CMS\Workspaces\Controller\ReviewController\singleIndexAction
‪singleIndexAction()
Definition: ReviewController.php:235
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:29
‪TYPO3\CMS\Workspaces\Controller\ReviewController\getModuleUri
‪string getModuleUri(int $workspaceId)
Definition: ReviewController.php:302
‪TYPO3\CMS\Workspaces\Service\AdditionalResourceService
Definition: AdditionalResourceService.php:26
‪TYPO3\CMS\Workspaces\Service\AdditionalColumnService\getDefinition
‪array getDefinition()
Definition: AdditionalColumnService.php:75
‪TYPO3\CMS\Extbase\Mvc\Controller\AbstractController\$uriBuilder
‪TYPO3 CMS Extbase Mvc Web Routing UriBuilder $uriBuilder
Definition: AbstractController.php:37
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3\CMS\Backend\Utility\BackendUtility\setUpdateSignal
‪static setUpdateSignal($set='', $params='')
Definition: BackendUtility.php:3164
‪TYPO3\CMS\Workspaces\Controller\ReviewController
Definition: ReviewController.php:37
‪TYPO3\CMS\Workspaces\Controller\ReviewController\getLanguageSelection
‪string getLanguageSelection()
Definition: ReviewController.php:360
‪TYPO3\CMS\Workspaces\Controller\ReviewController\assignExtensionSettings
‪assignExtensionSettings()
Definition: ReviewController.php:321
‪TYPO3\CMS\Extbase\Mvc\Cli\Request\getArguments
‪array getArguments()
Definition: Request.php:243
‪TYPO3\CMS\Workspaces\Controller\ReviewController\prepareWorkspaceTabs
‪array prepareWorkspaceTabs(array $workspaceList, int $activeWorkspace, bool $showAllWorkspaceTab=true)
Definition: ReviewController.php:259
‪TYPO3\CMS\Workspaces\Service\AdditionalColumnService\getHandler
‪array getHandler()
Definition: AdditionalColumnService.php:97
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:31
‪TYPO3\CMS\Core\Versioning\VersionState\DELETE_PLACEHOLDER
‪const DELETE_PLACEHOLDER
Definition: VersionState.php:54
‪TYPO3\CMS\Workspaces\Controller\ReviewController\initializeAction
‪initializeAction()
Definition: ReviewController.php:89
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:158
‪TYPO3\CMS\Workspaces\Controller\ReviewController\getPageRenderer
‪PageRenderer getPageRenderer()
Definition: ReviewController.php:389
‪TYPO3\CMS\Extbase\Mvc\Controller\AbstractController\$extensionName
‪string $extensionName
Definition: AbstractController.php:41
‪TYPO3\CMS\Workspaces\Service\AdditionalColumnService
Definition: AdditionalColumnService.php:27
‪TYPO3\CMS\Workspaces\Controller\ReviewController\getAdditionalColumnService
‪AdditionalColumnService getAdditionalColumnService()
Definition: ReviewController.php:373
‪TYPO3\CMS\Workspaces\Controller\ReviewController\$pageId
‪int $pageId
Definition: ReviewController.php:52
‪TYPO3\CMS\Workspaces\Controller\ReviewController\$defaultViewObjectName
‪string $defaultViewObjectName
Definition: ReviewController.php:40
‪TYPO3\CMS\Core\Type\Enumeration\cast
‪static static cast($value)
Definition: Enumeration.php:182
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:35
‪TYPO3\CMS\Workspaces\Service\WorkspaceService\SELECT_ALL_WORKSPACES
‪const SELECT_ALL_WORKSPACES
Definition: WorkspaceService.php:44
‪TYPO3\CMS\Workspaces\Controller\ReviewController\$pageRenderer
‪PageRenderer $pageRenderer
Definition: ReviewController.php:48
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:35
‪TYPO3\CMS\Workspaces\Controller\ReviewController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: ReviewController.php:405
‪TYPO3\CMS\Extbase\Mvc\Controller\AbstractController\redirect
‪redirect($actionName, $controllerName=null, $extensionName=null, array $arguments=null, $pageUid=null, $delay=0, $statusCode=303)
Definition: AbstractController.php:284
‪TYPO3\CMS\Workspaces\Controller\ReviewController\getLanguageService
‪LanguageService getLanguageService()
Definition: ReviewController.php:397
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordTitle
‪static string getRecordTitle($table, $row, $prep=false, $forceResult=true)
Definition: BackendUtility.php:1811
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Workspaces\Controller\ReviewController\canCreatePreviewLink
‪bool canCreatePreviewLink(int $pageUid, int $workspaceUid)
Definition: ReviewController.php:342
‪TYPO3\CMS\Core\Authentication\AbstractUserAuthentication\setAndSaveSessionData
‪setAndSaveSessionData($key, $data)
Definition: AbstractUserAuthentication.php:1285
‪TYPO3\CMS\Extbase\Mvc\View\ViewInterface
Definition: ViewInterface.php:21
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Workspaces\Service\WorkspaceService
Definition: WorkspaceService.php:34
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:130
‪TYPO3\CMS\Core\Versioning\VersionState
Definition: VersionState.php:23
‪TYPO3\CMS\Workspaces\Controller\ReviewController\fullIndexAction
‪fullIndexAction()
Definition: ReviewController.php:206
‪TYPO3\CMS\Backend\View\BackendTemplateView
Definition: BackendTemplateView.php:27
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Utility\BackendUtility\workspaceOL
‪static workspaceOL($table, &$row, $wsid=-99, $unsetMovePointers=false)
Definition: BackendUtility.php:4048
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\$request
‪TYPO3 CMS Extbase Mvc Request $request
Definition: ActionController.php:87
‪TYPO3\CMS\Workspaces\Controller\ReviewController\indexAction
‪indexAction()
Definition: ReviewController.php:140
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController
Definition: ActionController.php:31
‪TYPO3\CMS\Workspaces\Controller\ReviewController\$view
‪BackendTemplateView $view
Definition: ReviewController.php:44
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Workspaces\Controller\ReviewController\getAdditionalResourceService
‪AdditionalResourceService getAdditionalResourceService()
Definition: ReviewController.php:381
‪TYPO3\CMS\Workspaces\Controller
Definition: AjaxController.php:2
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪$icons
‪$icons
Definition: ext_localconf.php:77
‪TYPO3\CMS\Workspaces\Controller\ReviewController\registerButtons
‪registerButtons()
Definition: ReviewController.php:69
‪TYPO3\CMS\Workspaces\Service\WorkspaceService\getWorkspaceTitle
‪static string getWorkspaceTitle($wsId)
Definition: WorkspaceService.php:107
‪TYPO3\CMS\Workspaces\Controller\ReviewController\initializeView
‪initializeView(ViewInterface $view)
Definition: ReviewController.php:59