[BUGFIX] Use single postProcessor layout, otherwise the global layout
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / PostProcess / PostProcessor.php
1 <?php
2 namespace TYPO3\CMS\Form\PostProcess;
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\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Form\ObjectFactory;
19
20 /**
21 * The post processor
22 */
23 class PostProcessor {
24
25 /**
26 * @var \TYPO3\CMS\Form\View\Form\FormView
27 */
28 protected $form;
29
30 /**
31 * @var \TYPO3\CMS\Form\Domain\Factory\TypoScriptFactory
32 */
33 protected $typoscriptFactory;
34
35 /**
36 * Constructor
37 *
38 * @param \TYPO3\CMS\Form\Domain\Model\Form $form Form domain model
39 * @param array $typoScript Post processor TypoScript settings
40 */
41 public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $form, array $typoScript) {
42 $this->form = $form;
43 $this->typoscriptFactory = GeneralUtility::makeInstance(\TYPO3\CMS\Form\Domain\Factory\TypoScriptFactory::class);
44 $this->typoScript = $typoScript;
45 }
46
47 /**
48 * The main method called by the controller
49 *
50 * Iterates over the configured post processors and calls them with their
51 * own settings
52 *
53 * @return string HTML messages from the called processors
54 */
55 public function process() {
56 $html = '';
57 if (is_array($this->typoScript)) {
58 $keys = \TYPO3\CMS\Core\TypoScript\TemplateService::sortedKeyList($this->typoScript);
59
60 foreach ($keys as $key) {
61 if (!(int)$key || strpos($key, '.') !== FALSE) {
62 continue;
63 }
64 $className = FALSE;
65 $processorName = $this->typoScript[$key];
66 $processorArguments = array();
67 if (isset($this->typoScript[$key . '.'])) {
68 $processorArguments = $this->typoScript[$key . '.'];
69 }
70
71 if (isset($processorArguments['layout.'])) {
72 $layoutHandler = $this->typoscriptFactory->setLayoutHandler($processorArguments);
73 } else {
74 $layoutHandler = $this->typoscriptFactory->setLayoutHandler($this->typoScript);
75 }
76
77 if (class_exists($processorName, TRUE)) {
78 $className = $processorName;
79 } else {
80 $classNameExpanded = 'TYPO3\\CMS\\Form\\PostProcess\\' . ucfirst(strtolower($processorName)) . 'PostProcessor';
81 if (class_exists($classNameExpanded, TRUE)) {
82 $className = $classNameExpanded;
83 }
84 }
85 if ($className !== FALSE) {
86 $layout = $this->typoscriptFactory->getLayoutFromTypoScript($this->typoScript[$processorName . '.']);
87 $layoutHandler->setLayout($layout);
88
89 $processor = ObjectFactory::createFormObject($className, $this->form, $processorArguments);
90 if ($processor instanceof PostProcessorInterface) {
91 $html .= $processor->process();
92 }
93 }
94 }
95 }
96 return $html;
97 }
98
99 }