diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-59505-UseFallbacksForAbstractWidgetControllerView-configuration.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-59505-UseFallbacksForAbstractWidgetControllerView-configuration.rst deleted file mode 100644 index 92045c42feeddf8f45b73d508d9c092154f901e3..0000000000000000000000000000000000000000 --- a/typo3/sysext/core/Documentation/Changelog/master/Breaking-59505-UseFallbacksForAbstractWidgetControllerView-configuration.rst +++ /dev/null @@ -1,39 +0,0 @@ -================================================================================ -Breaking: #59505 - Use fallbacks for AbstractWidgetController view-configuration -================================================================================ - -Description -=========== - -The ``AbstractWidgetController`` is now capable of view fallbacks. This it is using the existing functionality of Extbase controllers. - - -Impact -====== - -Paths to templates, layouts and partials specified in the old syntax do not work anymore. - -Old syntax: - -.. code-block:: typoscript - - plugin.tx_ext.settings.view.widget.widgetName.templateRootPath = some/path/Template.html - - -Affected Installations -====================== - -Any installation using third party extensions including wizards - - -Migration -========= - -Specifying paths for layouts, templates and partials must now use the array syntax. - -New syntax: - -.. code-block:: typoscript - - plugin.tx_ext.settings.view.widget.widgetName.templateRootPaths.10 = some/path/Template.html - diff --git a/typo3/sysext/fluid/Classes/Core/Widget/AbstractWidgetController.php b/typo3/sysext/fluid/Classes/Core/Widget/AbstractWidgetController.php index 0b422d9352c4ab97fd54c9a21f3a56906cea7602..f7620bb99b2792f2ce4fae5a4c8a1f6ed0383576 100644 --- a/typo3/sysext/fluid/Classes/Core/Widget/AbstractWidgetController.php +++ b/typo3/sysext/fluid/Classes/Core/Widget/AbstractWidgetController.php @@ -20,14 +20,6 @@ namespace TYPO3\CMS\Fluid\Core\Widget; * * * The TYPO3 project - inspiring people to share! * * */ - -use TYPO3\CMS\Core\SingletonInterface; -use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; -use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; -use TYPO3\CMS\Extbase\Mvc\RequestInterface; -use TYPO3\CMS\Extbase\Mvc\ResponseInterface; -use TYPO3\CMS\Extbase\Mvc\View\ViewInterface; - /** * This is the base class for all widget controllers. * Basically, it is an ActionController, and it additionally @@ -35,12 +27,12 @@ use TYPO3\CMS\Extbase\Mvc\View\ViewInterface; * * @api */ -abstract class AbstractWidgetController extends ActionController implements SingletonInterface { +abstract class AbstractWidgetController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController implements \TYPO3\CMS\Core\SingletonInterface { /** * @var array */ - protected $supportedRequestTypes = array(WidgetRequest::class); + protected $supportedRequestTypes = array(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class); /** * Configuration for this widget. @@ -53,38 +45,32 @@ abstract class AbstractWidgetController extends ActionController implements Sing /** * Handles a request. The result output is returned by altering the given response. * - * @param RequestInterface $request The request object - * @param ResponseInterface $response The response, modified by this handler + * @param \TYPO3\CMS\Extbase\Mvc\RequestInterface $request The request object + * @param \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response The response, modified by this handler * @return void * @api */ - public function processRequest(RequestInterface $request, ResponseInterface $response) { - if ($request instanceof WidgetRequest) { - $this->widgetConfiguration = $request->getWidgetContext()->getWidgetConfiguration(); - } + public function processRequest(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response) { + $this->widgetConfiguration = $request->getWidgetContext()->getWidgetConfiguration(); parent::processRequest($request, $response); } /** - * Allows the widget template root path to be overridden via the framework configuration, - * e.g. plugin.tx_extension.view.widget.<WidgetViewHelperClassName>.templateRootPaths + * Allows the widget template root path to be overriden via the framework configuration, + * e.g. plugin.tx_extension.view.widget.<WidgetViewHelperClassName>.templateRootPath * - * @param ViewInterface $view + * @param \TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view * @return void */ - protected function setViewConfiguration(ViewInterface $view) { - if ($this->request instanceof WidgetRequest) { - $extbaseFrameworkConfiguration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, $this->extensionName); - $widgetViewHelperClassName = $this->request->getWidgetContext()->getWidgetViewHelperClassName(); - if (isset($extbaseFrameworkConfiguration['view']['widget'][$widgetViewHelperClassName])) { - $configurationOverridden = $extbaseFrameworkConfiguration; - $configurationOverridden['view'] = array_replace_recursive($configurationOverridden['view'], $configurationOverridden['view']['widget'][$widgetViewHelperClassName]); - $this->configurationManager->setConfiguration($configurationOverridden); - parent::setViewConfiguration($view); - $this->configurationManager->setConfiguration($extbaseFrameworkConfiguration); - } else { - parent::setViewConfiguration($view); - } + protected function setViewConfiguration(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view) { + $extbaseFrameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK); + $widgetViewHelperClassName = $this->request->getWidgetContext()->getWidgetViewHelperClassName(); + if ( + isset($extbaseFrameworkConfiguration['view']['widget'][$widgetViewHelperClassName]['templateRootPath']) + && $extbaseFrameworkConfiguration['view']['widget'][$widgetViewHelperClassName]['templateRootPath'] !== '' + && method_exists($view, 'setTemplateRootPath') + ) { + $view->setTemplateRootPath(\TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($extbaseFrameworkConfiguration['view']['widget'][$widgetViewHelperClassName]['templateRootPath'])); } } diff --git a/typo3/sysext/fluid/Tests/Unit/Core/Widget/AbstractWidgetControllerTest.php b/typo3/sysext/fluid/Tests/Unit/Core/Widget/AbstractWidgetControllerTest.php index 9438cf03b775fb472b3138683485e72aa152d4ef..b9a873e8f1428446413807c51a4cc29563a998f2 100644 --- a/typo3/sysext/fluid/Tests/Unit/Core/Widget/AbstractWidgetControllerTest.php +++ b/typo3/sysext/fluid/Tests/Unit/Core/Widget/AbstractWidgetControllerTest.php @@ -21,34 +21,25 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\Core\Widget; * The TYPO3 project - inspiring people to share! * * */ -use TYPO3\CMS\Core\Tests\UnitTestCase; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Extbase\Configuration\ConfigurationManager; use TYPO3\CMS\Extbase\Mvc\Controller\Arguments; -use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext; -use TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService; use TYPO3\CMS\Extbase\Mvc\ResponseInterface; -use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder; -use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; use TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController; -use TYPO3\CMS\Fluid\Core\Widget\WidgetContext; use TYPO3\CMS\Fluid\Core\Widget\WidgetRequest; -use TYPO3\CMS\Fluid\View\TemplateView; -use TYPO3\CMS\Fluid\ViewHelpers\Widget\PaginateViewHelper; /** * Test case */ -class AbstractWidgetControllerTest extends UnitTestCase { +class AbstractWidgetControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { /** * @test */ public function canHandleWidgetRequest() { /** @var WidgetRequest|\PHPUnit_Framework_MockObject_MockObject $request */ - $request = $this->getMock(WidgetRequest::class, array('dummy'), array(), '', FALSE); + $request = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class, array('dummy'), array(), '', FALSE); /** @var AbstractWidgetController|\PHPUnit_Framework_MockObject_MockObject $abstractWidgetController */ - $abstractWidgetController = $this->getMock(AbstractWidgetController::class, array('dummy'), array(), '', FALSE); + $abstractWidgetController = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController::class, array('dummy'), array(), '', FALSE); $this->assertTrue($abstractWidgetController->canProcessRequest($request)); } @@ -56,20 +47,20 @@ class AbstractWidgetControllerTest extends UnitTestCase { * @test */ public function processRequestSetsWidgetConfiguration() { - $widgetContext = $this->getMock(WidgetContext::class); + $widgetContext = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetContext::class); $widgetContext->expects($this->once())->method('getWidgetConfiguration')->will($this->returnValue('myConfiguration')); /** @var WidgetRequest|\PHPUnit_Framework_MockObject_MockObject $request */ - $request = $this->getMock(WidgetRequest::class, array(), array(), '', FALSE); + $request = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class, array(), array(), '', FALSE); $request->expects($this->once())->method('getWidgetContext')->will($this->returnValue($widgetContext)); /** @var ResponseInterface|\PHPUnit_Framework_MockObject_MockObject $response */ - $response = $this->getMock(ResponseInterface::class); + $response = $this->getMock(\TYPO3\CMS\Extbase\Mvc\ResponseInterface::class); /** @var AbstractWidgetController|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $abstractWidgetController */ - $abstractWidgetController = $this->getAccessibleMock(AbstractWidgetController::class, array('resolveActionMethodName', 'initializeActionMethodArguments', 'initializeActionMethodValidators', 'initializeAction', 'checkRequestHash', 'mapRequestArgumentsToControllerArguments', 'buildControllerContext', 'resolveView', 'callActionMethod'), array(), '', FALSE); - $mockUriBuilder = $this->getMock(UriBuilder::class); - $objectManager = $this->getMock(ObjectManagerInterface::class); - $objectManager->expects($this->any())->method('get')->with(UriBuilder::class)->will($this->returnValue($mockUriBuilder)); + $abstractWidgetController = $this->getAccessibleMock(\TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController::class, array('resolveActionMethodName', 'initializeActionMethodArguments', 'initializeActionMethodValidators', 'initializeAction', 'checkRequestHash', 'mapRequestArgumentsToControllerArguments', 'buildControllerContext', 'resolveView', 'callActionMethod'), array(), '', FALSE); + $mockUriBuilder = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder::class); + $objectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class); + $objectManager->expects($this->any())->method('get')->with(\TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder::class)->will($this->returnValue($mockUriBuilder)); - $configurationService = $this->getMock(MvcPropertyMappingConfigurationService::class); + $configurationService = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService::class); $abstractWidgetController->_set('mvcPropertyMappingConfigurationService', $configurationService); $abstractWidgetController->_set('arguments', new Arguments()); @@ -86,39 +77,24 @@ class AbstractWidgetControllerTest extends UnitTestCase { $frameworkConfiguration = array( 'view' => array( 'widget' => array( - PaginateViewHelper::class => array( - 'templateRootPath' => 'EXT:fluid/Resources/Private', - 'templateRootPaths' => ['EXT:fluid/Resources/Private'] + \TYPO3\CMS\Fluid\ViewHelpers\Widget\PaginateViewHelper::class => array( + 'templateRootPath' => 'EXT:fluid/Resources/Private/DummyTestTemplates' ) ) ) ); - $overriddenConfiguration['view'] = array_merge_recursive($frameworkConfiguration['view'], $frameworkConfiguration['view']['widget'][PaginateViewHelper::class]); - - $widgetContext = $this->getMock(WidgetContext::class); - $widgetContext->expects($this->any())->method('getWidgetViewHelperClassName')->will($this->returnValue(PaginateViewHelper::class)); - - $request = $this->getMock(WidgetRequest::class, array(), array(), '', FALSE); + $widgetContext = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetContext::class); + $widgetContext->expects($this->any())->method('getWidgetViewHelperClassName')->will($this->returnValue(\TYPO3\CMS\Fluid\ViewHelpers\Widget\PaginateViewHelper::class)); + $request = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class, array(), array(), '', FALSE); $request->expects($this->any())->method('getWidgetContext')->will($this->returnValue($widgetContext)); - $request->expects($this->any())->method('getControllerExtensionKey')->will($this->returnValue('fluid')); - - $configurationManager = $this->getMock(ConfigurationManager::class); - $configurationManager->expects($this->at(1))->method('setConfiguration')->with($overriddenConfiguration); - $configurationManager->expects($this->any())->method('getConfiguration')->willReturnOnConsecutiveCalls($this->returnValue($frameworkConfiguration), $this->returnValue($overriddenConfiguration)); - - $controllerContext = $this->getMock(ControllerContext::class); - $controllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($request)); - - /** @var TemplateView|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $view */ - $view = $this->getAccessibleMock(TemplateView::class, array('dummy'), array(), '', FALSE); - $view->_set('controllerContext', $controllerContext); - - $abstractWidgetController = $this->getAccessibleMock(AbstractWidgetController::class, array('dummy')); + $configurationManager = $this->getMock(\TYPO3\CMS\Extbase\Configuration\ConfigurationManager::class); + $configurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($frameworkConfiguration)); + $view = $this->getAccessibleMock(\TYPO3\CMS\Fluid\View\TemplateView::class, array('dummy'), array(), '', FALSE); + $abstractWidgetController = $this->getAccessibleMock(\TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController::class, array('dummy')); $abstractWidgetController->_set('configurationManager', $configurationManager); $abstractWidgetController->_set('request', $request); - $abstractWidgetController->_set('controllerContext', $controllerContext); $abstractWidgetController->_call('setViewConfiguration', $view); - $this->assertSame(array('EXT:fluid/Resources/Private'), $view->_call('getTemplateRootPaths')); + $this->assertSame(array(GeneralUtility::getFileAbsFileName('EXT:fluid/Resources/Private/DummyTestTemplates')), $view->_call('getTemplateRootPaths')); } }