861de84bdaafdf14cbb25977b83113a18a62cc3b
[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 FlexFormEntryContainer. 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 {
36 $languageService = $this->getLanguageService();
37 $docTemplate = $this->getDocumentTemplate();
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 $flexFormRowData = $this->data['flexFormRowData'];
45
46 $tabId = 'TCEFORMS:flexform:' . $this->data['parameterArray']['itemFormElName'] . 'lDEF';
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]['lDEF'] ?: [];
54
55 if (!is_array($sheetDataStructure['ROOT']['el'])) {
56 $resultArray['html'] .= LF . 'No Data Structure ERROR: No [\'ROOT\'][\'el\'] found for sheet "' . $sheetName . '".';
57 continue;
58 }
59
60 $tabCounter ++;
61
62 // Assemble key for loading the correct CSH file
63 // @todo: what is that good for? That is for the title of single elements ... see FlexFormElementContainer!
64 $dsPointerFields = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['columns'][$fieldName]['config']['ds_pointerField'], true);
65 $parameterArray['_cshKey'] = $table . '.' . $fieldName;
66 foreach ($dsPointerFields as $key) {
67 if ((string)$row[$key] !== '') {
68 $parameterArray['_cshKey'] .= '.' . $row[$key];
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'][] = array(
80 'tab',
81 $tabIdString . '-' . $tabCounter,
82 );
83 $options['renderType'] = 'flexFormElementContainer';
84 $childReturn = $this->nodeFactory->create($options)->render();
85
86 $tabsContent[] = array(
87 'label' => !empty($sheetDataStructure['ROOT']['sheetTitle']) ? $languageService->sL($sheetDataStructure['ROOT']['sheetTitle']) : $sheetName,
88 'content' => $childReturn['html'],
89 'description' => $sheetDataStructure['ROOT']['sheetDescription'] ? $languageService->sL($sheetDataStructure['ROOT']['sheetDescription']) : '',
90 'linkTitle' => $sheetDataStructure['ROOT']['sheetShortDescr'] ? $languageService->sL($sheetDataStructure['ROOT']['sheetShortDescr']) : '',
91 );
92
93 $childReturn['html'] = '';
94 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childReturn);
95 }
96
97 // Feed everything to document template for tab rendering
98 $resultArray['html'] = $docTemplate->getDynamicTabMenu($tabsContent, $tabId, 1, false, false);
99 return $resultArray;
100 }
101
102 /**
103 * @throws \RuntimeException
104 * @return DocumentTemplate
105 */
106 protected function getDocumentTemplate()
107 {
108 $docTemplate = $GLOBALS['TBE_TEMPLATE'];
109 if (!is_object($docTemplate)) {
110 throw new \RuntimeException('No instance of DocumentTemplate found', 1427143328);
111 }
112 return $docTemplate;
113 }
114
115 /**
116 * @return LanguageService
117 */
118 protected function getLanguageService()
119 {
120 return $GLOBALS['LANG'];
121 }
122 }