d03cca68b4ea3e3327feac9fe23950d147db835d
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / Container / FlexFormTabsContainer.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 use TYPO3\CMS\Lang\LanguageService;
19
20 /**
21 * Handle flex forms that have tabs (multiple "sheets").
22 *
23 * This container is called by FlexFormEntryContainer. It resolves each
24 * sheet and hands rendering of single sheet content over to FlexFormElementContainer.
25 */
26 class FlexFormTabsContainer extends AbstractContainer
27 {
28 /**
29 * Entry method
30 *
31 * @return array As defined in initializeResultArray() of AbstractNode
32 */
33 public function render()
34 {
35 $languageService = $this->getLanguageService();
36
37 $table = $this->data['tableName'];
38 $row = $this->data['databaseRow'];
39 $fieldName = $this->data['fieldName']; // field name of the flex form field in DB
40 $parameterArray = $this->data['parameterArray'];
41 $flexFormDataStructureArray = $this->data['flexFormDataStructureArray'];
42 $flexFormRowData = $this->data['flexFormRowData'];
43
44 $resultArray = $this->initializeResultArray();
45 $resultArray['requireJsModules'][] = 'TYPO3/CMS/Backend/Tabs';
46
47 $domIdPrefix = 'DTM-' . GeneralUtility::shortMD5($this->data['parameterArray']['itemFormElName']);
48 $tabCounter = 0;
49 $tabElements = [];
50 foreach ($flexFormDataStructureArray['sheets'] as $sheetName => $sheetDataStructure) {
51 $flexFormRowSheetDataSubPart = $flexFormRowData['data'][$sheetName]['lDEF'] ?: [];
52
53 if (!is_array($sheetDataStructure['ROOT']['el'])) {
54 $resultArray['html'] .= LF . 'No Data Structure ERROR: No [\'ROOT\'][\'el\'] found for sheet "' . $sheetName . '".';
55 continue;
56 }
57
58 $tabCounter ++;
59
60 // Assemble key for loading the correct CSH file
61 // @todo: what is that good for? That is for the title of single elements ... see FlexFormElementContainer!
62 $dsPointerFields = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['columns'][$fieldName]['config']['ds_pointerField'], true);
63 $parameterArray['_cshKey'] = $table . '.' . $fieldName;
64 foreach ($dsPointerFields as $key) {
65 if (is_string($row[$key]) && $row[$key] !== '') {
66 $parameterArray['_cshKey'] .= '.' . $row[$key];
67 } elseif (is_array($row[$key]) && isset($row[$key][0]) && is_string($row[$key][0]) && $row[$key][0] !== '') {
68 $parameterArray['_cshKey'] .= '.' . $row[$key][0];
69 }
70 }
71
72 $options = $this->data;
73 $options['flexFormDataStructureArray'] = $sheetDataStructure['ROOT']['el'];
74 $options['flexFormRowData'] = $flexFormRowSheetDataSubPart;
75 $options['flexFormFormPrefix'] = '[data][' . $sheetName . '][lDEF]';
76 $options['parameterArray'] = $parameterArray;
77 // Merge elements of this tab into a single list again and hand over to
78 // palette and single field container to render this group
79 $options['tabAndInlineStack'][] = [
80 'tab',
81 $domIdPrefix . '-' . $tabCounter,
82 ];
83 $options['renderType'] = 'flexFormElementContainer';
84 $childReturn = $this->nodeFactory->create($options)->render();
85
86 $tabElements[] = [
87 'label' => !empty(trim($sheetDataStructure['ROOT']['sheetTitle'])) ? $languageService->sL(trim($sheetDataStructure['ROOT']['sheetTitle'])) : $sheetName,
88 'content' => $childReturn['html'],
89 'description' => trim($sheetDataStructure['ROOT']['sheetDescription']) ? $languageService->sL(trim($sheetDataStructure['ROOT']['sheetDescription'])) : '',
90 'linkTitle' => trim($sheetDataStructure['ROOT']['sheetShortDescr']) ? $languageService->sL(trim($sheetDataStructure['ROOT']['sheetShortDescr'])) : '',
91 ];
92
93 $childReturn['html'] = '';
94 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childReturn);
95 }
96
97 $resultArray['html'] = $this->renderTabMenu($tabElements, $domIdPrefix);
98 return $resultArray;
99 }
100
101 /**
102 * @return LanguageService
103 */
104 protected function getLanguageService()
105 {
106 return $GLOBALS['LANG'];
107 }
108 }