cabea31594bb77c37ff92b9fb9bb52f55e081629
[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 $docTemplate = $this->getDocumentTemplate();
39
40 $table = $this->data['tableName'];
41 $row = $this->data['databaseRow'];
42 $fieldName = $this->data['fieldName']; // field name of the flex form field in DB
43 $parameterArray = $this->data['parameterArray'];
44 $flexFormDataStructureArray = $this->data['flexFormDataStructureArray'];
45 $flexFormCurrentLanguage = $this->data['flexFormCurrentLanguage'];
46 $flexFormRowData = $this->data['flexFormRowData'];
47
48 $tabId = 'TCEFORMS:flexform:' . $this->data['parameterArray']['itemFormElName'] . $flexFormCurrentLanguage;
49 $tabIdString = $docTemplate->getDynTabMenuId($tabId);
50 $tabCounter = 0;
51
52 $resultArray = $this->initializeResultArray();
53 $tabsContent = array();
54 foreach ($flexFormDataStructureArray['sheets'] as $sheetName => $sheetDataStructure) {
55 $flexFormRowSheetDataSubPart = $flexFormRowData['data'][$sheetName][$flexFormCurrentLanguage];
56
57 if (!is_array($sheetDataStructure['ROOT']['el'])) {
58 $resultArray['html'] .= LF . 'No Data Structure ERROR: No [\'ROOT\'][\'el\'] found for sheet "' . $sheetName . '".';
59 continue;
60 }
61
62 $tabCounter ++;
63
64 // Assemble key for loading the correct CSH file
65 // @todo: what is that good for? That is for the title of single elements ... see FlexFormElementContainer!
66 $dsPointerFields = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['columns'][$fieldName]['config']['ds_pointerField'], true);
67 $parameterArray['_cshKey'] = $table . '.' . $fieldName;
68 foreach ($dsPointerFields as $key) {
69 if ((string)$row[$key] !== '') {
70 $parameterArray['_cshKey'] .= '.' . $row[$key];
71 }
72 }
73
74 $options = $this->data;
75 $options['flexFormDataStructureArray'] = $sheetDataStructure['ROOT']['el'];
76 $options['flexFormRowData'] = $flexFormRowSheetDataSubPart;
77 $options['flexFormFormPrefix'] = '[data][' . $sheetName . '][' . $flexFormCurrentLanguage . ']';
78 $options['parameterArray'] = $parameterArray;
79 // Merge elements of this tab into a single list again and hand over to
80 // palette and single field container to render this group
81 $options['tabAndInlineStack'][] = array(
82 'tab',
83 $tabIdString . '-' . $tabCounter,
84 );
85 $options['renderType'] = 'flexFormElementContainer';
86 $childReturn = $this->nodeFactory->create($options)->render();
87
88 $tabsContent[] = array(
89 'label' => !empty($sheetDataStructure['ROOT']['sheetTitle']) ? $languageService->sL($sheetDataStructure['ROOT']['sheetTitle']) : $sheetName,
90 'content' => $childReturn['html'],
91 'description' => $sheetDataStructure['ROOT']['sheetDescription'] ? $languageService->sL($sheetDataStructure['ROOT']['sheetDescription']) : '',
92 'linkTitle' => $sheetDataStructure['ROOT']['sheetShortDescr'] ? $languageService->sL($sheetDataStructure['ROOT']['sheetShortDescr']) : '',
93 );
94
95 $childReturn['html'] = '';
96 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childReturn);
97 }
98
99 // Feed everything to document template for tab rendering
100 $resultArray['html'] = $docTemplate->getDynamicTabMenu($tabsContent, $tabId, 1, false, false);
101 return $resultArray;
102 }
103
104 /**
105 * @throws \RuntimeException
106 * @return DocumentTemplate
107 */
108 protected function getDocumentTemplate()
109 {
110 $docTemplate = $GLOBALS['TBE_TEMPLATE'];
111 if (!is_object($docTemplate)) {
112 throw new \RuntimeException('No instance of DocumentTemplate found', 1427143328);
113 }
114 return $docTemplate;
115 }
116
117 /**
118 * @return LanguageService
119 */
120 protected function getLanguageService()
121 {
122 return $GLOBALS['LANG'];
123 }
124 }