Skip to content
Snippets Groups Projects
Commit 2e526cc1 authored by Robert Vock's avatar Robert Vock Committed by Christian Kuhn
Browse files

[BUGFIX] Added missing workspace preview info

The workspace preview info got lost from TYPO3 4.5 to 4.6. This commit
readds the info and respects the same TypoScript config options.

Resolves: #77467
Releases: master, 8.7
Change-Id: Ie1696a5f86714c6ef9a61c10c41b0397abb95ab5
Reviewed-on: https://review.typo3.org/49740


Reviewed-by: default avatarJan Helke <typo3@helke.de>
Tested-by: default avatarJan Helke <typo3@helke.de>
Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 2d536cfd
Branches
Tags
No related merge requests found
......@@ -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 : '';
}
/**
......
......@@ -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>
......@@ -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
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment