Fixed bug #16173: Refactor FLUIDTEMPLATE cObject to use the new Fluid standalone...
authorSteffen Kamper <info@sk-typo3.de>
Tue, 2 Nov 2010 15:05:45 +0000 (15:05 +0000)
committerSteffen Kamper <info@sk-typo3.de>
Tue, 2 Nov 2010 15:05:45 +0000 (15:05 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@9242 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/cms/tslib/content/class.tslib_content_fluidtemplate.php

index ba738ee..62604dd 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-11-02  Steffen Kamper  <steffen@typo3.org>
+
+       * Fixed bug #16173: Refactor FLUIDTEMPLATE cObject to use the new Fluid standalone view (Thanks to Bastian Waidelich)
+
 2010-11-02  Xavier Perseguers  <typo3@perseguers.ch>
 
        * Added feature #16177: Add DB structure update pre-processing hook in EM
index 4537305..88a7f31 100644 (file)
  * $Id: class.tslib_content.php 7905 2010-06-13 14:42:33Z ohader $
  * @author Xavier Perseguers <typo3@perseguers.ch>
  * @author Steffen Kamper <steffen@typo3.org>
+ * @author Bastian Waidelich <bastian@typo3.org>
  */
 class tslib_content_FluidTemplate extends tslib_content_Abstract {
 
        /**
-        * Rendering the cObject, TEMPLATE
-        *
-        * @param       array           array of TypoScript properties
-        * @return      string          Output
-        * @see substituteMarkerArrayCached()
-        */
-       function TEMPLATE($conf) {
-               return $this->getContentObject('TEMPLATE')->render($conf);
-       }
-
-       /**
         * Rendering the cObject, FLUIDTEMPLATE
         *   configuration properties are:
         *   - file     string+stdWrap  the FLUID template file
@@ -67,145 +57,113 @@ class tslib_content_FluidTemplate extends tslib_content_Abstract {
         *
         * @param       array           array of TypoScript properties
         * @return      string          the HTML output
-        * @author      Steffen Ritter  <info@steffen-ritter.net>
-        * @author      Benjamin Mack   <benni@typo3.org>
+        * @author      Steffen Ritter          <info@steffen-ritter.net>
+        * @author      Benjamin Mack           <benni@typo3.org>
+        * @author      Bastian Waidelich       <bastian@typo3.org>
         */
        public function render($conf = array()) {
                        // check if the needed extensions are installed
                if (!t3lib_extMgm::isLoaded('fluid')) {
                        return 'You need to install "Fluid" in order to use the FLUIDTEMPLATE content element';
                }
-               if (!t3lib_extMgm::isLoaded('extbase')) {
-                       return 'You need to install "Extbase" in order to use the FLUIDTEMPLATE content element';
-               }
-
-                       // initialize the extbase autoloader,
-                       // see Extbase_Dispatcher->initializeClassLoader
-               if (!class_exists('Tx_Extbase_Utility_ClassLoader')) {
-                       require(t3lib_extmgm::extPath('extbase') . 'Classes/Utility/ClassLoader.php');
-
-                       $classLoader = new Tx_Extbase_Utility_ClassLoader();
-                       spl_autoload_register(array($classLoader, 'loadClass'));
-               }
-
 
                /**
-                * 1. initializing configuration parameters
+                * 1. initializing Fluid StandaloneView and setting configuration parameters
                 **/
-
-                       // fetch the FLUID file
-               $templateFile = $GLOBALS['TSFE']->tmpl->getFileName($this->cObj->stdWrap($conf['file'], $conf['file.']));
-               $templatePath = dirname($templateFile) . '/';
-               $layoutRootPath = $templatePath . 'Layouts';
-               $partialRootPath = $templatePath . 'Partials';
+               $view = t3lib_div::makeInstance('Tx_Fluid_View_StandaloneView');
+                       // fetch the Fluid template
+               $file = isset($conf['file.'])
+                       ? $this->cObj->stdWrap($conf['file'], $conf['file.'])
+                       : $conf['file'];
+               $templatePathAndFilename = $GLOBALS['TSFE']->tmpl->getFileName($file);
+               $view->setTemplatePathAndFilename($templatePathAndFilename);
 
                        // override the default layout path via typoscript
-               if (isset($conf['layoutRootPath']) || isset($conf['layoutRootPath.'])) {
-                       $layoutRootPath = $this->cObj->stdWrap($conf['layoutRootPath'], $conf['layoutRootPath.']);
+               $layoutRootPath = isset($conf['layoutRootPath.'])
+                       ? $this->cObj->stdWrap($conf['layoutRootPath'], $conf['layoutRootPath.'])
+                       : $conf['layoutRootPath'];
+               if($layoutRootPath) {
                        $layoutRootPath = t3lib_div::getFileAbsFileName($layoutRootPath);
+                       $view->setLayoutRootPath($layoutRootPath);
                }
 
                        // override the default partials path via typoscript
-               if (isset($conf['partialRootPath']) || isset($conf['partialRootPath.'])) {
-                       $partialRootPath = $this->cObj->stdWrap($conf['partialRootPath'], $conf['partialRootPath.']);
+               $partialRootPath = isset($conf['partialRootPath.'])
+                       ? $this->cObj->stdWrap($conf['partialRootPath'], $conf['partialRootPath.'])
+                       : $conf['partialRootPath'];
+               if($partialRootPath) {
                        $partialRootPath = t3lib_div::getFileAbsFileName($partialRootPath);
+                       $view->setPartialRootPath($partialRootPath);
                }
 
+                       // override the default format
+               $format = isset($conf['format.'])
+                       ? $this->cObj->stdWrap($conf['format'], $conf['format.'])
+                       : $conf['format'];
+               if ($format) {
+                       $view->setFormat($format);
+               }
 
                        // set some default variables for initializing Extbase
-               if (isset($conf['extbase.']['pluginName'])) {
-                       $requestPluginName = $conf['extbase.']['pluginName'];
-               } else {
-                       $requestPluginName = 'pi1';
+               $requestPluginName = isset($conf['extbase.']['pluginName.'])
+                       ? $this->cObj->stdWrap($conf['extbase.']['pluginName'], $conf['extbase.']['pluginName.'])
+                       : $conf['extbase.']['pluginName'];
+               if($requestPluginName) {
+                       $view->getRequest()->setPluginName($requestPluginName);
                }
 
-               if (isset($conf['extbase.']['controllerExtensionName'])) {
-                       $requestControllerExtensionName = $conf['extbase.']['controllerExtensionName'];
-               } else {
-                       $requestControllerExtensionName = 'cms';
+               $requestControllerExtensionName = isset($conf['extbase.']['controllerExtensionName.'])
+                       ? $this->cObj->stdWrap($conf['extbase.']['controllerExtensionName'], $conf['extbase.']['controllerExtensionName.'])
+                       : $conf['extbase.']['controllerExtensionName'];
+               if($requestControllerExtensionName) {
+                       $view->getRequest()->setControllerExtensionName($requestControllerExtensionName);
                }
 
-               if (isset($conf['extbase.']['controllerName'])) {
-                       $requestControllerName = $conf['extbase.']['controllerName'];
-               } else {
-                       $requestControllerName = 'cms';
+               $requestControllerName = isset($conf['extbase.']['controllerName.'])
+                       ? $this->cObj->stdWrap($conf['extbase.']['controllerName'], $conf['extbase.']['controllerName.'])
+                       : $conf['extbase.']['controllerName'];
+               if($requestControllerName) {
+                       $view->getRequest()->setControllerName($requestControllerName);
                }
 
-               if (isset($conf['extbase.']['controllerActionName'])) {
-                       $requestControllerActionName = $conf['extbase.']['controllerActionName'];
-               } else {
-                       $requestControllerActionName = 'index';
+               $requestControllerActionName = isset($conf['extbase.']['controllerActionName.'])
+                       ? $this->cObj->stdWrap($conf['extbase.']['controllerActionName'], $conf['extbase.']['controllerActionName.'])
+                       : $conf['extbase.']['controllerActionName'];
+               if($requestControllerActionName) {
+                       $view->getRequest()->setControllerActionName($requestControllerActionName);
                }
 
-
-               /**
-                * 2. initializing Fluid classes,
-                * first, the controller context needs to be created
-                **/
-               $objectManager = t3lib_div::makeInstance('Tx_Fluid_Compatibility_ObjectManager');
-
-                       // creating a request object
-               $controllerContext = $objectManager->create('Tx_Extbase_MVC_Controller_ControllerContext');
-               /**
-                * @var $request Tx_Extbase_MVC_Web_Request
-                */
-               $request = t3lib_div::makeInstance('Tx_Extbase_MVC_Web_Request');
-               $request->setPluginName($requestPluginName);
-               $request->setControllerExtensionName($requestControllerExtensionName);
-               $request->setControllerName($requestControllerName);
-               $request->setControllerActionName($requestControllerActionName);
-               $request->setRequestURI(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'));
-               $request->setBaseURI(t3lib_div::getIndpEnv('TYPO3_SITE_URL'));
-
-               /**
-                * @var $uriBuilder Tx_Extbase_MVC_Web_Routing_UriBuilder
-                */
-               $uriBuilder = t3lib_div::makeInstance('Tx_Extbase_MVC_Web_Routing_UriBuilder');
-               $uriBuilder->setRequest($request);
-
-               $controllerContext->setRequest($request);
-               $controllerContext->setUriBuilder($uriBuilder);
-
-               /**
-                * @var $view Tx_Fluid_View_TemplateView
-                */
-               $view = t3lib_div::makeInstance('Tx_Fluid_View_TemplateView');
-               $view->setControllerContext($controllerContext);
-
-                       // setting the paths for the template and the layouts/partials
-               $view->setTemplatePathAndFilename($templateFile);
-               $view->setLayoutRootPath($layoutRootPath);
-               $view->setPartialRootPath($partialRootPath);
-
-                       // In FLOW3, solved through Object Lifecycle methods,
-                       // v4 needs to call it explicitely
-               $view->initializeView();
-
-
                /**
-                * 3. variable replacement
-                */
+                * 2. variable assignment
+                */
                $reservedVariables = array('data', 'current');
                        // accumulate the variables to be replaced
                        // and loop them through cObjGetSingle
                $variables = (array) $conf['variables.'];
                foreach ($variables as $variableName => $cObjType) {
+                       if (is_array($cObjType)) {
+                               continue;
+                       }
                        if(!in_array($variableName, $reservedVariables)) {
-                               if (!is_array($cObjType)) {
-                                       $view->assign($variableName, $this->cObj->cObjGetSingle($cObjType, $variables[$variableName . '.']));
-                               }
+                               $view->assign($variableName, $this->cObj->cObjGetSingle($cObjType, $variables[$variableName . '.']));
                        } else {
-                               throw new InvalidArgumentException('Cannot use reserved name "' . $variableName . '" as variable name in FLUIDTEMPLATE');
+                               throw new InvalidArgumentException('Cannot use reserved name "' . $variableName . '" as variable name in FLUIDTEMPLATE.', 1288095720);
                        }
                }
                $view->assign('data', $this->cObj->data);
                $view->assign('current', $this->cObj->data[$this->cObj->currentValKey]);
 
                /**
-                * 4. render the content
+                * 3. render the content
                 */
-               $content = $view->render();
-               return $this->cObj->stdWrap($content, $conf['stdWrap.']);
+               $theValue = $view->render();
+
+               if(isset($conf['stdWrap.'])) {
+                       $theValue = $this->cObj->stdWrap($theValue, $conf['stdWrap.']);
+               }
+
+               return $theValue;
+
        }
 
 }