4109b50ffa5f0086928533bb15dca5abcb3a8797
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / Container / AbstractContainer.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\Form\AbstractNode;
18 use TYPO3\CMS\Core\Utility\ArrayUtility;
19 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Fluid\View\StandaloneView;
22
23 /**
24 * Abstract container has various methods used by the container classes
25 */
26 abstract class AbstractContainer extends AbstractNode
27 {
28 /**
29 * Merge field information configuration with default and render them.
30 *
31 * @return array Result array
32 */
33 protected function renderFieldInformation(): array
34 {
35 $options = $this->data;
36 $fieldInformation = $this->defaultFieldInformation;
37 $currentRenderType = $this->data['renderType'];
38 $fieldInformationFromTca = $options['processedTca']['ctrl']['container'][$currentRenderType]['fieldInformation'] ?? [];
39 ArrayUtility::mergeRecursiveWithOverrule($fieldInformation, $fieldInformationFromTca);
40 $options['renderType'] = 'fieldInformation';
41 $options['renderData']['fieldInformation'] = $fieldInformation;
42 return $this->nodeFactory->create($options)->render();
43 }
44
45 /**
46 * Merge field control configuration with default controls and render them.
47 *
48 * @return array Result array
49 */
50 protected function renderFieldControl(): array
51 {
52 $options = $this->data;
53 $fieldControl = $this->defaultFieldControl;
54 $currentRenderType = $this->data['renderType'];
55 $fieldControlFromTca = $options['processedTca']['ctrl']['container'][$currentRenderType]['fieldControl'] ?? [];
56 ArrayUtility::mergeRecursiveWithOverrule($fieldControl, $fieldControlFromTca);
57 $options['renderType'] = 'fieldControl';
58 $options['renderData']['fieldControl'] = $fieldControl;
59 return $this->nodeFactory->create($options)->render();
60 }
61
62 /**
63 * Merge field wizard configuration with default wizards and render them.
64 *
65 * @return array Result array
66 */
67 protected function renderFieldWizard(): array
68 {
69 $options = $this->data;
70 $fieldWizard = $this->defaultFieldWizard;
71 $currentRenderType = $this->data['renderType'];
72 $fieldWizardFromTca = $options['processedTca']['ctrl']['container'][$currentRenderType]['fieldWizard'] ?? [];
73 ArrayUtility::mergeRecursiveWithOverrule($fieldWizard, $fieldWizardFromTca);
74 $options['renderType'] = 'fieldWizard';
75 $options['renderData']['fieldWizard'] = $fieldWizard;
76 return $this->nodeFactory->create($options)->render();
77 }
78
79 /**
80 * A single field of TCA 'types' 'showitem' can have three semicolon separated configuration options:
81 * fieldName: Name of the field to be found in TCA 'columns' section
82 * fieldLabel: An alternative field label
83 * paletteName: Name of a palette to be found in TCA 'palettes' section that is rendered after this field
84 *
85 * @param string $field Semicolon separated field configuration
86 * @throws \RuntimeException
87 * @return array
88 */
89 protected function explodeSingleFieldShowItemConfiguration($field)
90 {
91 $fieldArray = GeneralUtility::trimExplode(';', $field);
92 if (empty($fieldArray[0])) {
93 throw new \RuntimeException('Field must not be empty', 1426448465);
94 }
95 return [
96 'fieldName' => $fieldArray[0],
97 'fieldLabel' => $fieldArray[1] ?: null,
98 'paletteName' => $fieldArray[2] ?: null,
99 ];
100 }
101
102 /**
103 * Render tabs with label and content. Used by TabsContainer and FlexFormTabsContainer.
104 * Re-uses the template Tabs.html which is also used by ModuleTemplate.php.
105 *
106 * @param array $menuItems Tab elements, each element is an array with "label" and "content"
107 * @param string $domId DOM id attribute, will be appended with an iteration number per tab.
108 * @return string
109 */
110 protected function renderTabMenu(array $menuItems, $domId, $defaultTabIndex = 1)
111 {
112 $templatePath = ExtensionManagementUtility::extPath('backend')
113 . 'Resources/Private/Templates/DocumentTemplate/';
114
115 $view = GeneralUtility::makeInstance(StandaloneView::class);
116 $view->setTemplatePathAndFilename($templatePath . 'Tabs.html');
117 $view->setPartialRootPaths([$templatePath . 'Partials']);
118 $view->assignMultiple([
119 'id' => $domId,
120 'items' => $menuItems,
121 'defaultTabIndex' => $defaultTabIndex,
122 'wrapContent' => false,
123 'storeLastActiveTab' => true,
124 ]);
125 return $view->render();
126 }
127 }