[TASK] Move verbosity settings into TemplateService
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / TypoScript / ConfigurationForm.php
1 <?php
2 namespace TYPO3\CMS\Core\TypoScript;
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\Context\Context;
18 use TYPO3\CMS\Core\Utility\ArrayUtility;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20
21 /**
22 * Provides a simplified layer for making Constant Editor style configuration forms
23 */
24 class ConfigurationForm extends ExtendedTemplateService
25 {
26 /**
27 * @var array
28 */
29 public $categories = [];
30
31 /**
32 * @var bool
33 */
34 public $ext_dontCheckIssetValues = 1;
35
36 /**
37 * @var string
38 */
39 public $ext_CEformName = 'tsStyleConfigForm';
40
41 /**
42 * @var bool
43 */
44 public $ext_printAll = true;
45
46 /**
47 * @var array
48 */
49 public $ext_incomingValues = [];
50
51 /**
52 * @var array
53 */
54 protected $ext_realValues = [];
55
56 /**
57 * @param Context|null $context
58 */
59 public function __construct(Context $context = null)
60 {
61 parent::__construct($context);
62 // Deprecate this class
63 trigger_error('Class ConfigurationForm has been deprecated with v9 and will be removed in v10', E_USER_DEPRECATED);
64 }
65 /**
66 * @param string $configTemplate
67 * @return array
68 */
69 public function ext_initTSstyleConfig($configTemplate)
70 {
71 // Do not log time-performance information
72 $this->tt_track = 0;
73 $this->constants = [$configTemplate, ''];
74 // The editable constants are returned in an array.
75 $theConstants = $this->generateConfig_constants();
76 return $theConstants;
77 }
78
79 /**
80 * Ext set value array
81 *
82 * @param array $theConstants
83 * @param array $valueArray
84 * @return array
85 */
86 public function ext_setValueArray($theConstants, $valueArray)
87 {
88 $temp = $this->flatSetup;
89 $this->flatSetup = [];
90 $this->flattenSetup($valueArray, '');
91 $this->objReg = $this->ext_realValues = $this->flatSetup;
92 $this->flatSetup = $temp;
93 foreach ($theConstants as $k => $p) {
94 if (isset($this->objReg[$k])) {
95 $theConstants[$k]['value'] = $this->ext_realValues[$k];
96 }
97 }
98 // Reset the default pool of categories.
99 $this->categories = [];
100 // The returned constants are sorted in categories, that goes into the $this->categories array
101 $this->ext_categorizeEditableConstants($theConstants);
102 return $theConstants;
103 }
104
105 /**
106 * @return array
107 */
108 public function ext_getCategoriesForModMenu()
109 {
110 return $this->ext_getCategoryLabelArray();
111 }
112
113 /**
114 * Get the form for extension configuration
115 *
116 * @param string $cat
117 * @param array $theConstants
118 * @param string $script
119 * @param string $addFields
120 * @param string $extKey
121 * @param bool $addFormTag Adds opening <form> tag to the output, if TRUE
122 * @return string The form
123 */
124 public function ext_getForm($cat, $theConstants, $script = '', $addFields = '', $extKey = '', $addFormTag = true)
125 {
126 $printFields = trim($this->ext_printFields($theConstants, $cat));
127 $content = '';
128 $content .= GeneralUtility::wrapJS('
129 function uFormUrl(aname) {
130 document.' . $this->ext_CEformName . '.action = ' . GeneralUtility::quoteJSvalue(GeneralUtility::linkThisScript() . '#') . '+aname;
131 }
132 ');
133 if ($addFormTag) {
134 $content .= '<form action="' . htmlspecialchars(($script ?: GeneralUtility::linkThisScript())) . '" name="' . $this->ext_CEformName . '" method="post" enctype="multipart/form-data">';
135 }
136 $content .= $addFields;
137 $content .= $printFields;
138 $content .= '<input class="btn btn-default" type="submit" name="submit" value="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_tsfe.xlf:update')) . '" id="configuration-submit-' . htmlspecialchars($extKey) . '" />';
139 return $content;
140 }
141
142 /**
143 * Merge incoming with existing
144 *
145 * @param array $arr
146 * @return array
147 */
148 public function ext_mergeIncomingWithExisting($arr)
149 {
150 $parseObj = GeneralUtility::makeInstance(Parser\TypoScriptParser::class);
151 $parseObj->parse(implode(LF, $this->ext_incomingValues));
152 $arr2 = $parseObj->setup;
153 ArrayUtility::mergeRecursiveWithOverrule($arr, $arr2);
154 return $arr;
155 }
156
157 /**
158 * @param array $params
159 * @return array
160 */
161 public function ext_fNandV($params)
162 {
163 $fN = 'data[' . $params['name'] . ']';
164 $idName = str_replace('.', '-', $params['name']);
165 $fV = ($params['value'] = $this->ext_realValues[$params['name']] ?? $params['default_value']);
166 $reg = [];
167 // Values entered from the constantsedit cannot be constants!
168 if (preg_match('/^\\{[\\$][a-zA-Z0-9\\.]*\\}$/', trim($fV), $reg)) {
169 $fV = '';
170 }
171 $fV = htmlspecialchars($fV);
172 return [$fN, $fV, $params, $idName];
173 }
174
175 /**
176 * @param string $key
177 * @param string $var
178 */
179 public function ext_putValueInConf($key, $var)
180 {
181 $this->ext_incomingValues[$key] = $key . '=' . $var;
182 }
183
184 /**
185 * @param string $key
186 */
187 public function ext_removeValueInConf($key)
188 {
189 }
190 }