diff --git a/typo3/sysext/workspaces/Classes/Hook/TypoScriptFrontendControllerHook.php b/typo3/sysext/workspaces/Classes/Hook/TypoScriptFrontendControllerHook.php index 0d103983b58ffddc8b2c5b51a3a0d53aed1e81bc..46daee2e5d0fc91d203444aa83c0b00c760928df 100644 --- a/typo3/sysext/workspaces/Classes/Hook/TypoScriptFrontendControllerHook.php +++ b/typo3/sysext/workspaces/Classes/Hook/TypoScriptFrontendControllerHook.php @@ -14,20 +14,35 @@ namespace TYPO3\CMS\Workspaces\Hook; * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Database\ConnectionPool; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Utility\LocalizationUtility; + /** * Frontend hooks */ class TypoScriptFrontendControllerHook { /** + * Renders a message at the bottom of the HTML page, can be modified via + * + * config.disablePreviewNotification = 1 (to disable the additional info text) + * + * and + * + * config.message_preview_workspace = This is not the online version but the version of "%s" workspace (ID: %s). + * + * via TypoScript. + * * @param array $params * @param \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $pObj + * @return string */ - public function hook_eofe($params, $pObj) + public function renderPreviewInfo(array $params, \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $pObj) { // 2 means preview of a non-live workspace if ($pObj->fePreview !== 2) { - return; + return ''; } if (empty($this->getBackendUserAuthentication()->getSessionData('workspaces.backend_domain'))) { @@ -36,22 +51,57 @@ class TypoScriptFrontendControllerHook $backendDomain = $this->getBackendUserAuthentication()->getSessionData('workspaces.backend_domain'); } - $previewParts = $this->getTypoScriptFrontendController()->cObj->cObjGetSingle('FLUIDTEMPLATE', [ + $content = $pObj->cObj->cObjGetSingle('FLUIDTEMPLATE', [ 'file' => 'EXT:workspaces/Resources/Private/Templates/Preview/Preview.html', 'variables.' => [ 'backendDomain' => 'TEXT', 'backendDomain.' => ['value' => $backendDomain] ] ]); - $this->getTypoScriptFrontendController()->content = str_ireplace('</body>', $previewParts . '</body>', $this->getTypoScriptFrontendController()->content); + + if (!isset($pObj->config['config']['disablePreviewNotification']) || (int)$pObj->config['config']['disablePreviewNotification'] !== 1) { + // get the title of the current workspace + $currentWorkspaceId = $pObj->whichWorkspace(); + $currentWorkspaceTitle = $this->getWorkspaceTitle($currentWorkspaceId); + $currentWorkspaceTitle = htmlspecialchars($currentWorkspaceTitle); + if ($pObj->config['config']['message_preview_workspace']) { + $content .= sprintf($pObj->config['config']['message_preview_workspace'], $currentWorkspaceTitle, + $currentWorkspaceId ?? -1); + } else { + $text = LocalizationUtility::translate('LLL:EXT:workspaces/Resources/Private/Language/locallang_mod.xlf:previewText', + 'workspaces', [$currentWorkspaceTitle, $currentWorkspaceId ?? -1]); + if ($pObj->doWorkspacePreview()) { + $urlForStoppingPreview = GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . 'index.php?ADMCMD_prev=LOGOUT&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI')); + $text .= '<br><a style="color: #000;" href="' . $urlForStoppingPreview . '">Stop preview</a>'; + } + $content .= '<div id="typo3-previewInfo" style="position: absolute; top: 20px; right: 20px; border: 2px solid #000; padding: 5px; background: #f00; font: 1em Verdana; color: #000; font-weight: bold; z-index: 10001">' . $text . '</div>'; + } + } + return $content; } /** - * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController + * Fetches the title of the workspace + * + * @param $workspaceId + * @return string the title of the workspace */ - protected function getTypoScriptFrontendController() + protected function getWorkspaceTitle(int $workspaceId): string { - return $GLOBALS['TSFE']; + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable('sys_workspace'); + $title = $queryBuilder + ->select('title') + ->from('sys_workspace') + ->where( + $queryBuilder->expr()->eq( + 'uid', + $queryBuilder->createNamedParameter($workspaceId, \PDO::PARAM_INT) + ) + ) + ->execute() + ->fetchColumn(); + return $title !== false ? $title : ''; } /** diff --git a/typo3/sysext/workspaces/Resources/Private/Language/locallang_mod.xlf b/typo3/sysext/workspaces/Resources/Private/Language/locallang_mod.xlf index c6b21529970641feb4cac451e35ac8a94e2d6c7b..da322ec6c493b00b2e5aa3fe12569741dfe11ca3 100644 --- a/typo3/sysext/workspaces/Resources/Private/Language/locallang_mod.xlf +++ b/typo3/sysext/workspaces/Resources/Private/Language/locallang_mod.xlf @@ -27,6 +27,9 @@ <trans-unit id="stage_ready_to_publish"> <source>Ready to publish</source> </trans-unit> + <trans-unit id="previewText"> + <source>Preview of workspace %s (%s)</source> + </trans-unit> </body> </file> </xliff> diff --git a/typo3/sysext/workspaces/ext_localconf.php b/typo3/sysext/workspaces/ext_localconf.php index ad67131908b4041a9ca31fd7cb3a59415e14ad5c..be5576b8fabb3b6435401838824e8872b3b8797f 100644 --- a/typo3/sysext/workspaces/ext_localconf.php +++ b/typo3/sysext/workspaces/ext_localconf.php @@ -17,7 +17,7 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][\TYPO3\CMS\Works $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass']['workspaces'] = \TYPO3\CMS\Workspaces\Hook\DataHandlerHook::class; $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass']['workspaces'] = \TYPO3\CMS\Workspaces\Hook\BackendUtilityHook::class; -$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['hook_eofe']['workspaces'] = \TYPO3\CMS\Workspaces\Hook\TypoScriptFrontendControllerHook::class . '->hook_eofe'; +$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['hook_previewInfo']['workspaces'] = \TYPO3\CMS\Workspaces\Hook\TypoScriptFrontendControllerHook::class . '->renderPreviewInfo'; $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/alt_doc.php']['makeEditForm_accessCheck']['workspaces'] = \TYPO3\CMS\Workspaces\Hook\BackendUtilityHook::class . '->makeEditForm_accessCheck'; // Register hook to check for the preview mode in the FE