[!!!][TASK] Improve flex and TCA handling in FormEngine
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / Container / FlexFormNoTabsContainer.php
1 <?php
2 namespace TYPO3\CMS\Backend\Form\Container;
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
19 /**
20 * Handle a flex form that has no tabs.
21 *
22 * This container is called by FlexFormEntryContainer if only a default sheet
23 * exists. It evaluates the display condition and hands over rendering of single
24 * fields to FlexFormElementContainer.
25 */
26 class FlexFormNoTabsContainer extends AbstractContainer
27 {
28 /**
29 * Entry method
30 *
31 * @return array As defined in initializeResultArray() of AbstractNode
32 */
33 public function render()
34 {
35 $table = $this->data['tableName'];
36 $row = $this->data['databaseRow'];
37 $fieldName = $this->data['fieldName']; // field name of the flex form field in DB
38 $parameterArray = $this->data['parameterArray'];
39 $flexFormDataStructureArray = $this->data['flexFormDataStructureArray'];
40 $flexFormRowData = $this->data['flexFormRowData'];
41 $resultArray = $this->initializeResultArray();
42
43 // Determine this single sheet name, most often it ends up with sDEF, except if only one sheet was defined
44 $sheetName = array_pop(array_keys($flexFormDataStructureArray['sheets']));
45 $flexFormRowDataSubPart = $flexFormRowData['data'][$sheetName]['lDEF'] ?: [];
46
47 // That was taken from GeneralUtility::resolveSheetDefInDS - no idea if it is important
48 unset($flexFormDataStructureArray['meta']);
49
50 if (!is_array($flexFormDataStructureArray['sheets'][$sheetName]['ROOT']['el'])) {
51 $resultArray['html'] = 'Data Structure ERROR: No [\'ROOT\'][\'el\'] element found in flex form definition.';
52 return $resultArray;
53 }
54
55 // Assemble key for loading the correct CSH file
56 // @todo: what is that good for? That is for the title of single elements ... see FlexFormElementContainer!
57 $dsPointerFields = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['columns'][$fieldName]['config']['ds_pointerField'], true);
58 $parameterArray['_cshKey'] = $table . '.' . $fieldName;
59 foreach ($dsPointerFields as $key) {
60 if (is_string($row[$key]) && $row[$key] !== '') {
61 $parameterArray['_cshKey'] .= '.' . $row[$key];
62 } elseif (is_array($row[$key]) && isset($row[$key][0]) && is_string($row[$key][0]) && $row[$key][0] !== '') {
63 $parameterArray['_cshKey'] .= '.' . $row[$key][0];
64 }
65 }
66
67 $options = $this->data;
68 $options['flexFormDataStructureArray'] = $flexFormDataStructureArray['sheets'][$sheetName]['ROOT']['el'];
69 $options['flexFormRowData'] = $flexFormRowDataSubPart;
70 $options['flexFormSheetName'] = $sheetName;
71 $options['flexFormFormPrefix'] = '[data][' . $sheetName . '][lDEF]';
72 $options['parameterArray'] = $parameterArray;
73
74 $options['renderType'] = 'flexFormElementContainer';
75 return $this->nodeFactory->create($options)->render();
76 }
77 }