[TASK] Streamline phpdoc annotations in EXT:fluid
[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 file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Fluid\View\TemplatePaths;
18
19 /**
20 * This is the base class for all widget controllers.
21 * It is basically an ActionController and additionally has $this->widgetConfiguration set to the
22 * Configuration of the current Widget.
23 */
24 abstract class AbstractWidgetController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController implements \TYPO3\CMS\Core\SingletonInterface
25 {
26 /**
27 * @var array
28 */
29 protected $supportedRequestTypes = [\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class];
30
31 /**
32 * Configuration for this widget.
33 *
34 * @var array
35 */
36 protected $widgetConfiguration;
37
38 /**
39 * Handles a request. The result output is returned by altering the given response.
40 *
41 * @param \TYPO3\CMS\Extbase\Mvc\RequestInterface $request The request object
42 * @param \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response The response, modified by this handler
43 */
44 public function processRequest(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response)
45 {
46 $this->widgetConfiguration = $request->getWidgetContext()->getWidgetConfiguration();
47 parent::processRequest($request, $response);
48 }
49
50 /**
51 * Allows the widget template root path to be overridden via the framework configuration,
52 * e.g. plugin.tx_extension.view.widget.<WidgetViewHelperClassName>.templateRootPath
53 *
54 * @param \TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view
55 */
56 protected function setViewConfiguration(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view)
57 {
58 $extbaseFrameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
59 $widgetViewHelperClassName = $this->request->getWidgetContext()->getWidgetViewHelperClassName();
60 $templatePaths = new TemplatePaths($this->controllerContext->getRequest()->getControllerExtensionKey());
61 $parentConfiguration = $view->getTemplatePaths()->toArray();
62 $rootConfiguration = $templatePaths->toArray();
63 $pluginConfiguration = $extbaseFrameworkConfiguration['view']['widget'][$widgetViewHelperClassName] ?? [];
64 if (isset($pluginConfiguration['templateRootPath']) && !isset($pluginConfiguration['templateRootPaths'])) {
65 $pluginConfiguration['templateRootPaths'][10] = $pluginConfiguration['templateRootPath'];
66 }
67 $widgetViewConfiguration = array_merge_recursive(
68 (array)$rootConfiguration,
69 (array)$parentConfiguration,
70 (array)$pluginConfiguration
71 );
72 $view->getTemplatePaths()->fillFromConfigurationArray($widgetViewConfiguration);
73 }
74 }