‪TYPO3CMS  10.4
ReviewController.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
33 
38 {
42  protected ‪$defaultViewObjectName = BackendTemplateView::class;
43 
47  protected ‪$view;
48 
52  protected ‪$pageRenderer;
53 
57  protected ‪$pageId;
58 
64  protected function ‪initializeView(‪ViewInterface ‪$view)
65  {
66  parent::initializeView(‪$view);
67  $this->‪registerButtons();
68  $this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
69  }
70 
74  protected function ‪registerButtons()
75  {
76  $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
77  $currentRequest = ‪$this->request;
78  $moduleName = $currentRequest->‪getPluginName();
79  $getVars = $this->request->getArguments();
80  $extensionName = $currentRequest->getControllerExtensionName();
81  if (count($getVars) === 0) {
82  $modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
83  $getVars = ['id', 'route', $modulePrefix];
84  }
85  $shortcutButton = $buttonBar->makeShortcutButton()
86  ->setModuleName($moduleName)
87  ->setGetVariables($getVars);
88  $buttonBar->addButton($shortcutButton);
89  }
90 
94  protected function ‪initializeAction()
95  {
96  $this->pageRenderer = $this->‪getPageRenderer();
97  // @todo Evaluate how the (int) typecast can be used with Extbase validators/filters
98  $this->pageId = (int)GeneralUtility::_GP('id');
99  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
100  $lang = $this->‪getLanguageService();
101  ‪$icons = [
102  'language' => $iconFactory->getIcon('flags-multiple', ‪Icon::SIZE_SMALL)->render(),
103  'integrity' => $iconFactory->getIcon('status-dialog-information', ‪Icon::SIZE_SMALL)->render(),
104  'success' => $iconFactory->getIcon('status-dialog-ok', ‪Icon::SIZE_SMALL)->render(),
105  'info' => $iconFactory->getIcon('status-dialog-information', ‪Icon::SIZE_SMALL)->render(),
106  'warning' => $iconFactory->getIcon('status-dialog-warning', ‪Icon::SIZE_SMALL)->render(),
107  'error' => $iconFactory->getIcon('status-dialog-error', ‪Icon::SIZE_SMALL)->render()
108  ];
109  $this->pageRenderer->addInlineSetting('Workspaces', 'icons', ‪$icons);
110  $this->pageRenderer->addInlineSetting('Workspaces', 'id', $this->pageId);
111  $this->pageRenderer->addInlineSetting('Workspaces', 'depth', $this->pageId === 0 ? 999 : 1);
112  $this->pageRenderer->addInlineSetting('Workspaces', 'language', $this->‪getLanguageSelection());
113  $this->pageRenderer->addInlineLanguageLabelArray([
114  'title' => $lang->getLL('title'),
115  'path' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.path'),
116  'table' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.table'),
117  'depth' => $lang->sL('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:Depth'),
118  'depth_0' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_0'),
119  'depth_1' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_1'),
120  'depth_2' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_2'),
121  'depth_3' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_3'),
122  'depth_4' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_4'),
123  'depth_infi' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_infi')
124  ]);
125  $this->pageRenderer->addInlineLanguageLabelFile('EXT:workspaces/Resources/Private/Language/locallang.xlf');
126  $states = $this->‪getBackendUser()->uc['moduleData']['Workspaces']['States'];
127  $this->pageRenderer->addInlineSetting('Workspaces', 'States', $states);
128 
129  foreach ($this->‪getAdditionalResourceService()->getLocalizationResources() as $localizationResource) {
130  $this->pageRenderer->addInlineLanguageLabelFile($localizationResource);
131  }
132  ‪$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
133  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Workspaces/Backend');
134  $this->pageRenderer->addInlineSetting('FormEngine', 'moduleUrl', (string)‪$uriBuilder->buildUriFromRoute('record_edit'));
135  $this->pageRenderer->addInlineSetting('RecordHistory', 'moduleUrl', (string)‪$uriBuilder->buildUriFromRoute('record_history'));
136  $this->pageRenderer->addInlineSetting('Workspaces', 'id', (int)GeneralUtility::_GP('id'));
137 
139  }
140 
145  public function ‪indexAction()
146  {
147  $backendUser = $this->‪getBackendUser();
148  $moduleTemplate = $this->view->getModuleTemplate();
149 
150  if (GeneralUtility::_GP('id')) {
151  $pageRecord = ‪BackendUtility::getRecord('pages', GeneralUtility::_GP('id'));
152  if ($pageRecord) {
153  $moduleTemplate->getDocHeaderComponent()->setMetaInformation($pageRecord);
154  $this->view->assign('pageTitle', ‪BackendUtility::getRecordTitle('pages', $pageRecord));
155  }
156  }
157  $wsList = GeneralUtility::makeInstance(WorkspaceService::class)->getAvailableWorkspaces();
158  $customWorkspaceExists = $this->‪customWorkspaceExists($wsList);
159  $activeWorkspace = $backendUser->workspace;
160  $performWorkspaceSwitch = false;
161  if ((string)GeneralUtility::_GP('workspace') !== '') {
162  $switchWs = (int)GeneralUtility::_GP('workspace');
163  if (array_key_exists($switchWs, $wsList) && $activeWorkspace != $switchWs) {
164  $activeWorkspace = $switchWs;
165  $backendUser->setWorkspace($activeWorkspace);
166  $performWorkspaceSwitch = true;
167  ‪BackendUtility::setUpdateSignal('updatePageTree');
168  }
169  }
170  $this->pageRenderer->addInlineSetting('Workspaces', 'isLiveWorkspace', (int)$backendUser->workspace === 0);
171  $this->pageRenderer->addInlineSetting('Workspaces', 'workspaceTabs', $this->‪prepareWorkspaceTabs($wsList, $activeWorkspace));
172  $this->pageRenderer->addInlineSetting('Workspaces', 'activeWorkspaceId', $activeWorkspace);
173  $workspaceIsAccessible = $backendUser->workspace !== ‪WorkspaceService::LIVE_WORKSPACE_ID;
174  $this->view->assignMultiple([
175  'isAdmin' => $backendUser->isAdmin(),
176  'customWorkspaceExists' => $customWorkspaceExists,
177  'showGrid' => $workspaceIsAccessible,
178  'showLegend' => $workspaceIsAccessible,
179  'pageUid' => (int)GeneralUtility::_GP('id'),
180  'performWorkspaceSwitch' => $performWorkspaceSwitch,
181  'workspaceList' => $this->prepareWorkspaceTabs($wsList, $activeWorkspace),
182  'activeWorkspaceUid' => $activeWorkspace,
183  'activeWorkspaceTitle' => ‪WorkspaceService::getWorkspaceTitle($activeWorkspace),
184  ]);
185 
186  if ($this->‪canCreatePreviewLink((int)GeneralUtility::_GP('id'), (int)$activeWorkspace)) {
187  $buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();
188  $iconFactory = $moduleTemplate->getIconFactory();
189  $showButton = $buttonBar->makeLinkButton()
190  ->setHref('#')
191  ->setClasses('t3js-preview-link')
192  ->setShowLabelText(true)
193  ->setTitle($this->‪getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:tooltip.generatePagePreview'))
194  ->setIcon($iconFactory->getIcon('actions-version-workspaces-preview-link', ‪Icon::SIZE_SMALL));
195  $buttonBar->addButton($showButton);
196  }
197  }
198 
206  protected function ‪prepareWorkspaceTabs(array $workspaceList, int $activeWorkspace)
207  {
208  $tabs = [];
209 
210  if ($activeWorkspace !== ‪WorkspaceService::LIVE_WORKSPACE_ID) {
211  $tabs[] = [
212  'title' => $workspaceList[$activeWorkspace],
213  'itemId' => 'workspace-' . $activeWorkspace,
214  'workspaceId' => $activeWorkspace,
215  'triggerUrl' => $this->‪getModuleUri($activeWorkspace),
216  ];
217  }
218 
219  foreach ($workspaceList as $workspaceId => $workspaceTitle) {
220  if ($workspaceId === $activeWorkspace
221  || $workspaceId === ‪WorkspaceService::LIVE_WORKSPACE_ID
222  ) {
223  continue;
224  }
225  $tabs[] = [
226  'title' => $workspaceTitle,
227  'itemId' => 'workspace-' . $workspaceId,
228  'workspaceId' => $workspaceId,
229  'triggerUrl' => $this->‪getModuleUri($workspaceId),
230  ];
231  }
232 
233  return $tabs;
234  }
235 
242  protected function ‪getModuleUri(int $workspaceId): string
243  {
244  $parameters = [
245  'id' => ‪$this->pageId,
246  'workspace' => $workspaceId,
247  ];
248  ‪$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
249  return (string)‪$uriBuilder->buildUriFromRoute('web_WorkspacesWorkspaces', $parameters);
250  }
251 
255  protected function ‪assignExtensionSettings()
256  {
257  $extension = [
258  'AdditionalColumn' => [
259  'Definition' => [],
260  'Handler' => [],
261  ],
262  ];
263 
264  $extension['AdditionalColumn']['Definition'] = $this->‪getAdditionalColumnService()->‪getDefinition();
265  $extension['AdditionalColumn']['Handler'] = $this->‪getAdditionalColumnService()->‪getHandler();
266  $this->pageRenderer->addInlineSetting('Workspaces', 'extension', $extension);
267  }
268 
276  protected function ‪canCreatePreviewLink(int $pageUid, int $workspaceUid): bool
277  {
278  if ($pageUid > 0 && $workspaceUid > 0) {
279  $pageRecord = ‪BackendUtility::getRecord('pages', $pageUid);
280  ‪BackendUtility::workspaceOL('pages', $pageRecord, $workspaceUid);
281  if (‪VersionState::cast($pageRecord['t3ver_state'])->equals(‪VersionState::DELETE_PLACEHOLDER)) {
282  return false;
283  }
284  return true;
285  }
286  return false;
287  }
288 
294  protected function ‪getLanguageSelection(): string
295  {
296  $language = 'all';
297  $backendUser = $this->‪getBackendUser();
298  if (isset($backendUser->uc['moduleData']['Workspaces'][$backendUser->workspace]['language'])) {
299  $language = $backendUser->uc['moduleData']['Workspaces'][$backendUser->workspace]['language'];
300  }
301  return $language;
302  }
303 
310  protected function ‪customWorkspaceExists(array $workspaceList): bool
311  {
312  foreach (array_keys($workspaceList) as $workspaceId) {
313  if ($workspaceId > 0) {
314  return true;
315  }
316  }
317  return false;
318  }
319 
324  {
325  return $this->objectManager->get(AdditionalColumnService::class);
326  }
327 
332  {
333  return $this->objectManager->get(AdditionalResourceService::class);
334  }
335 
339  protected function ‪getPageRenderer(): ‪PageRenderer
340  {
341  return GeneralUtility::makeInstance(PageRenderer::class);
342  }
343 
347  protected function ‪getLanguageService(): ‪LanguageService
348  {
349  return ‪$GLOBALS['LANG'];
350  }
351 
355  protected function ‪getBackendUser(): ‪BackendUserAuthentication
356  {
357  return ‪$GLOBALS['BE_USER'];
358  }
359 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Workspaces\Controller\ReviewController\getModuleUri
‪string getModuleUri(int $workspaceId)
Definition: ReviewController.php:238
‪TYPO3\CMS\Workspaces\Service\AdditionalResourceService
Definition: AdditionalResourceService.php:26
‪TYPO3\CMS\Workspaces\Service\AdditionalColumnService\getDefinition
‪array getDefinition()
Definition: AdditionalColumnService.php:67
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Workspaces\Controller\ReviewController\customWorkspaceExists
‪bool customWorkspaceExists(array $workspaceList)
Definition: ReviewController.php:306
‪TYPO3\CMS\Backend\Utility\BackendUtility\setUpdateSignal
‪static setUpdateSignal($set='', $params='')
Definition: BackendUtility.php:2798
‪TYPO3\CMS\Workspaces\Controller\ReviewController
Definition: ReviewController.php:38
‪TYPO3\CMS\Workspaces\Controller\ReviewController\getLanguageSelection
‪string getLanguageSelection()
Definition: ReviewController.php:290
‪TYPO3\CMS\Workspaces\Controller\ReviewController\assignExtensionSettings
‪assignExtensionSettings()
Definition: ReviewController.php:251
‪TYPO3\CMS\Extbase\Mvc\Request\getPluginName
‪string getPluginName()
Definition: Request.php:181
‪TYPO3\CMS\Workspaces\Service\AdditionalColumnService\getHandler
‪array getHandler()
Definition: AdditionalColumnService.php:89
‪TYPO3\CMS\Workspaces\Service\WorkspaceService\LIVE_WORKSPACE_ID
‪const LIVE_WORKSPACE_ID
Definition: WorkspaceService.php:46
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:33
‪TYPO3\CMS\Core\Versioning\VersionState\DELETE_PLACEHOLDER
‪const DELETE_PLACEHOLDER
Definition: VersionState.php:55
‪TYPO3\CMS\Workspaces\Controller\ReviewController\initializeAction
‪initializeAction()
Definition: ReviewController.php:90
‪TYPO3\CMS\Workspaces\Controller\ReviewController\getPageRenderer
‪PageRenderer getPageRenderer()
Definition: ReviewController.php:335
‪TYPO3\CMS\Workspaces\Service\AdditionalColumnService
Definition: AdditionalColumnService.php:27
‪TYPO3\CMS\Workspaces\Controller\ReviewController\getAdditionalColumnService
‪AdditionalColumnService getAdditionalColumnService()
Definition: ReviewController.php:319
‪TYPO3\CMS\Workspaces\Controller\ReviewController\$pageId
‪int $pageId
Definition: ReviewController.php:53
‪TYPO3\CMS\Workspaces\Controller\ReviewController\$defaultViewObjectName
‪string $defaultViewObjectName
Definition: ReviewController.php:41
‪TYPO3\CMS\Core\Type\Enumeration\cast
‪static static cast($value)
Definition: Enumeration.php:186
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:42
‪TYPO3\CMS\Workspaces\Controller\ReviewController\$pageRenderer
‪PageRenderer $pageRenderer
Definition: ReviewController.php:49
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\$uriBuilder
‪TYPO3 CMS Extbase Mvc Web Routing UriBuilder $uriBuilder
Definition: ActionController.php:127
‪TYPO3\CMS\Workspaces\Controller\ReviewController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: ReviewController.php:351
‪TYPO3\CMS\Workspaces\Controller\ReviewController\getLanguageService
‪LanguageService getLanguageService()
Definition: ReviewController.php:343
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordTitle
‪static string getRecordTitle($table, $row, $prep=false, $forceResult=true)
Definition: BackendUtility.php:1541
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Workspaces\Controller\ReviewController\canCreatePreviewLink
‪bool canCreatePreviewLink(int $pageUid, int $workspaceUid)
Definition: ReviewController.php:272
‪TYPO3\CMS\Extbase\Mvc\View\ViewInterface
Definition: ViewInterface.php:24
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Workspaces\Service\WorkspaceService
Definition: WorkspaceService.php:36
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:95
‪TYPO3\CMS\Core\Versioning\VersionState
Definition: VersionState.php:24
‪TYPO3\CMS\Backend\View\BackendTemplateView
Definition: BackendTemplateView.php:28
‪TYPO3\CMS\Workspaces\Controller\ReviewController\prepareWorkspaceTabs
‪array prepareWorkspaceTabs(array $workspaceList, int $activeWorkspace)
Definition: ReviewController.php:202
‪$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:3586
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\$request
‪TYPO3 CMS Extbase Mvc Request $request
Definition: ActionController.php:109
‪TYPO3\CMS\Workspaces\Controller\ReviewController\indexAction
‪indexAction()
Definition: ReviewController.php:141
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController
Definition: ActionController.php:55
‪TYPO3\CMS\Workspaces\Controller\ReviewController\$view
‪BackendTemplateView $view
Definition: ReviewController.php:45
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Workspaces\Controller\ReviewController\getAdditionalResourceService
‪AdditionalResourceService getAdditionalResourceService()
Definition: ReviewController.php:327
‪TYPO3\CMS\Workspaces\Controller
Definition: AjaxController.php:16
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪$icons
‪$icons
Definition: ext_localconf.php:54
‪TYPO3\CMS\Workspaces\Controller\ReviewController\registerButtons
‪registerButtons()
Definition: ReviewController.php:70
‪TYPO3\CMS\Workspaces\Service\WorkspaceService\getWorkspaceTitle
‪static string getWorkspaceTitle($wsId)
Definition: WorkspaceService.php:120
‪TYPO3\CMS\Workspaces\Controller\ReviewController\initializeView
‪initializeView(ViewInterface $view)
Definition: ReviewController.php:60