[TASK] Remove old language labels in EXT:setup
[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\ArrayUtility;
18
19 /**
20 * The post processor
21 */
22 class PostProcessor extends AbstractPostProcessor
23 {
24 /**
25 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
26 */
27 protected $objectManager;
28
29 /**
30 * @var array
31 */
32 protected $postProcessorTypoScript;
33
34 /**
35 * @var \TYPO3\CMS\Form\Domain\Model\Element $form
36 */
37 protected $form;
38
39 /**
40 * @param \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager
41 * @return void
42 */
43 public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager)
44 {
45 $this->objectManager = $objectManager;
46 }
47
48 /**
49 * Constructor
50 *
51 * @param \TYPO3\CMS\Form\Domain\Model\Element $form
52 * @param array $postProcessorTypoScript Post processor TypoScript settings
53 */
54 public function __construct(\TYPO3\CMS\Form\Domain\Model\Element $form, array $postProcessorTypoScript)
55 {
56 $this->form = $form;
57 $this->postProcessorTypoScript = $postProcessorTypoScript;
58 }
59
60 /**
61 * The main method called by the controller
62 *
63 * Iterates over the configured post processors and calls them with their
64 * own settings
65 *
66 * @return string HTML messages from the called processors
67 */
68 public function process()
69 {
70 $html = '';
71
72 if (is_array($this->postProcessorTypoScript)) {
73 $keys = ArrayUtility::filterAndSortByNumericKeys($this->postProcessorTypoScript);
74
75 foreach ($keys as $key) {
76 if (!(int)$key || strpos($key, '.') !== false) {
77 continue;
78 }
79 $className = false;
80 $processorName = $this->postProcessorTypoScript[$key];
81 $processorArguments = [];
82 if (isset($this->postProcessorTypoScript[$key . '.'])) {
83 $processorArguments = $this->postProcessorTypoScript[$key . '.'];
84 }
85
86 if (class_exists($processorName, true)) {
87 $className = $processorName;
88 } else {
89 $classNameExpanded = 'TYPO3\\CMS\\Form\\PostProcess\\' . ucfirst(strtolower($processorName)) . 'PostProcessor';
90 if (class_exists($classNameExpanded, true)) {
91 $className = $classNameExpanded;
92 }
93 }
94 if ($className !== false) {
95 $processor = $this->objectManager->get($className, $this->form, $processorArguments);
96 if ($processor instanceof PostProcessorInterface) {
97 $processor->setControllerContext($this->controllerContext);
98 $html .= $processor->process();
99 }
100 }
101 }
102 }
103
104 return $html;
105 }
106 }