/** * Sets the TYPO3 Backend context to a certain workspace, * called by the Backend toolbar menu * * @param ServerRequestInterface $request * @param ResponseInterface $response * @return ResponseInterface */ public function switchWorkspaceAction(ServerRequestInterface $request, ResponseInterface $response) { $parsedBody = $request->getParsedBody(); $queryParams = $request->getQueryParams(); $workspaceId = (int) (isset($parsedBody['workspaceId']) ? $parsedBody['workspaceId'] : $queryParams['workspaceId']); $pageId = (int) (isset($parsedBody['pageId']) ? $parsedBody['pageId'] : $queryParams['pageId']); $finalPageUid = 0; $originalPageId = $pageId; $this->getBackendUser()->setWorkspace($workspaceId); while ($pageId) { $page = BackendUtility::getRecordWSOL('pages', $pageId, '*', ' AND pages.t3ver_wsid IN (0, ' . $workspaceId . ')'); if ($page) { if ($this->getBackendUser()->doesUserHaveAccess($page, 1)) { break; } } else { $page = BackendUtility::getRecord('pages', $pageId); } $pageId = $page['pid']; } if (isset($page['uid'])) { $finalPageUid = (int) $page['uid']; } $ajaxResponse = ['title' => \TYPO3\CMS\Workspaces\Service\WorkspaceService::getWorkspaceTitle($workspaceId), 'workspaceId' => $workspaceId, 'pageId' => $finalPageUid && $originalPageId == $finalPageUid ? null : $finalPageUid]; $response->getBody()->write(json_encode($ajaxResponse)); return $response; }
/** * Sets the TYPO3 Backend context to a certain workspace, * called by the Backend toolbar menu * * @param array $parameters * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxRequestHandler * @return void */ public function setWorkspace($parameters, \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxRequestHandler) { $workspaceId = (int) GeneralUtility::_GP('workspaceId'); $pageId = (int) GeneralUtility::_GP('pageId'); $finalPageUid = 0; $originalPageId = $pageId; $this->getBackendUser()->setWorkspace($workspaceId); while ($pageId) { $page = BackendUtility::getRecordWSOL('pages', $pageId, '*', ' AND pages.t3ver_wsid IN (0, ' . $workspaceId . ')'); if ($page) { if ($this->getBackendUser()->doesUserHaveAccess($page, 1)) { break; } } else { $page = BackendUtility::getRecord('pages', $pageId); } $pageId = $page['pid']; } if (isset($page['uid'])) { $finalPageUid = (int) $page['uid']; } $response = array('title' => \TYPO3\CMS\Workspaces\Service\WorkspaceService::getWorkspaceTitle($workspaceId), 'workspaceId' => $workspaceId, 'pageId' => $finalPageUid && $originalPageId == $finalPageUid ? NULL : $finalPageUid); $ajaxRequestHandler->setContent($response); $ajaxRequestHandler->setContentFormat('json'); }
/** * Constructor */ public function __construct() { /** @var \TYPO3\CMS\Workspaces\Service\WorkspaceService $wsService */ $wsService = GeneralUtility::makeInstance(WorkspaceService::class); $this->availableWorkspaces = $wsService->getAvailableWorkspaces(); $pageRenderer = $this->getPageRenderer(); $pageRenderer->addInlineLanguageLabel('Workspaces.workspaceTitle', WorkspaceService::getWorkspaceTitle($this->getBackendUser()->workspace)); $pageRenderer->loadRequireJsModule('TYPO3/CMS/Workspaces/Toolbar/WorkspacesMenu'); }
/** * constructor * * @param \TYPO3\CMS\Backend\Controller\BackendController TYPO3 backend object reference */ public function __construct(\TYPO3\CMS\Backend\Controller\BackendController &$backendReference = NULL) { $this->backendReference = $backendReference; $this->changeWorkspace = GeneralUtility::_GP('changeWorkspace'); $this->changeWorkspacePreview = GeneralUtility::_GP('changeWorkspacePreview'); $pageRenderer = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Page\\PageRenderer'); $this->backendReference->addJavaScript('TYPO3.Workspaces = { workspaceTitle : \'' . addslashes(\TYPO3\CMS\Workspaces\Service\WorkspaceService::getWorkspaceTitle($GLOBALS['BE_USER']->workspace)) . '\'}; '); }
/** * @param $parameter * @return array */ public function setWorkspace($parameter) { $workspaceId = (int) $parameter->workSpaceId; $pageId = (int) $parameter->pageId; $GLOBALS['BE_USER']->setWorkspace($workspaceId); while ($pageId) { $page = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordWSOL('pages', $pageId, '*', ' AND pages.t3ver_wsid IN (0, ' . $workspaceId . ')'); if ($page) { if ($GLOBALS['BE_USER']->doesUserHaveAccess($page, 1)) { break; } } else { $page = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('pages', $pageId); } $pageId = $page['pid']; } return array('title' => \TYPO3\CMS\Workspaces\Service\WorkspaceService::getWorkspaceTitle($workspaceId), 'id' => $workspaceId, 'page' => isset($page['uid']) && $parameter->pageId == $page['uid'] ? NULL : (int) $page['uid']); }
/** * Renders the review module user dependent with all workspaces. * The module will show all records of one workspace. * * @return void */ public function indexAction() { $wsService = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\WorkspaceService::class); $this->view->assign('showGrid', !($GLOBALS['BE_USER']->workspace === 0 && !$GLOBALS['BE_USER']->isAdmin())); $this->view->assign('showAllWorkspaceTab', TRUE); $this->view->assign('pageUid', GeneralUtility::_GP('id')); if (GeneralUtility::_GP('id')) { $pageRecord = BackendUtility::getRecord('pages', GeneralUtility::_GP('id')); $this->view->assign('pageTitle', BackendUtility::getRecordTitle('pages', $pageRecord)); } $this->view->assign('showLegend', !($GLOBALS['BE_USER']->workspace === 0 && !$GLOBALS['BE_USER']->isAdmin())); $wsList = $wsService->getAvailableWorkspaces(); $activeWorkspace = $GLOBALS['BE_USER']->workspace; $performWorkspaceSwitch = FALSE; // Only admins see multiple tabs, we decided to use it this // way for usability reasons. Regular users might be confused // by switching workspaces with the tabs in a module. if (!$GLOBALS['BE_USER']->isAdmin()) { $wsCur = array($activeWorkspace => TRUE); $wsList = array_intersect_key($wsList, $wsCur); } else { if ((string) GeneralUtility::_GP('workspace') !== '') { $switchWs = (int) GeneralUtility::_GP('workspace'); if (in_array($switchWs, array_keys($wsList)) && $activeWorkspace != $switchWs) { $activeWorkspace = $switchWs; $GLOBALS['BE_USER']->setWorkspace($activeWorkspace); $performWorkspaceSwitch = TRUE; BackendUtility::setUpdateSignal('updatePageTree'); } elseif ($switchWs == WorkspaceService::SELECT_ALL_WORKSPACES) { $this->redirect('fullIndex'); } } } $this->pageRenderer->addInlineSetting('Workspaces', 'isLiveWorkspace', (int) $GLOBALS['BE_USER']->workspace === 0 ? TRUE : FALSE); $this->pageRenderer->addInlineSetting('Workspaces', 'workspaceTabs', $this->prepareWorkspaceTabs($wsList, $activeWorkspace)); $this->pageRenderer->addInlineSetting('Workspaces', 'activeWorkspaceId', $activeWorkspace); $this->pageRenderer->addInlineSetting('FormEngine', 'moduleUrl', BackendUtility::getModuleUrl('record_edit')); $this->view->assign('performWorkspaceSwitch', $performWorkspaceSwitch); $this->view->assign('workspaceList', $wsList); $this->view->assign('activeWorkspaceUid', $activeWorkspace); $this->view->assign('activeWorkspaceTitle', WorkspaceService::getWorkspaceTitle($activeWorkspace)); $this->view->assign('showPreviewLink', $wsService->canCreatePreviewLink(GeneralUtility::_GP('id'), $activeWorkspace)); $GLOBALS['BE_USER']->setAndSaveSessionData('tx_workspace_activeWorkspace', $activeWorkspace); }
/** * Renders the review module user dependent with all workspaces. * The module will show all records of one workspace. * * @return void */ public function indexAction() { $backendUser = $this->getBackendUser(); $moduleTemplate = $this->view->getModuleTemplate(); /** @var WorkspaceService $wsService */ $wsService = GeneralUtility::makeInstance(WorkspaceService::class); if (GeneralUtility::_GP('id')) { $pageRecord = BackendUtility::getRecord('pages', GeneralUtility::_GP('id')); if ($pageRecord) { $moduleTemplate->getDocHeaderComponent()->setMetaInformation($pageRecord); $this->view->assign('pageTitle', BackendUtility::getRecordTitle('pages', $pageRecord)); } } $wsList = $wsService->getAvailableWorkspaces(); $activeWorkspace = $backendUser->workspace; $performWorkspaceSwitch = false; // Only admins see multiple tabs, we decided to use it this // way for usability reasons. Regular users might be confused // by switching workspaces with the tabs in a module. if (!$backendUser->isAdmin()) { $wsCur = [$activeWorkspace => true]; $wsList = array_intersect_key($wsList, $wsCur); } else { if ((string) GeneralUtility::_GP('workspace') !== '') { $switchWs = (int) GeneralUtility::_GP('workspace'); if (in_array($switchWs, array_keys($wsList)) && $activeWorkspace != $switchWs) { $activeWorkspace = $switchWs; $backendUser->setWorkspace($activeWorkspace); $performWorkspaceSwitch = true; BackendUtility::setUpdateSignal('updatePageTree'); } elseif ($switchWs == WorkspaceService::SELECT_ALL_WORKSPACES) { $this->redirect('fullIndex'); } } } $this->pageRenderer->addInlineSetting('Workspaces', 'isLiveWorkspace', (int) $backendUser->workspace === 0); $this->pageRenderer->addInlineSetting('Workspaces', 'workspaceTabs', $this->prepareWorkspaceTabs($wsList, $activeWorkspace)); $this->pageRenderer->addInlineSetting('Workspaces', 'activeWorkspaceId', $activeWorkspace); $this->pageRenderer->addInlineSetting('FormEngine', 'moduleUrl', BackendUtility::getModuleUrl('record_edit')); $workspaceIsAccessible = !($backendUser->workspace === 0 && !$backendUser->isAdmin()); $this->view->assignMultiple(['showGrid' => $workspaceIsAccessible, 'showLegend' => $workspaceIsAccessible, 'pageUid' => (int) GeneralUtility::_GP('id'), 'performWorkspaceSwitch' => $performWorkspaceSwitch, 'workspaceList' => $this->prepareWorkspaceTabs($wsList, $activeWorkspace), 'activeWorkspaceUid' => $activeWorkspace, 'activeWorkspaceTitle' => WorkspaceService::getWorkspaceTitle($activeWorkspace), 'showPreviewLink' => $wsService->canCreatePreviewLink(GeneralUtility::_GP('id'), $activeWorkspace)]); if ($wsService->canCreatePreviewLink(GeneralUtility::_GP('id'), $activeWorkspace)) { $buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar(); $iconFactory = $moduleTemplate->getIconFactory(); $showButton = $buttonBar->makeLinkButton()->setHref('#')->setClasses('t3js-preview-link')->setTitle($this->getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:tooltip.generatePagePreview'))->setIcon($iconFactory->getIcon('module-workspaces-action-preview-link', Icon::SIZE_SMALL)); $buttonBar->addButton($showButton); } $backendUser->setAndSaveSessionData('tx_workspace_activeWorkspace', $activeWorkspace); }
/** * Generates grid list array from given versions. * * @param array $versions All available version records * @param string $filterTxt Text to be used to filter record result * @return void */ protected function generateDataArray(array $versions, $filterTxt) { $workspaceAccess = $GLOBALS['BE_USER']->checkWorkspace($GLOBALS['BE_USER']->workspace); $swapStage = $workspaceAccess['publish_access'] & 1 ? \TYPO3\CMS\Workspaces\Service\StagesService::STAGE_PUBLISH_ID : 0; $swapAccess = $GLOBALS['BE_USER']->workspacePublishAccess($GLOBALS['BE_USER']->workspace) && $GLOBALS['BE_USER']->workspaceSwapAccess(); $this->initializeWorkspacesCachingFramework(); // check for dataArray in cache if ($this->getDataArrayFromCache($versions, $filterTxt) === FALSE) { /** @var $stagesObj \TYPO3\CMS\Workspaces\Service\StagesService */ $stagesObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\StagesService'); $defaultGridColumns = array(self::GridColumn_Collection => 0, self::GridColumn_CollectionLevel => 0, self::GridColumn_CollectionParent => '', self::GridColumn_CollectionCurrent => '', self::GridColumn_CollectionChildren => 0); foreach ($versions as $table => $records) { $hiddenField = $this->getTcaEnableColumnsFieldName($table, 'disabled'); $isRecordTypeAllowedToModify = $GLOBALS['BE_USER']->check('tables_modify', $table); foreach ($records as $record) { $origRecord = BackendUtility::getRecord($table, $record['t3ver_oid']); $versionRecord = BackendUtility::getRecord($table, $record['uid']); $combinedRecord = \TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord::createFromArrays($table, $origRecord, $versionRecord); $this->getIntegrityService()->checkElement($combinedRecord); if ($hiddenField !== NULL) { $recordState = $this->workspaceState($versionRecord['t3ver_state'], $origRecord[$hiddenField], $versionRecord[$hiddenField]); } else { $recordState = $this->workspaceState($versionRecord['t3ver_state']); } $isDeletedPage = $table == 'pages' && $recordState == 'deleted'; $viewUrl = \TYPO3\CMS\Workspaces\Service\WorkspaceService::viewSingleRecord($table, $record['uid'], $origRecord, $versionRecord); $versionArray = array(); $versionArray['table'] = $table; $versionArray['id'] = $table . ':' . $record['uid']; $versionArray['uid'] = $record['uid']; $versionArray['workspace'] = $versionRecord['t3ver_id']; $versionArray = array_merge($versionArray, $defaultGridColumns); $versionArray['label_Workspace'] = htmlspecialchars(BackendUtility::getRecordTitle($table, $versionRecord)); $versionArray['label_Live'] = htmlspecialchars(BackendUtility::getRecordTitle($table, $origRecord)); $versionArray['label_Stage'] = htmlspecialchars($stagesObj->getStageTitle($versionRecord['t3ver_stage'])); $tempStage = $stagesObj->getNextStage($versionRecord['t3ver_stage']); $versionArray['label_nextStage'] = htmlspecialchars($stagesObj->getStageTitle($tempStage['uid'])); $tempStage = $stagesObj->getPrevStage($versionRecord['t3ver_stage']); $versionArray['label_prevStage'] = htmlspecialchars($stagesObj->getStageTitle($tempStage['uid'])); $versionArray['path_Live'] = htmlspecialchars(BackendUtility::getRecordPath($record['livepid'], '', 999)); $versionArray['path_Workspace'] = htmlspecialchars(BackendUtility::getRecordPath($record['wspid'], '', 999)); $versionArray['workspace_Title'] = htmlspecialchars(\TYPO3\CMS\Workspaces\Service\WorkspaceService::getWorkspaceTitle($versionRecord['t3ver_wsid'])); $versionArray['workspace_Tstamp'] = $versionRecord['tstamp']; $versionArray['workspace_Formated_Tstamp'] = BackendUtility::datetime($versionRecord['tstamp']); $versionArray['t3ver_wsid'] = $versionRecord['t3ver_wsid']; $versionArray['t3ver_oid'] = $record['t3ver_oid']; $versionArray['livepid'] = $record['livepid']; $versionArray['stage'] = $versionRecord['t3ver_stage']; $versionArray['icon_Live'] = \TYPO3\CMS\Backend\Utility\IconUtility::mapRecordTypeToSpriteIconClass($table, $origRecord); $versionArray['icon_Workspace'] = \TYPO3\CMS\Backend\Utility\IconUtility::mapRecordTypeToSpriteIconClass($table, $versionRecord); $languageValue = $this->getLanguageValue($table, $versionRecord); $versionArray['languageValue'] = $languageValue; $versionArray['language'] = array('cls' => \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconClasses($this->getSystemLanguageValue($languageValue, 'flagIcon')), 'title' => htmlspecialchars($this->getSystemLanguageValue($languageValue, 'title'))); $versionArray['allowedAction_nextStage'] = $isRecordTypeAllowedToModify && $stagesObj->isNextStageAllowedForUser($versionRecord['t3ver_stage']); $versionArray['allowedAction_prevStage'] = $isRecordTypeAllowedToModify && $stagesObj->isPrevStageAllowedForUser($versionRecord['t3ver_stage']); if ($swapAccess && $swapStage != 0 && $versionRecord['t3ver_stage'] == $swapStage) { $versionArray['allowedAction_swap'] = $isRecordTypeAllowedToModify && $stagesObj->isNextStageAllowedForUser($swapStage); } elseif ($swapAccess && $swapStage == 0) { $versionArray['allowedAction_swap'] = $isRecordTypeAllowedToModify; } else { $versionArray['allowedAction_swap'] = FALSE; } $versionArray['allowedAction_delete'] = $isRecordTypeAllowedToModify; // preview and editing of a deleted page won't work ;) $versionArray['allowedAction_view'] = !$isDeletedPage && $viewUrl; $versionArray['allowedAction_edit'] = $isRecordTypeAllowedToModify && !$isDeletedPage; $versionArray['allowedAction_editVersionedPage'] = $isRecordTypeAllowedToModify && !$isDeletedPage; $versionArray['state_Workspace'] = $recordState; $versionArray = array_merge($versionArray, $this->getAdditionalColumnService()->getData($combinedRecord)); if ($filterTxt == '' || $this->isFilterTextInVisibleColumns($filterTxt, $versionArray)) { $versionIdentifier = $versionArray['id']; $this->dataArray[$versionIdentifier] = $versionArray; } } } // Suggested slot method: // methodName(\TYPO3\CMS\Workspaces\Service\GridDataService $gridData, array &$dataArray, array $versions) $this->emitSignal(self::SIGNAL_GenerateDataArray_BeforeCaching, $this->dataArray, $versions); // Enrich elements after everything has been processed: foreach ($this->dataArray as &$element) { $identifier = $element['table'] . ':' . $element['t3ver_oid']; $element['integrity'] = array('status' => $this->getIntegrityService()->getStatusRepresentation($identifier), 'messages' => htmlspecialchars($this->getIntegrityService()->getIssueMessages($identifier, TRUE))); } $this->setDataArrayIntoCache($versions, $filterTxt); } // Suggested slot method: // methodName(\TYPO3\CMS\Workspaces\Service\GridDataService $gridData, array &$dataArray, array $versions) $this->emitSignal(self::SIGNAL_GenerateDataArray_PostProcesss, $this->dataArray, $versions); $this->sortDataArray(); $this->resolveDataArrayDependencies(); }
/** * Create the workspace information * * @return string HTML containing workspace info */ protected function getWorkspaceInfo() { if (ExtensionManagementUtility::isLoaded('workspaces') && ($this->getBackendUser()->workspace !== 0 || $this->getBackendUser()->getTSConfigVal('options.pageTree.onlineWorkspaceInfo'))) { $wsTitle = htmlspecialchars(WorkspaceService::getWorkspaceTitle($this->getBackendUser()->workspace)); $workspaceInfo = '<div class="bgColor4 workspace-info"><span title="' . $wsTitle . '" onclick="top.goToModule(\'web_WorkspacesWorkspaces\');" style="cursor:pointer;">' . $this->iconFactory->getIcon('apps-toolbar-menu-workspace', Icon::SIZE_SMALL)->render() . '</span>' . $wsTitle . '</div>'; } else { $workspaceInfo = ''; } return $workspaceInfo; }
/** * Create the workspace information * * @return string HTML containing workspace info */ protected function getWorkspaceInfo() { if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('workspaces') && ($GLOBALS['BE_USER']->workspace !== 0 || $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.onlineWorkspaceInfo'))) { $wsTitle = htmlspecialchars(\TYPO3\CMS\Workspaces\Service\WorkspaceService::getWorkspaceTitle($GLOBALS['BE_USER']->workspace)); $workspaceInfo = ' <div class="bgColor4 workspace-info">' . IconUtility::getSpriteIcon('apps-toolbar-menu-workspace', array('title' => $wsTitle, 'onclick' => 'top.goToModule(\'web_WorkspacesWorkspaces\');', 'style' => 'cursor:pointer;')) . $wsTitle . '</div> '; } return $workspaceInfo; }
/** * Constructor * * @param \TYPO3\CMS\Backend\Controller\BackendController $backendReference TYPO3 backend object reference */ public function __construct(\TYPO3\CMS\Backend\Controller\BackendController &$backendReference = NULL) { $this->backendReference = $backendReference; $this->backendReference->addJavaScript('TYPO3.Workspaces = { workspaceTitle : ' . GeneralUtility::quoteJSvalue(addslashes(\TYPO3\CMS\Workspaces\Service\WorkspaceService::getWorkspaceTitle($GLOBALS['BE_USER']->workspace))) . '};'); }