‪TYPO3CMS  10.4
FormDataCompiler.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
19 
25 {
31  protected ‪$formDataGroup;
32 
40  ];
41 
48  {
49  $this->formDataGroup = ‪$formDataGroup;
50  }
51 
61  public function ‪compile(array $initialData)
62  {
63  $result = $this->‪initializeResultArray();
64 
65  // There must be only keys that actually exist in result data.
66  $keysNotInResult = array_diff(array_keys($initialData), array_keys($result));
67  if (!empty($keysNotInResult)) {
68  throw new \InvalidArgumentException(
69  'Array keys ' . implode(',', $keysNotInResult) . ' do not exist in result array and can not be set',
70  1440601540
71  );
72  }
73 
74  foreach ($initialData as $dataKey => $dataValue) {
75  if ($dataKey === 'command') {
76  // Sanitize $command
77  if ($dataValue !== 'edit' && $dataValue !== 'new') {
78  throw new \InvalidArgumentException('Command must be either "edit" or "new"', 1437653136);
79  }
80  }
81  if ($dataKey === 'tableName') {
82  // Sanitize $tableName
83  if (empty($dataValue)) {
84  throw new \InvalidArgumentException('No $tableName given', 1437654409);
85  }
86  }
87  if ($dataKey === 'vanillaUid') {
88  if (!‪MathUtility::canBeInterpretedAsInteger($dataValue) && strpos($dataValue, 'NEW') !== 0) {
89  throw new \InvalidArgumentException('$vanillaUid is not an integer or "NEW..." string ID', 1437654247);
90  }
91  if (isset($initialData['command']) && $initialData['command'] === 'edit' && $dataValue < 0) {
92  throw new \InvalidArgumentException('Negative $vanillaUid is not supported with $command="edit', 1437654332);
93  }
94  }
95  $result[$dataKey] = $dataValue;
96  }
97 
98  // Call the data group provider but take care it does not add or remove result keys
99  // This is basically a safety measure against data providers colliding with our array "contract"
100  $resultKeysBeforeFormDataGroup = array_keys($result);
101 
102  $result = $this->formDataGroup->compile($result);
103 
104  if (!is_array($result)) {
105  throw new \UnexpectedValueException(
106  'Data group provider must return array',
107  1446664764
108  );
109  }
110 
111  if (!empty($result['renderData'])) {
112  throw new \RuntimeException(
113  'Array \'renderData\' not empty. Data providers must not add data here',
114  1485201279
115  );
116  }
117 
118  $resultKeysAfterFormDataGroup = array_keys($result);
119 
120  if ($resultKeysAfterFormDataGroup !== $resultKeysBeforeFormDataGroup) {
121  throw new \UnexpectedValueException(
122  'Data group provider must not change result key list',
123  1438079402
124  );
125  }
126 
127  // Remove some data elements form result that are data provider internal and should
128  // not be exposed to calling object.
129  foreach ($this->removeKeysFromFinalResultArray as $key) {
130  unset($result[$key]);
131  }
132 
133  return $result;
134  }
135 
139  protected function ‪initializeResultArray()
140  {
141  return [
142  // Either "edit" or "new"
143  'command' => '',
144  // Table name of the handled row
145  'tableName' => '',
146  // Not changed uid of the record, meaning of value depends on context (new / edit)
147  // * If $command is "edit"
148  // ** $vanillaUid is a positive integer > 0 pointing to the record in the table
149  // * If $command is "new":
150  // ** If $vanillaUid > 0, it is the uid of a page the record should be added at
151  // ** If $vanillaUid < 0, it is the uid of a record in the same table after which the new record should be added
152  // ** If $vanillaUid = 0, a new record is added on page 0
153  // ** If $vanillaUid = "NEW..." Id of a parent page record if an inline child is added to a not yet persisted page
154  'vanillaUid' => 0,
155  // Url to return to
156  'returnUrl' => null,
157  // Title of the handled record.
158  'recordTitle' => '',
159  // Parent page record is either the full row of the parent page the record is located at or should
160  // be added to, or it is NULL, if a record is added or edited below the root page node.
161  'parentPageRow' => null,
162  // If a translated page is handled, the page row of the default language (the page against all page checks
163  // are made) is set here
164  'defaultLanguagePageRow' => null,
165  // Holds the "neighbor" row if incoming vanillaUid is negative and record creation is relative to a row of the same table.
166  'neighborRow' => null,
167  // For "new" this is the fully initialized row with defaults
168  // The database row. For "edit" fixVersioningPid() was applied already.
169  // @todo: rename to valueStructure or handledData or similar
170  'databaseRow' => [],
171  // The "effective" page uid we're working on. This is the uid of a page if a page is edited, or the uid
172  // of the parent page if a page or other record is added, or 0 if a record is added or edited below root node.
173  'effectivePid' => 0,
174  // Rootline of page the record that is handled is located at as created by BackendUtility::BEgetRootline()
175  'rootline' => [],
176  // The resolved SiteInterface object of the page or page given record is located on.
177  'site' => null,
178  // For "edit", this is the permission bitmask of the page that is edited, or of the page a record is located at
179  // For "new", this is the permission bitmask of the page the record is added to
180  // @todo: Remove if not needed on a lower level
181  'userPermissionOnPage' => 0,
182  // Full user TsConfig
183  'userTsConfig' => [],
184  // Full page TSConfig of the page that is edited or of the parent page if a record is added.
185  // This includes any defaultPageTSconfig and is merged with user TsConfig page. section. After type
186  // of handled record was determined, record type specific settings [TCEFORM.][tableName.][field.][types.][type.]
187  // are merged into [TCEFORM.][tableName.][field.]. Array keys still contain the concatenation dots.
188  'pageTsConfig' => [],
189  // List of available system languages. Array key is the system language uid, value array
190  // contains details of the record, with iso code resolved. Key is the sys_language_uid uid.
191  'systemLanguageRows' => [],
192  // If the page that is handled has "page_language_overlay" records (page has localizations in
193  // different languages), then this array holds those rows.
194  'pageLanguageOverlayRows' => [],
195  // If the handled row is a localized row, this entry hold the default language row array
196  'defaultLanguageRow' => null,
197  // If the handled row is a localized row and $TCA[<tableName>]['ctrl']['translationSource'] is configured,
198  // This entry holds the row of the language source record.
199  'sourceLanguageRow' => null,
200  // If the handled row is a localized row and a transOrigDiffSourceField is defined, this
201  // is the unserialized version of it. The diff source field is basically a shadow version
202  // of the default language record at the time when the language overlay record was created.
203  // This is used later to compare the default record with this content to show a "diff" if
204  // the default language record changed meanwhile.
205  'defaultLanguageDiffRow' => null,
206  // With userTS options.additionalPreviewLanguages set, field values of additional languages
207  // can be shown. This array holds those additional language records, Array key is sys_language_uid.
208  'additionalLanguageRows' => [],
209  // The tca record type value of the record. Forced to string, there can be "named" type values.
210  'recordTypeValue' => '',
211  // TCA of table with processed fields. After processing, this array contains merged and resolved
212  // array data, items were resolved, only used types are set, renderTypes are set.
213  'processedTca' => [],
214  // List of columns to be processed by data provider. Array value is the column name.
215  'columnsToProcess' => [],
216  // If set to TRUE, no wizards are calculated and rendered later
217  'disabledWizards' => false,
218 
219  // Flex form field data handling is done in a separated FormDataCompiler instance. The full databaseRow
220  // of the record this flex form is embedded in is transferred in case features like single fields
221  // itemsProcFunc need to have this data at hand to do their job.
222  'flexParentDatabaseRow' => [],
223  // If not empty, it tells the TcaFlexProcess data provider to not calculate existing flex fields and
224  // existing flex container sections, but to instead prepare field values and the data structure TCA
225  // for a new container section. This is used by FormFlexAjaxController, the array contains details
226  // which container of which flex field should be created.
227  'flexSectionContainerPreparation' => [],
228 
229  // If true, TcaSelectTreeItems data provider will compile tree items. This is false by default since
230  // on opening a record items are not calculated but are fetch in an ajax request, see FormSelectTreeAjaxController.
231  'selectTreeCompileItems' => false,
232 
233  // BackendUser->uc['inlineView'] - This array holds status of expand / collapsed inline items
234  // This array is "flat", an inline structure with parent uid 1 having firstChild uid 2 having secondChild uid 3
235  // firstChild and secondChild are not nested. If a uid is set it means "record is expanded", example:
236  // 'parent' => [
237  // 1 => [
238  // 'firstChild' => [ 2 ], // record 2 of firstChild table is open in inline context to parent 1
239  // 'secondChild' => [ 3 ], // record 3 of secondChild table is open in inline context to parent 1
240  // ],
241  // ]
242  'inlineExpandCollapseStateArray' => [],
243  // The "entry" pid for inline records. Nested inline records can potentially hang around on different
244  // pid's, but the entry pid is needed for AJAX calls, so that they would know where the action takes
245  // place on the page structure. This is usually an int, but can be a "NEW..." string if an inline relation
246  // is added to a currently being created page.
247  'inlineFirstPid' => null,
248  // The "config" section of an inline parent, prepared and sanitized by TcaInlineConfiguration provider
249  'inlineParentConfig' => [],
250  // Flag that is enabled if a records is child of an inline parent
251  'isInlineChild' => false,
252  // Flag if an inline child is expanded so that additional fields need to be rendered
253  'isInlineChildExpanded' => false,
254  // Flag if the inline is in an ajax context that wants to expand the element
255  'isInlineAjaxOpeningContext' => false,
256  // Uid of the direct parent of the inline element. Handled as string since it may be a "NEW123" string
257  'inlineParentUid' => '',
258  // Table name of the direct parent of the inline element
259  'inlineParentTableName' => '',
260  // Field name of the direct parent of the inline element
261  'inlineParentFieldName' => '',
262  // Uid of the top most parent element. Handled as string since it may be a "NEW123" string
263  'inlineTopMostParentUid' => '',
264  // Table name of the top most parent element
265  'inlineTopMostParentTableName' => '',
266  // Field name of the top most parent element
267  'inlineTopMostParentFieldName' => '',
268 
269  // If is on symmetric side of an inline child parent reference.
270  // symmetric side can be achieved in case of an mm relation to the same table. If record A has a relation
271  // to record B, the symmetric side is set in case that record B gets edited.
272  // Record A (table1) <=> mm <=> Record B (table1)
273  'isOnSymmetricSide' => false,
274 
275  // Uid of a "child-child" if a new record of an intermediate table is compiled to an existing child. This
276  // happens if foreign_selector in parent inline config is set. It will be used by default database row
277  // data providers to set this as value for the foreign_selector field on the intermediate table. One use
278  // case is FAL, where for instance a tt_content parent adds relation to an existing sys_file record and
279  // should set the uid of the existing sys_file record as uid_local - the foreign_selector of this inline
280  // configuration - of the new intermediate sys_file_reference record. Data provider that are called later
281  // will then use this relation to resolve for instance input placeholder relation values.
282  'inlineChildChildUid' => null,
283  // Inline scenario: A localized parent record is handled, so inline parents can have localized children.
284  // This value is set to TRUE if this array represents a default language
285  // child record that was not yet localized.
286  'isInlineDefaultLanguageRecordInLocalizedParentContext' => false,
287  // If set, inline children will be resolved. This is set to FALSE in inline ajax context where new children
288  // are created and existing children don't matter much.
289  'inlineResolveExistingChildren' => true,
290  // @todo - for input placeholder inline to suppress an infinite loop, this *may* become obsolete if
291  // @todo compilation of certain fields is possible
292  'inlineCompileExistingChildren' => true,
293 
294  // @todo: keys below must be handled / further defined
295  'elementBaseName' => '',
296  'tabAndInlineStack' => [],
297  'inlineData' => [],
298  'inlineStructure' => [],
299 
300  // This array of fields will be set as hidden-fields instead of rendered normally!
301  // This is used by EditDocumentController to force some field values if set as "overrideVals" in _GP
302  'overrideValues' => [],
303  // Default values for fields. This is for example used in DatabaseRowInitializeNew data provider to set
304  // fields to specific values if new records are created. Values are often carried around as "defVals" GET
305  // parameters and hand over by controllers to FormEngine using this array. Array structure is
306  // ['aTableName']['aFieldName'] = 'aValue'.
307  'defaultValues' => [],
308 
309  // This array must NOT be set / manipulated by data providers but is instead used by the render part
310  // of FormEngine to add runtime data. Containers and elements add data here which is given to
311  // sub-containers, elements, controls and wizards.
312  'renderData' => [],
313 
314  // A place for non-core, additional, custom data providers to add data. If a data provider needs to add
315  // additional data to the data array that doesn't fit elsewhere, it can place it here to use it in the
316  // render part again. Data in here should be namespaced in a way that it does not collide with other
317  // data providers adding further data here. Using the extension key as array key could be a good idea.
318  'customData' => [],
319  ];
320  }
321 }
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger($var)
Definition: MathUtility.php:74
‪TYPO3\CMS\Backend\Form
Definition: AbstractNode.php:18
‪TYPO3\CMS\Backend\Form\FormDataCompiler\compile
‪array compile(array $initialData)
Definition: FormDataCompiler.php:59
‪TYPO3\CMS\Backend\Form\FormDataCompiler\__construct
‪__construct(FormDataGroupInterface $formDataGroup)
Definition: FormDataCompiler.php:45
‪TYPO3\CMS\Backend\Form\FormDataCompiler\$formDataGroup
‪FormDataGroupInterface $formDataGroup
Definition: FormDataCompiler.php:30
‪TYPO3\CMS\Backend\Form\FormDataCompiler\$removeKeysFromFinalResultArray
‪array $removeKeysFromFinalResultArray
Definition: FormDataCompiler.php:37
‪TYPO3\CMS\Backend\Form\FormDataCompiler\initializeResultArray
‪array initializeResultArray()
Definition: FormDataCompiler.php:137
‪TYPO3\CMS\Backend\Form\FormDataGroupInterface
Definition: FormDataGroupInterface.php:23
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Backend\Form\FormDataCompiler
Definition: FormDataCompiler.php:25