FlexFormTabsContainer.php 5.18 KB
Newer Older
Christian Kuhn's avatar
Christian Kuhn committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
namespace TYPO3\CMS\Backend\Form\Container;

/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

use TYPO3\CMS\Backend\Template\DocumentTemplate;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Lang\LanguageService;
20
use TYPO3\CMS\Backend\Form\NodeFactory;
Christian Kuhn's avatar
Christian Kuhn committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

/**
 * Handle flex forms that have tabs (multiple "sheets").
 *
 * This container is called by FlexFormLanguageContainer. It resolves each
 * sheet and hands rendering of single sheet content over to FlexFormElementContainer.
 */
class FlexFormTabsContainer extends AbstractContainer {

	/**
	 * Entry method
	 *
	 * @return array As defined in initializeResultArray() of AbstractNode
	 */
	public function render() {
		$languageService = $this->getLanguageService();
		$docTemplate = $this->getDocumentTemplate();

		$table = $this->globalOptions['table'];
		$row = $this->globalOptions['databaseRow'];
		$fieldName = $this->globalOptions['fieldName']; // field name of the flex form field in DB
		$parameterArray = $this->globalOptions['parameterArray'];
		$flexFormDataStructureArray = $this->globalOptions['flexFormDataStructureArray'];
		$flexFormCurrentLanguage = $this->globalOptions['flexFormCurrentLanguage'];
		$flexFormRowData = $this->globalOptions['flexFormRowData'];

		$tabId = 'TCEFORMS:flexform:' . $this->globalOptions['parameterArray']['itemFormElName'] . $flexFormCurrentLanguage;
		$tabIdString = $docTemplate->getDynTabMenuId($tabId);
		$tabCounter = 0;

		$resultArray = $this->initializeResultArray();
		$tabsContent = array();
		foreach ($flexFormDataStructureArray['sheets'] as $sheetName => $sheetDataStructure) {
			$flexFormRowSheetDataSubPart = $flexFormRowData['data'][$sheetName][$flexFormCurrentLanguage];

			// Evaluate display condition for this sheet if there is one
			$displayConditionResult = TRUE;
			if (!empty($sheetDataStructure['ROOT']['TCEforms']['displayCond'])) {
				$displayConditionDefinition = $sheetDataStructure['ROOT']['TCEforms']['displayCond'];
				$displayConditionResult = $this->evaluateFlexFormDisplayCondition(
					$displayConditionDefinition,
					$flexFormRowSheetDataSubPart
				);
			}
			if (!$displayConditionResult) {
				continue;
			}

			if (!is_array($sheetDataStructure['ROOT']['el'])) {
				$resultArray['html'] .= LF . 'No Data Structure ERROR: No [\'ROOT\'][\'el\'] found for sheet "' . $sheetName . '".';
				continue;
			}

			$tabCounter ++;

			// Assemble key for loading the correct CSH file
			// @todo: what is that good for? That is for the title of single elements ... see FlexFormElementContainer!
			$dsPointerFields = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['columns'][$fieldName]['config']['ds_pointerField'], TRUE);
			$parameterArray['_cshKey'] = $table . '.' . $fieldName;
			foreach ($dsPointerFields as $key) {
				$parameterArray['_cshKey'] .= '.' . $row[$key];
			}

			$options = $this->globalOptions;
			$options['flexFormDataStructureArray'] = $sheetDataStructure['ROOT']['el'];
			$options['flexFormRowData'] = $flexFormRowSheetDataSubPart;
			$options['flexFormFormPrefix'] = '[data][' . $sheetName . '][' . $flexFormCurrentLanguage . ']';
			$options['parameterArray'] = $parameterArray;
			// Merge elements of this tab into a single list again and hand over to
			// palette and single field container to render this group
			$options['tabAndInlineStack'][] = array(
				'tab',
				$tabIdString . '-' . $tabCounter,
			);
95
			$options['renderType'] = 'flexFormElementContainer';
96
97
98
			/** @var NodeFactory $nodeFactory */
			$nodeFactory = $this->globalOptions['nodeFactory'];
			$childReturn = $nodeFactory->create($options)->render();
Christian Kuhn's avatar
Christian Kuhn committed
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

			$tabsContent[] = array(
				'label' => !empty($sheetDataStructure['ROOT']['TCEforms']['sheetTitle']) ? $languageService->sL($sheetDataStructure['ROOT']['TCEforms']['sheetTitle']) : $sheetName,
				'content' => $childReturn['html'],
				'description' => $sheetDataStructure['ROOT']['TCEforms']['sheetDescription'] ? $languageService->sL($sheetDataStructure['ROOT']['TCEforms']['sheetDescription']) : '',
				'linkTitle' => $sheetDataStructure['ROOT']['TCEforms']['sheetShortDescr'] ? $languageService->sL($sheetDataStructure['ROOT']['TCEforms']['sheetShortDescr']) : '',
			);

			$childReturn['html'] = '';
			$resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childReturn);
		}

		// Feed everything to document template for tab rendering
		$resultArray['html'] = $docTemplate->getDynamicTabMenu($tabsContent, $tabId, 1, FALSE, FALSE);
		return $resultArray;
	}

	/**
	 * @throws \RuntimeException
	 * @return DocumentTemplate
	 */
	protected function getDocumentTemplate() {
		$docTemplate = $GLOBALS['TBE_TEMPLATE'];
		if (!is_object($docTemplate)) {
			throw new \RuntimeException('No instance of DocumentTemplate found', 1427143328);
		}
		return $docTemplate;
	}

	/**
	 * @return LanguageService
	 */
	protected function getLanguageService() {
		return $GLOBALS['LANG'];
	}

}