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