[TASK] FormEngine: Remove "TCEforms" from sheet level data structure
[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\Backend\Template\DocumentTemplate;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Lang\LanguageService;
20
21 /**
22 * Handle flex forms that have tabs (multiple "sheets").
23 *
24 * This container is called by FlexFormLanguageContainer. It resolves each
25 * sheet and hands rendering of single sheet content over to FlexFormElementContainer.
26 */
27 class FlexFormTabsContainer extends AbstractContainer {
28
29 /**
30 * Entry method
31 *
32 * @return array As defined in initializeResultArray() of AbstractNode
33 */
34 public function render() {
35 $languageService = $this->getLanguageService();
36 $docTemplate = $this->getDocumentTemplate();
37
38 $table = $this->data['tableName'];
39 $row = $this->data['databaseRow'];
40 $fieldName = $this->data['fieldName']; // field name of the flex form field in DB
41 $parameterArray = $this->data['parameterArray'];
42 $flexFormDataStructureArray = $this->data['flexFormDataStructureArray'];
43 $flexFormCurrentLanguage = $this->data['flexFormCurrentLanguage'];
44 $flexFormRowData = $this->data['flexFormRowData'];
45
46 $tabId = 'TCEFORMS:flexform:' . $this->data['parameterArray']['itemFormElName'] . $flexFormCurrentLanguage;
47 $tabIdString = $docTemplate->getDynTabMenuId($tabId);
48 $tabCounter = 0;
49
50 $resultArray = $this->initializeResultArray();
51 $tabsContent = array();
52 foreach ($flexFormDataStructureArray['sheets'] as $sheetName => $sheetDataStructure) {
53 $flexFormRowSheetDataSubPart = $flexFormRowData['data'][$sheetName][$flexFormCurrentLanguage];
54
55 // Evaluate display condition for this sheet if there is one
56 $displayConditionResult = TRUE;
57 if (!empty($sheetDataStructure['ROOT']['displayCond'])) {
58 $displayConditionDefinition = $sheetDataStructure['ROOT']['displayCond'];
59 $displayConditionResult = $this->evaluateFlexFormDisplayCondition(
60 $displayConditionDefinition,
61 $flexFormRowData['data'],
62 $flexFormCurrentLanguage
63 );
64 }
65 if (!$displayConditionResult) {
66 continue;
67 }
68
69 if (!is_array($sheetDataStructure['ROOT']['el'])) {
70 $resultArray['html'] .= LF . 'No Data Structure ERROR: No [\'ROOT\'][\'el\'] found for sheet "' . $sheetName . '".';
71 continue;
72 }
73
74 $tabCounter ++;
75
76 // Assemble key for loading the correct CSH file
77 // @todo: what is that good for? That is for the title of single elements ... see FlexFormElementContainer!
78 $dsPointerFields = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['columns'][$fieldName]['config']['ds_pointerField'], TRUE);
79 $parameterArray['_cshKey'] = $table . '.' . $fieldName;
80 foreach ($dsPointerFields as $key) {
81 if ((string)$row[$key] !== '') {
82 $parameterArray['_cshKey'] .= '.' . $row[$key];
83 }
84 }
85
86 $options = $this->data;
87 $options['flexFormDataStructureArray'] = $sheetDataStructure['ROOT']['el'];
88 $options['flexFormRowData'] = $flexFormRowSheetDataSubPart;
89 $options['flexFormFormPrefix'] = '[data][' . $sheetName . '][' . $flexFormCurrentLanguage . ']';
90 $options['parameterArray'] = $parameterArray;
91 // Merge elements of this tab into a single list again and hand over to
92 // palette and single field container to render this group
93 $options['tabAndInlineStack'][] = array(
94 'tab',
95 $tabIdString . '-' . $tabCounter,
96 );
97 $options['renderType'] = 'flexFormElementContainer';
98 $childReturn = $this->nodeFactory->create($options)->render();
99
100 $tabsContent[] = array(
101 'label' => !empty($sheetDataStructure['ROOT']['sheetTitle']) ? $languageService->sL($sheetDataStructure['ROOT']['sheetTitle']) : $sheetName,
102 'content' => $childReturn['html'],
103 'description' => $sheetDataStructure['ROOT']['sheetDescription'] ? $languageService->sL($sheetDataStructure['ROOT']['sheetDescription']) : '',
104 'linkTitle' => $sheetDataStructure['ROOT']['sheetShortDescr'] ? $languageService->sL($sheetDataStructure['ROOT']['sheetShortDescr']) : '',
105 );
106
107 $childReturn['html'] = '';
108 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childReturn);
109 }
110
111 // Feed everything to document template for tab rendering
112 $resultArray['html'] = $docTemplate->getDynamicTabMenu($tabsContent, $tabId, 1, FALSE, FALSE);
113 return $resultArray;
114 }
115
116 /**
117 * @throws \RuntimeException
118 * @return DocumentTemplate
119 */
120 protected function getDocumentTemplate() {
121 $docTemplate = $GLOBALS['TBE_TEMPLATE'];
122 if (!is_object($docTemplate)) {
123 throw new \RuntimeException('No instance of DocumentTemplate found', 1427143328);
124 }
125 return $docTemplate;
126 }
127
128 /**
129 * @return LanguageService
130 */
131 protected function getLanguageService() {
132 return $GLOBALS['LANG'];
133 }
134
135 }