‪TYPO3CMS  ‪main
FlexFormElementContainer.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 
32 {
38  public function ‪render(): array
39  {
40  $flexFormDataStructureArray = $this->data['flexFormDataStructureArray'];
41  $flexFormRowData = $this->data['flexFormRowData'];
42  $flexFormFormPrefix = $this->data['flexFormFormPrefix'];
43  $parameterArray = $this->data['parameterArray'];
44 
45  $languageService = $this->‪getLanguageService();
46  $resultArray = $this->‪initializeResultArray();
47 
48  foreach ($flexFormDataStructureArray as $flexFormFieldName => $flexFormFieldArray) {
49  if (
50  // No item array found at all
51  !is_array($flexFormFieldArray)
52  // Not a section or container and not a list of single items
53  || (!isset($flexFormFieldArray['type']) && !is_array($flexFormFieldArray['config']))
54  ) {
55  continue;
56  }
57 
58  if (($flexFormFieldArray['type'] ?? null) === 'array') {
59  // Section
60  if (empty($flexFormFieldArray['section'])) {
61  $resultArray['html'] = LF . 'Section expected at ' . $flexFormFieldName . ' but not found';
62  continue;
63  }
64 
65  $options = ‪$this->data;
66  $options['flexFormDataStructureArray'] = $flexFormFieldArray;
67  $options['flexFormRowData'] = $flexFormRowData[$flexFormFieldName]['el'] ?? [];
68  $options['flexFormFieldName'] = $flexFormFieldName;
69  $options['renderType'] = 'flexFormSectionContainer';
70  $sectionContainerResult = $this->nodeFactory->create($options)->render();
71  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $sectionContainerResult);
72  } else {
73  // Set up options for single element
74  $fakeParameterArray = [
75  'fieldConf' => [
76  'label' => $languageService->sL(trim($flexFormFieldArray['label'] ?? '')),
77  'config' => $flexFormFieldArray['config'] ?? [],
78  'children' => $flexFormFieldArray['children'] ?? [],
79  // https://docs.typo3.org/m/typo3/reference-tca/main/en-us/Columns/Properties/OnChange.html
80  'onChange' => $flexFormFieldArray['onChange'] ?? '',
81  ],
82  'fieldChangeFunc' => $parameterArray['fieldChangeFunc'],
83  'label' => $parameterArray['label'] ?? '',
84  ];
85 
86  if (isset($flexFormFieldArray['description']) && !empty($flexFormFieldArray['description'])) {
87  $fakeParameterArray['fieldConf']['description'] = $flexFormFieldArray['description'];
88  }
89 
90  if (isset($fakeParameterArray['fieldConf']['onChange']) && $fakeParameterArray['fieldConf']['onChange'] === 'reload') {
91  $confirmation = $this->‪getBackendUserAuthentication()->jsConfirmation(‪JsConfirmation::TYPE_CHANGE);
92  $fakeParameterArray['fieldChangeFunc']['alert'] = new ‪ReloadOnFieldChange($confirmation);
93  }
94 
95  $originalFieldName = $parameterArray['itemFormElName'];
96  $fakeParameterArray['itemFormElName'] = $parameterArray['itemFormElName'] . $flexFormFormPrefix . '[' . $flexFormFieldName . '][vDEF]';
97  if ($fakeParameterArray['itemFormElName'] !== $originalFieldName) {
98  // If calculated itemFormElName is different from originalFieldName
99  // change the originalFieldName in TBE_EDITOR_fieldChanged. This is
100  // especially relevant for wizards writing their content back to hidden fields
101  $onFieldChange = $fakeParameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] ?? null;
102  if ($onFieldChange instanceof ‪UpdateValueOnFieldChange) {
103  $fakeParameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = $onFieldChange->withElementName($fakeParameterArray['itemFormElName']);
104  }
105  }
106  if (isset($flexFormRowData[$flexFormFieldName]['vDEF'])) {
107  $fakeParameterArray['itemFormElValue'] = $flexFormRowData[$flexFormFieldName]['vDEF'];
108  } else {
109  $fakeParameterArray['itemFormElValue'] = $fakeParameterArray['fieldConf']['config']['default'];
110  }
111 
112  $options = ‪$this->data;
113  // Set either flexFormFieldName or flexFormContainerFieldName, depending on if we are a "regular" field or a flex container section field
114  if (empty($options['flexFormFieldName'])) {
115  $options['flexFormFieldName'] = $flexFormFieldName;
116  } else {
117  $options['flexFormContainerFieldName'] = $flexFormFieldName;
118  }
119  $options['parameterArray'] = $fakeParameterArray;
120  $options['elementBaseName'] = $this->data['elementBaseName'] . $flexFormFormPrefix . '[' . $flexFormFieldName . '][vDEF]';
121 
122  if (!empty($flexFormFieldArray['config']['renderType'])) {
123  $options['renderType'] = $flexFormFieldArray['config']['renderType'];
124  } else {
125  // Fallback to type if no renderType is given
126  $options['renderType'] = $flexFormFieldArray['config']['type'];
127  }
128  $childResult = $this->nodeFactory->create($options)->render();
129 
130  if (!empty($childResult['html'])) {
131  $html = [];
132  $html[] = '<div class="form-section" data-id="' . htmlspecialchars($flexFormFieldName) . '">';
133  $html[] = '<div class="form-group t3js-formengine-palette-field t3js-formengine-validation-marker">';
134  $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
135  $html[] = $childResult['html'];
136  $html[] = '</div>';
137  $html[] = '</div>';
138  $html[] = '</div>';
139  $resultArray['html'] .= implode(LF, $html);
140  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $childResult, false);
141  }
142  }
143  }
144 
145  return $resultArray;
146  }
147 
149  {
150  return ‪$GLOBALS['LANG'];
151  }
152 
153 }
‪TYPO3\CMS\Backend\Form\AbstractNode\mergeChildReturnIntoExistingResult
‪array mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
Definition: AbstractNode.php:104
‪TYPO3\CMS\Backend\Form\Container\FlexFormElementContainer\render
‪array render()
Definition: FlexFormElementContainer.php:38
‪TYPO3\CMS\Backend\Form\Behavior\UpdateValueOnFieldChange
Definition: UpdateValueOnFieldChange.php:25
‪TYPO3\CMS\Backend\Form\Container\FlexFormElementContainer\getLanguageService
‪getLanguageService()
Definition: FlexFormElementContainer.php:148
‪TYPO3\CMS\Backend\Form\Container
Definition: AbstractContainer.php:16
‪TYPO3\CMS\Core\Authentication\JsConfirmation
Definition: JsConfirmation.php:28
‪TYPO3\CMS\Backend\Form\Container\AbstractContainer\getBackendUserAuthentication
‪getBackendUserAuthentication()
Definition: AbstractContainer.php:149
‪TYPO3\CMS\Backend\Form\AbstractNode\$data
‪array $data
Definition: AbstractNode.php:35
‪TYPO3\CMS\Backend\Form\Container\AbstractContainer
Definition: AbstractContainer.php:29
‪TYPO3\CMS\Core\Authentication\JsConfirmation\TYPE_CHANGE
‪const TYPE_CHANGE
Definition: JsConfirmation.php:29
‪TYPO3\CMS\Backend\Form\Behavior\ReloadOnFieldChange
Definition: ReloadOnFieldChange.php:25
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Backend\Form\Container\FlexFormElementContainer
Definition: FlexFormElementContainer.php:32
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪initializeResultArray()
Definition: AbstractNode.php:77