[+FEATURE] Fluid (Widgets): Allow overriding templateRootPath
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / Core / Widget / AbstractWidgetController.php
1 <?php
2
3 /*
4 * This script belongs to the FLOW3 package "Fluid". *
5 * *
6 * It is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU Lesser General Public License as published by the *
8 * Free Software Foundation, either version 3 of the License, or (at your *
9 * option) any later version. *
10 * *
11 * This script is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with the script. *
18 * If not, see http://www.gnu.org/licenses/lgpl.html *
19 * *
20 * The TYPO3 project - inspiring people to share! *
21 * */
22
23 /**
24 * This is the base class for all widget controllers.
25 * Basically, it is an ActionController, and it additionally
26 * has $this->widgetConfiguration set to the Configuration of the current Widget.
27 *
28 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
29 * @api
30 */
31 abstract class Tx_Fluid_Core_Widget_AbstractWidgetController extends Tx_Extbase_MVC_Controller_ActionController implements t3lib_Singleton {
32
33 /**
34 * @var array
35 */
36 protected $supportedRequestTypes = array('Tx_Fluid_Core_Widget_WidgetRequest');
37
38 /**
39 * Configuration for this widget.
40 *
41 * @var array
42 * @api
43 */
44 protected $widgetConfiguration;
45
46 /**
47 * Handles a request. The result output is returned by altering the given response.
48 *
49 * @param Tx_Extbase_MVC_RequestInterface $request The request object
50 * @param Tx_Extbase_MVC_ResponseInterface $response The response, modified by this handler
51 * @return void
52 * @api
53 */
54 public function processRequest(Tx_Extbase_MVC_RequestInterface $request, Tx_Extbase_MVC_ResponseInterface $response) {
55 $this->widgetConfiguration = $request->getWidgetContext()->getWidgetConfiguration();
56 parent::processRequest($request, $response);
57 }
58
59 /**
60 * Allows the widget template root path to be overriden via the framework configuration,
61 * e.g. plugin.tx_extension.view.widget.<WidgetViewHelperClassName>.templateRootPath
62 *
63 * @param Tx_Extbase_MVC_View_ViewInterface $view
64 * @return void
65 */
66 protected function setViewConfiguration(Tx_Extbase_MVC_View_ViewInterface $view) {
67 $extbaseFrameworkConfiguration = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
68 $widgetViewHelperClassName = $this->request->getWidgetContext()->getWidgetViewHelperClassName();
69
70 if (isset($extbaseFrameworkConfiguration['view']['widget'][$widgetViewHelperClassName]['templateRootPath'])
71 && strlen($extbaseFrameworkConfiguration['view']['widget'][$widgetViewHelperClassName]['templateRootPath']) > 0
72 && method_exists($view, 'setTemplateRootPath')) {
73 $view->setTemplateRootPath(t3lib_div::getFileAbsFileName($extbaseFrameworkConfiguration['view']['widget'][$widgetViewHelperClassName]['templateRootPath']));
74 }
75 }
76 }
77
78 ?>