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