98c190e1ea3b679e5ae345826854dc85e1454176
[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 // Flex ds was normalized in flex provider to always have a sheet.
44 // Determine this single sheet name, most often it ends up with sDEF, except if only one sheet was defined
45 $sheetName = array_pop(array_keys($flexFormDataStructureArray['sheets']));
46 $flexFormRowDataSubPart = $flexFormRowData['data'][$sheetName]['lDEF'] ?: [];
47
48 // That was taken from GeneralUtility::resolveSheetDefInDS - no idea if it is important
49 unset($flexFormDataStructureArray['meta']);
50
51 if (!is_array($flexFormDataStructureArray['sheets'][$sheetName]['ROOT']['el'])) {
52 $resultArray['html'] = 'Data Structure ERROR: No [\'ROOT\'][\'el\'] element found in flex form definition.';
53 return $resultArray;
54 }
55
56 // Assemble key for loading the correct CSH file
57 // @todo: what is that good for? That is for the title of single elements ... see FlexFormElementContainer!
58 $dsPointerFields = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['columns'][$fieldName]['config']['ds_pointerField'], true);
59 $parameterArray['_cshKey'] = $table . '.' . $fieldName;
60 foreach ($dsPointerFields as $key) {
61 if (is_string($row[$key]) && $row[$key] !== '') {
62 $parameterArray['_cshKey'] .= '.' . $row[$key];
63 } elseif (is_array($row[$key]) && isset($row[$key][0]) && is_string($row[$key][0]) && $row[$key][0] !== '') {
64 $parameterArray['_cshKey'] .= '.' . $row[$key][0];
65 }
66 }
67
68 $options = $this->data;
69 $options['flexFormDataStructureArray'] = $flexFormDataStructureArray['sheets'][$sheetName]['ROOT']['el'];
70 $options['flexFormRowData'] = $flexFormRowDataSubPart;
71 $options['flexFormFormPrefix'] = '[data][' . $sheetName . '][lDEF]';
72 $options['parameterArray'] = $parameterArray;
73
74 $options['renderType'] = 'flexFormElementContainer';
75 return $this->nodeFactory->create($options)->render();
76 }
77 }