[BUGFIX] Assure a backend domain is set in workspace preview 37/42837/2
authorDaniel Goerz <ervaude@gmail.com>
Fri, 7 Aug 2015 19:27:44 +0000 (21:27 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Sat, 22 Aug 2015 08:48:45 +0000 (10:48 +0200)
Change-Id: Idc17243f8741057ee6ea1746ec6c344aec28d57a
Resolves: #45519
Resolves: #31718
Releases: master, 6.2
Reviewed-on: http://review.typo3.org/42837
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/workspaces/Classes/Hook/TypoScriptFrontendControllerHook.php

index 70fa2f8..8a74296 100644 (file)
@@ -23,20 +23,41 @@ class TypoScriptFrontendControllerHook {
        /**
         * @param array $params
         * @param \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $pObj
-        * @return mixed
+        * @return void
         */
        public function hook_eofe($params, $pObj) {
-               if ($pObj->fePreview != 2) {
+               // 2 means preview of a non-live workspace
+               if ($pObj->fePreview !== 2) {
                        return;
                }
-               $previewParts = $GLOBALS['TSFE']->cObj->cObjGetSingle('FLUIDTEMPLATE', array(
+
+               $backendDomain = $this->getBackendUserAuthentication()->getSessionData('workspaces.backend_domain');
+               if (empty($backendDomain)) {
+                       $backendDomain = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY');
+               }
+
+               $previewParts = $this->getTypoScriptFrontendController()->cObj->cObjGetSingle('FLUIDTEMPLATE', array(
                        'file' => 'EXT:workspaces/Resources/Private/Templates/Preview/Preview.html',
                        'variables.' => array(
                                'backendDomain' => 'TEXT',
-                               'backendDomain.' => array('value' => $GLOBALS['BE_USER']->getSessionData('workspaces.backend_domain'))
+                               'backendDomain.' => array('value' => $backendDomain)
                        )
                ));
-               $GLOBALS['TSFE']->content = str_ireplace('</body>', $previewParts . '</body>', $GLOBALS['TSFE']->content);
+               $this->getTypoScriptFrontendController()->content = str_ireplace('</body>', $previewParts . '</body>', $this->getTypoScriptFrontendController()->content);
+       }
+
+       /**
+        * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
+        */
+       protected function getTypoScriptFrontendController() {
+               return $GLOBALS['TSFE'];
+       }
+
+       /**
+        * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
+        */
+       protected function getBackendUserAuthentication() {
+               return $GLOBALS['BE_USER'];
        }
 
 }