[!!!][TASK] Use fallbacks for AbstractWidgetController view-configuration
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / Core / Widget / AbstractWidgetController.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Core\Widget;
3
4 /*
5 * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * *
12 * This script is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15 * General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with the script. *
19 * If not, see http://www.gnu.org/licenses/lgpl.html *
20 * *
21 * The TYPO3 project - inspiring people to share! *
22 * */
23
24 use TYPO3\CMS\Core\SingletonInterface;
25 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
26 use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
27 use TYPO3\CMS\Extbase\Mvc\RequestInterface;
28 use TYPO3\CMS\Extbase\Mvc\ResponseInterface;
29 use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
30
31 /**
32 * This is the base class for all widget controllers.
33 * Basically, it is an ActionController, and it additionally
34 * has $this->widgetConfiguration set to the Configuration of the current Widget.
35 *
36 * @api
37 */
38 abstract class AbstractWidgetController extends ActionController implements SingletonInterface {
39
40 /**
41 * @var array
42 */
43 protected $supportedRequestTypes = array(WidgetRequest::class);
44
45 /**
46 * Configuration for this widget.
47 *
48 * @var array
49 * @api
50 */
51 protected $widgetConfiguration;
52
53 /**
54 * Handles a request. The result output is returned by altering the given response.
55 *
56 * @param RequestInterface $request The request object
57 * @param ResponseInterface $response The response, modified by this handler
58 * @return void
59 * @api
60 */
61 public function processRequest(RequestInterface $request, ResponseInterface $response) {
62 if ($request instanceof WidgetRequest) {
63 $this->widgetConfiguration = $request->getWidgetContext()->getWidgetConfiguration();
64 }
65 parent::processRequest($request, $response);
66 }
67
68 /**
69 * Allows the widget template root path to be overridden via the framework configuration,
70 * e.g. plugin.tx_extension.view.widget.<WidgetViewHelperClassName>.templateRootPaths
71 *
72 * @param ViewInterface $view
73 * @return void
74 */
75 protected function setViewConfiguration(ViewInterface $view) {
76 if ($this->request instanceof WidgetRequest) {
77 $extbaseFrameworkConfiguration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, $this->extensionName);
78 $widgetViewHelperClassName = $this->request->getWidgetContext()->getWidgetViewHelperClassName();
79 if (isset($extbaseFrameworkConfiguration['view']['widget'][$widgetViewHelperClassName])) {
80 $configurationOverridden = $extbaseFrameworkConfiguration;
81 $configurationOverridden['view'] = array_replace_recursive($configurationOverridden['view'], $configurationOverridden['view']['widget'][$widgetViewHelperClassName]);
82 $this->configurationManager->setConfiguration($configurationOverridden);
83 parent::setViewConfiguration($view);
84 $this->configurationManager->setConfiguration($extbaseFrameworkConfiguration);
85 } else {
86 parent::setViewConfiguration($view);
87 }
88 }
89 }
90
91 }