239c661f0f87e57f82016bacbf6712bab4c38855
[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 use TYPO3\CMS\Backend\Form\NodeFactory;
21
22 /**
23 * Handle flex forms that have tabs (multiple "sheets").
24 *
25 * This container is called by FlexFormLanguageContainer. 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 $languageService = $this->getLanguageService();
37 $docTemplate = $this->getDocumentTemplate();
38
39 $table = $this->globalOptions['table'];
40 $row = $this->globalOptions['databaseRow'];
41 $fieldName = $this->globalOptions['fieldName']; // field name of the flex form field in DB
42 $parameterArray = $this->globalOptions['parameterArray'];
43 $flexFormDataStructureArray = $this->globalOptions['flexFormDataStructureArray'];
44 $flexFormCurrentLanguage = $this->globalOptions['flexFormCurrentLanguage'];
45 $flexFormRowData = $this->globalOptions['flexFormRowData'];
46
47 $tabId = 'TCEFORMS:flexform:' . $this->globalOptions['parameterArray']['itemFormElName'] . $flexFormCurrentLanguage;
48 $tabIdString = $docTemplate->getDynTabMenuId($tabId);
49 $tabCounter = 0;
50
51 $resultArray = $this->initializeResultArray();
52 $tabsContent = array();
53 foreach ($flexFormDataStructureArray['sheets'] as $sheetName => $sheetDataStructure) {
54 $flexFormRowSheetDataSubPart = $flexFormRowData['data'][$sheetName][$flexFormCurrentLanguage];
55
56 // Evaluate display condition for this sheet if there is one
57 $displayConditionResult = TRUE;
58 if (!empty($sheetDataStructure['ROOT']['TCEforms']['displayCond'])) {
59 $displayConditionDefinition = $sheetDataStructure['ROOT']['TCEforms']['displayCond'];
60 $displayConditionResult = $this->evaluateFlexFormDisplayCondition(
61 $displayConditionDefinition,
62 $flexFormRowSheetDataSubPart
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 $parameterArray['_cshKey'] .= '.' . $row[$key];
82 }
83
84 $options = $this->globalOptions;
85 $options['flexFormDataStructureArray'] = $sheetDataStructure['ROOT']['el'];
86 $options['flexFormRowData'] = $flexFormRowSheetDataSubPart;
87 $options['flexFormFormPrefix'] = '[data][' . $sheetName . '][' . $flexFormCurrentLanguage . ']';
88 $options['parameterArray'] = $parameterArray;
89 // Merge elements of this tab into a single list again and hand over to
90 // palette and single field container to render this group
91 $options['tabAndInlineStack'][] = array(
92 'tab',
93 $tabIdString . '-' . $tabCounter,
94 );
95 $options['renderType'] = 'flexFormElementContainer';
96 /** @var NodeFactory $nodeFactory */
97 $nodeFactory = $this->globalOptions['nodeFactory'];
98 $childReturn = $nodeFactory->create($options)->render();
99
100 $tabsContent[] = array(
101 'label' => !empty($sheetDataStructure['ROOT']['TCEforms']['sheetTitle']) ? $languageService->sL($sheetDataStructure['ROOT']['TCEforms']['sheetTitle']) : $sheetName,
102 'content' => $childReturn['html'],
103 'description' => $sheetDataStructure['ROOT']['TCEforms']['sheetDescription'] ? $languageService->sL($sheetDataStructure['ROOT']['TCEforms']['sheetDescription']) : '',
104 'linkTitle' => $sheetDataStructure['ROOT']['TCEforms']['sheetShortDescr'] ? $languageService->sL($sheetDataStructure['ROOT']['TCEforms']['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 }