[+FEATURE] Fluid (Widgets): Allow overriding templateRootPath
authorStefan Neufeind <typo3.neufeind@speedpartner.de>
Sat, 11 Jun 2011 12:55:15 +0000 (14:55 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Sat, 11 Jun 2011 16:07:45 +0000 (18:07 +0200)
Allows the widget template root path to be overriden via the framework
configuration, for example:
plugin.tx_extension.view {
  widget.<WidgetViewHelperClassName>.templateRootPath=...
}

Thanks to Peter B├╝cker.

Change-Id: I0ca31753450c49a74e5161996f9a83bb7b032237
Resolves: #10823

typo3/sysext/fluid/Classes/Core/Widget/AbstractWidgetController.php
typo3/sysext/fluid/Tests/Unit/Core/Widget/AbstractWidgetControllerTest.php

index f16c094..69a944c 100644 (file)
@@ -57,12 +57,21 @@ abstract class Tx_Fluid_Core_Widget_AbstractWidgetController extends Tx_Extbase_
        }
 
        /**
+        * Allows the widget template root path to be overriden via the framework configuration,
+        * e.g. plugin.tx_extension.view.widget.<WidgetViewHelperClassName>.templateRootPath
+        *
         * @param Tx_Extbase_MVC_View_ViewInterface $view
         * @return void
-        * @todo implement logic for overriding widget template paths (tx_extension.view.widget.<WidgetViewHelperClassName>.templateRootPath...)
         */
        protected function setViewConfiguration(Tx_Extbase_MVC_View_ViewInterface $view) {
-               return;
+               $extbaseFrameworkConfiguration = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
+               $widgetViewHelperClassName = $this->request->getWidgetContext()->getWidgetViewHelperClassName();
+
+               if (isset($extbaseFrameworkConfiguration['view']['widget'][$widgetViewHelperClassName]['templateRootPath'])
+                       && strlen($extbaseFrameworkConfiguration['view']['widget'][$widgetViewHelperClassName]['templateRootPath']) > 0
+                       && method_exists($view, 'setTemplateRootPath')) {
+                       $view->setTemplateRootPath(t3lib_div::getFileAbsFileName($extbaseFrameworkConfiguration['view']['widget'][$widgetViewHelperClassName]['templateRootPath']));
+               }
        }
 }
 
index 79efb0a..e2463b7 100644 (file)
@@ -64,5 +64,39 @@ class Tx_Fluid_Tests_Unit_Core_Widget_AbstractWidgetControllerTest extends Tx_Ex
                $widgetConfiguration = $abstractWidgetController->_get('widgetConfiguration');
                $this->assertEquals('myConfiguration', $widgetConfiguration);
        }
+
+       /**
+        * @test
+        */
+       public function viewConfigurationCanBeOverriddenThroughFrameworkConfiguration() {
+               $frameworkConfiguration = array(
+                       'view' => array(
+                               'widget' => array(
+                                       'Tx_Fluid_ViewHelpers_Widget_PaginateViewHelper' => array(
+                                               'templateRootPath' => 'EXT:fluid/Resources/Private/DummyTestTemplates'
+                                       )
+                               )
+                       )
+               );
+
+               $widgetContext = $this->getMock('Tx_Fluid_Core_Widget_WidgetContext');
+               $widgetContext->expects($this->any())->method('getWidgetViewHelperClassName')->will($this->returnValue('Tx_Fluid_ViewHelpers_Widget_PaginateViewHelper'));
+
+               $request = $this->getMock('Tx_Fluid_Core_Widget_WidgetRequest', array(), array(), '', FALSE);
+               $request->expects($this->any())->method('getWidgetContext')->will($this->returnValue($widgetContext));
+
+               $configurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManager');
+               $configurationManager->expects($this->any())
+                       ->method('getConfiguration')
+                       ->will($this->returnValue($frameworkConfiguration));
+
+               $view = $this->getAccessibleMock('Tx_Fluid_View_TemplateView', array('dummy'));
+
+               $abstractWidgetController = $this->getAccessibleMock('Tx_Fluid_Core_Widget_AbstractWidgetController', array('dummy'));
+               $abstractWidgetController->injectConfigurationManager($configurationManager);
+               $abstractWidgetController->_set('request', $request);
+               $abstractWidgetController->_call('setViewConfiguration', $view);
+               $this->assertEquals(t3lib_div::getFileAbsFileName('EXT:fluid/Resources/Private/DummyTestTemplates'), $view->_call('getTemplateRootPath'));
+       }
 }
 ?>
\ No newline at end of file