[BUGFIX] FormEngine: Inline getDynamicTabMenu
[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 = array();
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 ((string)$row[$key] !== '') {
66 $parameterArray['_cshKey'] .= '.' . $row[$key];
67 }
68 }
69
70 $options = $this->data;
71 $options['flexFormDataStructureArray'] = $sheetDataStructure['ROOT']['el'];
72 $options['flexFormRowData'] = $flexFormRowSheetDataSubPart;
73 $options['flexFormFormPrefix'] = '[data][' . $sheetName . '][lDEF]';
74 $options['parameterArray'] = $parameterArray;
75 // Merge elements of this tab into a single list again and hand over to
76 // palette and single field container to render this group
77 $options['tabAndInlineStack'][] = array(
78 'tab',
79 $domIdPrefix . '-' . $tabCounter,
80 );
81 $options['renderType'] = 'flexFormElementContainer';
82 $childReturn = $this->nodeFactory->create($options)->render();
83
84 $tabElements[] = array(
85 'label' => !empty($sheetDataStructure['ROOT']['sheetTitle']) ? $languageService->sL($sheetDataStructure['ROOT']['sheetTitle']) : $sheetName,
86 'content' => $childReturn['html'],
87 'description' => $sheetDataStructure['ROOT']['sheetDescription'] ? $languageService->sL($sheetDataStructure['ROOT']['sheetDescription']) : '',
88 'linkTitle' => $sheetDataStructure['ROOT']['sheetShortDescr'] ? $languageService->sL($sheetDataStructure['ROOT']['sheetShortDescr']) : '',
89 );
90
91 $childReturn['html'] = '';
92 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childReturn);
93 }
94
95 $resultArray['html'] = $this->renderTabMenu($tabElements, $domIdPrefix);
96 return $resultArray;
97 }
98
99 /**
100 * @return LanguageService
101 */
102 protected function getLanguageService()
103 {
104 return $GLOBALS['LANG'];
105 }
106 }