[FEATURE] Fluid (TemplateView): Made templateRootPath configurable via TypoScript...
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / MVC / Controller / ActionController.php
index f9cf031..2247a64 100644 (file)
@@ -55,7 +55,7 @@ class Tx_Extbase_MVC_Controller_ActionController extends Tx_Extbase_MVC_Controll
         * @var string
         * @api
         */
-       protected $viewObjectNamePattern = 'Tx_@extension_View_@controller_@action';
+       protected $viewObjectNamePattern = 'Tx_@extension_View_@controller_@action@format';
 
        /**
         * The default view object to use if neither a Fluid template nor an action
@@ -255,10 +255,17 @@ class Tx_Extbase_MVC_Controller_ActionController extends Tx_Extbase_MVC_Controll
                $view = $this->objectManager->getObject('Tx_Fluid_View_TemplateView');
                $controllerContext = $this->buildControllerContext();
                $view->setControllerContext($controllerContext);
+               
+               // Template Path Override
+               $extbaseFrameworkConfiguration = Tx_Extbase_Dispatcher::getExtbaseFrameworkConfiguration();
+               if (isset($extbaseFrameworkConfiguration['view']['templateRootPath']) && $extbaseFrameworkConfiguration['view']['templateRootPath']) {
+                       $view->setTemplateRootPath($extbaseFrameworkConfiguration['view']['templateRootPath']);
+               }
+
                if ($view->hasTemplate() === FALSE) {
                        $viewObjectName = $this->resolveViewObjectName();
-                       if ($viewObjectName === FALSE) $viewObjectName = 'Tx_Extbase_MVC_View_EmptyView';
-                       $view = t3lib_div::makeInstance($viewObjectName);
+                       if (class_exists($viewObjectName) === FALSE) $viewObjectName = 'Tx_Extbase_MVC_View_EmptyView';
+                       $view = $this->objectManager->getObject($viewObjectName);
                        $view->setControllerContext($controllerContext);
                }
                if (method_exists($view, 'injectSettings')) {
@@ -277,18 +284,23 @@ class Tx_Extbase_MVC_Controller_ActionController extends Tx_Extbase_MVC_Controll
         */
        protected function resolveViewObjectName() {
                $possibleViewName = $this->viewObjectNamePattern;
-               $possibleViewName = str_replace('@extension', $this->request->getControllerExtensionName(), $possibleViewName);
+               $extensionName = $this->request->getControllerExtensionName();
+               $subextensionName = $this->request->getControllerSubextensionName();
+               if ($subextensionName !== NULL && $subextensionName !== '') {
+                       $extensionName.= '_' . $subextensionName;
+               }
+               $possibleViewName = str_replace('@extension', $extensionName, $possibleViewName);
                $possibleViewName = str_replace('@controller', $this->request->getControllerName(), $possibleViewName);
                $possibleViewName = str_replace('@action', ucfirst($this->request->getControllerActionName()), $possibleViewName);
 
-               if (class_exists($possibleViewName)) {
-                       return $possibleViewName;
+               $viewObjectName = str_replace('@format', ucfirst($this->request->getFormat()), $possibleViewName);              
+               if (class_exists($viewObjectName) === FALSE) {
+                       $viewObjectName = str_replace('@format', '', $possibleViewName);
                }
-
-               if ($this->defaultViewObjectName !== NULL && class_exists($this->defaultViewObjectName)) {
-                       return $this->defaultViewObjectName;
+               if (class_exists($viewObjectName) === FALSE && $this->defaultViewObjectName !== NULL) {
+                       $viewObjectName = $this->defaultViewObjectName;
                }
-               return FALSE;
+               return $viewObjectName;
        }
 
        /**
@@ -323,11 +335,15 @@ class Tx_Extbase_MVC_Controller_ActionController extends Tx_Extbase_MVC_Controll
         * The default implementation sets a flash message, request errors and forwards back
         * to the originating action. This is suitable for most actions dealing with form input.
         *
+        * We clear the page cache by default on an error as well, as we need to make sure the
+        * data is re-evaluated when the user changes something.
+        *
         * @return string
         * @api
         */
        protected function errorAction() {
                $this->request->setErrors($this->argumentsMappingResults->getErrors());
+               $this->clearCacheOnError();
 
                if ($this->request->hasArgument('__referrer')) {
                        $referrer = $this->request->getArgument('__referrer');
@@ -344,5 +360,21 @@ class Tx_Extbase_MVC_Controller_ActionController extends Tx_Extbase_MVC_Controll
                return $message;
        }
 
+       /**
+        * Clear cache of current page on error. Needed because we want a re-evaluation of the data.
+        * Better would be just do delete the cache for the error action, but that is not possible right now.
+        *
+        * @return void
+        */
+       protected function clearCacheOnError() {
+               $extbaseSettings = Tx_Extbase_Dispatcher::getExtbaseFrameworkConfiguration();
+               if (isset($extbaseSettings['persistence']['enableAutomaticCacheClearing']) && $extbaseSettings['persistence']['enableAutomaticCacheClearing'] === '1') {
+                       if (isset($GLOBALS['TSFE'])) {
+                               $pageUid = $GLOBALS['TSFE']->id;
+                               Tx_Extbase_Utility_Cache::clearPageCache(array($pageUid));
+                       }
+               }
+       }
+
 }
 ?>
\ No newline at end of file