[+BUGFIX] Fluid (ViewHelpers): replaced two occurrences of Tx_Extbase_Dispatcher...
authorBastian Waidelich <bastian@typo3.org>
Tue, 16 Nov 2010 23:49:43 +0000 (23:49 +0000)
committerBastian Waidelich <bastian@typo3.org>
Tue, 16 Nov 2010 23:49:43 +0000 (23:49 +0000)
[+TASK] Fluid (ViewHelpers): uri.image now works in BE mode too

typo3/sysext/fluid/Classes/ViewHelpers/Be/TableListViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php

index da12ee6..0d36110 100644 (file)
@@ -53,6 +53,18 @@ require_once (PATH_typo3 . 'class.db_list_extra.inc');
 
 class Tx_Fluid_ViewHelpers_Be_TableListViewHelper extends Tx_Fluid_ViewHelpers_Be_AbstractBackendViewHelper {
 
+       /**
+        * @var Tx_Extbase_Configuration_ConfigurationManagerInterface
+        */
+       protected $configurationManager;
+
+       /**
+        * @param Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager
+        * @return void
+        */
+       public function injectConfigurationManager(Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager) {
+               $this->configurationManager = $configurationManager;
+       }
 
        /**
         * Renders a record list as known from the TYPO3 list module
@@ -89,7 +101,7 @@ class Tx_Fluid_ViewHelpers_Be_TableListViewHelper extends Tx_Fluid_ViewHelpers_B
                $dblist->clickMenuEnabled = $enableClickMenu;
 
                if ($storagePid === NULL) {
-                       $frameworkConfiguration = Tx_Extbase_Dispatcher::getExtbaseFrameworkConfiguration();
+                       $frameworkConfiguration = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
                        $storagePid = $frameworkConfiguration['persistence']['storagePid'];
                }
 
index 41386a4..a17aaf0 100644 (file)
@@ -140,8 +140,7 @@ class Tx_Fluid_ViewHelpers_ImageViewHelper extends Tx_Fluid_Core_ViewHelper_Abst
                $this->workingDirectoryBackup = getcwd();
                chdir(PATH_site);
 
-               $configurationManager = Tx_Extbase_Dispatcher::getConfigurationManager();
-               $typoScriptSetup = $configurationManager->loadTypoScriptSetup();
+               $typoScriptSetup = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
                $GLOBALS['TSFE'] = new stdClass();
                $template = t3lib_div::makeInstance('t3lib_TStemplate');
                $template->tt_track = 0;
index f226b67..679ccd2 100644 (file)
@@ -57,7 +57,7 @@ class Tx_Fluid_ViewHelpers_Uri_ImageViewHelper extends Tx_Fluid_Core_ViewHelper_
         */
        public function render($src, $width = NULL, $height = NULL, $minWidth = NULL, $minHeight = NULL, $maxWidth = NULL, $maxHeight = NULL) {
                if (TYPO3_MODE === 'BE') {
-                       throw new Tx_Fluid_Core_ViewHelper_Exception('uri.image ViewHelper does not (yet) work in backend mode' , 1277367648);
+                       $this->simulateFrontendEnvironment();
                }
                $setup = array(
                        'width' => $width,
@@ -67,6 +67,9 @@ class Tx_Fluid_ViewHelpers_Uri_ImageViewHelper extends Tx_Fluid_Core_ViewHelper_
                        'maxW' => $maxWidth,
                        'maxH' => $maxHeight
                );
+               if (TYPO3_MODE === 'BE' && substr($src, 0, 3) === '../') {
+                       $src = substr($src, 3);
+               }
                $imageInfo = $this->contentObject->getImgResource($src, $setup);
                $GLOBALS['TSFE']->lastImageInfo = $imageInfo;
                if (!is_array($imageInfo)) {
@@ -76,7 +79,48 @@ class Tx_Fluid_ViewHelpers_Uri_ImageViewHelper extends Tx_Fluid_Core_ViewHelper_
                $GLOBALS['TSFE']->imagesOnPage[] = $imageInfo[3];
 
                $imageSource = $GLOBALS['TSFE']->absRefPrefix . t3lib_div::rawUrlEncodeFP($imageInfo[3]);
+               if (TYPO3_MODE === 'BE') {
+                       $imageSource = '../' . $imageSource;
+                       $this->resetFrontendEnvironment();
+               }
 
                return $imageSource;
        }
+
+       /**
+        * Prepares $GLOBALS['TSFE'] for Backend mode
+        * This somewhat hacky work around is currently needed because the getImgResource() function of tslib_cObj relies on those variables to be set
+        *
+        * @return void
+        * @author Bastian Waidelich <bastian@typo3.org>
+        */
+       protected function simulateFrontendEnvironment() {
+               $this->tsfeBackup = isset($GLOBALS['TSFE']) ? $GLOBALS['TSFE'] : NULL;
+                       // set the working directory to the site root
+               $this->workingDirectoryBackup = getcwd();
+               chdir(PATH_site);
+
+               $typoScriptSetup = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
+               $GLOBALS['TSFE'] = new stdClass();
+               $template = t3lib_div::makeInstance('t3lib_TStemplate');
+               $template->tt_track = 0;
+               $template->init();
+               $template->getFileName_backPath = PATH_site;
+               $GLOBALS['TSFE']->tmpl = $template;
+               $GLOBALS['TSFE']->tmpl->setup = $typoScriptSetup;
+               $GLOBALS['TSFE']->config = $typoScriptSetup;
+       }
+
+       /**
+        * Resets $GLOBALS['TSFE'] if it was previously changed by simulateFrontendEnvironment()
+        *
+        * @return void
+        * @author Bastian Waidelich <bastian@typo3.org>
+        * @see simulateFrontendEnvironment()
+        */
+       protected function resetFrontendEnvironment() {
+               $GLOBALS['TSFE'] = $this->tsfeBackup;
+               chdir($this->workingDirectoryBackup);
+       }
+
 }
\ No newline at end of file