‪TYPO3CMS  11.5
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 
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
24 
34 {
40  public function ‪render()
41  {
42  $flexFormDataStructureArray = $this->data['flexFormDataStructureArray'];
43  $flexFormRowData = $this->data['flexFormRowData'];
44  $flexFormFormPrefix = $this->data['flexFormFormPrefix'];
45  $parameterArray = $this->data['parameterArray'];
46 
47  $languageService = $this->‪getLanguageService();
48  $resultArray = $this->‪initializeResultArray();
50 
51  foreach ($flexFormDataStructureArray as $flexFormFieldName => $flexFormFieldArray) {
52  if (
53  // No item array found at all
54  !is_array($flexFormFieldArray)
55  // Not a section or container and not a list of single items
56  || (!isset($flexFormFieldArray['type']) && !is_array($flexFormFieldArray['config']))
57  ) {
58  continue;
59  }
60 
61  if (($flexFormFieldArray['type'] ?? null) === 'array') {
62  // Section
63  if (empty($flexFormFieldArray['section'])) {
64  $resultArray['html'] = LF . 'Section expected at ' . $flexFormFieldName . ' but not found';
65  continue;
66  }
67 
68  $options = ‪$this->data;
69  $options['flexFormDataStructureArray'] = $flexFormFieldArray;
70  $options['flexFormRowData'] = $flexFormRowData[$flexFormFieldName]['el'] ?? [];
71  $options['flexFormFieldName'] = $flexFormFieldName;
72  $options['renderType'] = 'flexFormSectionContainer';
73  $sectionContainerResult = $this->nodeFactory->create($options)->render();
74  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $sectionContainerResult);
75  } else {
76  // Set up options for single element
77  $fakeParameterArray = [
78  'fieldConf' => [
79  'label' => $languageService->sL(trim($flexFormFieldArray['label'] ?? '')),
80  'config' => $flexFormFieldArray['config'] ?? [],
81  'children' => $flexFormFieldArray['children'] ?? [],
82  // https://docs.typo3.org/m/typo3/reference-tca/main/en-us/Columns/Properties/OnChange.html
83  'onChange' => $flexFormFieldArray['onChange'] ?? '',
84  ],
85  'fieldChangeFunc' => $parameterArray['fieldChangeFunc'],
86  'label' => $parameterArray['label'] ?? '',
87  ];
88 
89  if (isset($flexFormFieldArray['description']) && !empty($flexFormFieldArray['description'])) {
90  $fakeParameterArray['fieldConf']['description'] = $flexFormFieldArray['description'];
91  }
92 
93  if (isset($fakeParameterArray['fieldConf']['onChange']) && $fakeParameterArray['fieldConf']['onChange'] === 'reload') {
95  $fakeParameterArray['fieldChangeFunc']['alert'] = new ‪ReloadOnFieldChange($confirmation);
96  }
97 
98  $originalFieldName = $parameterArray['itemFormElName'];
99  $fakeParameterArray['itemFormElName'] = $parameterArray['itemFormElName'] . $flexFormFormPrefix . '[' . $flexFormFieldName . '][vDEF]';
100  if ($fakeParameterArray['itemFormElName'] !== $originalFieldName) {
101  // If calculated itemFormElName is different from originalFieldName
102  // change the originalFieldName in TBE_EDITOR_fieldChanged. This is
103  // especially relevant for wizards writing their content back to hidden fields
104  $onFieldChange = $fakeParameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] ?? null;
105  if ($onFieldChange instanceof ‪UpdateValueOnFieldChange) {
106  $fakeParameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = $onFieldChange->withElementName($fakeParameterArray['itemFormElName']);
107  } elseif (!empty($onFieldChange)) {
108  // @deprecated
109  $fakeParameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = str_replace($originalFieldName, $fakeParameterArray['itemFormElName'], $onFieldChange);
110  }
111  }
112  $fakeParameterArray['itemFormElID'] = ($parameterArray['itemFormElID'] ?? '') . '_' . preg_replace('/[^a-zA-Z0-9_-]/', '_', $flexFormFieldName) . '_' . md5($fakeParameterArray['itemFormElName']);
113  if (isset($flexFormRowData[$flexFormFieldName]['vDEF'])) {
114  $fakeParameterArray['itemFormElValue'] = $flexFormRowData[$flexFormFieldName]['vDEF'];
115  } else {
116  $fakeParameterArray['itemFormElValue'] = $fakeParameterArray['fieldConf']['config']['default'];
117  }
118 
119  $options = ‪$this->data;
120  // Set either flexFormFieldName or flexFormContainerFieldName, depending on if we are a "regular" field or a flex container section field
121  if (empty($options['flexFormFieldName'])) {
122  $options['flexFormFieldName'] = $flexFormFieldName;
123  } else {
124  $options['flexFormContainerFieldName'] = $flexFormFieldName;
125  }
126  $options['parameterArray'] = $fakeParameterArray;
127  $options['elementBaseName'] = $this->data['elementBaseName'] . $flexFormFormPrefix . '[' . $flexFormFieldName . '][vDEF]';
128 
129  if (!empty($flexFormFieldArray['config']['renderType'])) {
130  $options['renderType'] = $flexFormFieldArray['config']['renderType'];
131  } else {
132  // Fallback to type if no renderType is given
133  $options['renderType'] = $flexFormFieldArray['config']['type'];
134  }
135  $childResult = $this->nodeFactory->create($options)->render();
136 
137  if (!empty($childResult['html'])) {
138  // Possible line breaks in the label through xml: \n => <br/>, usage of nl2br() not possible, so it's done through str_replace (?!)
139  $processedTitle = str_replace('\\n', '<br />', htmlspecialchars($fakeParameterArray['fieldConf']['label']));
140  $html = [];
141  $html[] = '<div class="form-section">';
142  $html[] = '<div class="form-group t3js-formengine-palette-field t3js-formengine-validation-marker">';
143  $html[] = '<label class="t3js-formengine-label">';
144  $html[] = BackendUtility::wrapInHelp($parameterArray['_cshKey'] ?? '', $flexFormFieldName, $processedTitle);
145  $html[] = $showFieldName ? ('<code>[' . htmlspecialchars($flexFormFieldName) . ']</code>') : '';
146  $html[] = '</label>';
147  $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
148  $html[] = $childResult['html'];
149  $html[] = '</div>';
150  $html[] = '</div>';
151  $html[] = '</div>';
152  $resultArray['html'] .= implode(LF, $html);
153  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $childResult, false);
154  }
155  }
156  }
157 
158  return $resultArray;
159  }
160 
164  protected function ‪getLanguageService()
165  {
166  return ‪$GLOBALS['LANG'];
167  }
168 
172  protected function ‪getBackendUserAuthentication()
173  {
174  return ‪$GLOBALS['BE_USER'];
175  }
176 }
‪TYPO3\CMS\Backend\Form\AbstractNode\mergeChildReturnIntoExistingResult
‪array mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
Definition: AbstractNode.php:120
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:91
‪TYPO3\CMS\Backend\Form\Container\FlexFormElementContainer\render
‪array render()
Definition: FlexFormElementContainer.php:40
‪TYPO3\CMS\Backend\Form\Behavior\UpdateValueOnFieldChange
Definition: UpdateValueOnFieldChange.php:27
‪TYPO3\CMS\Backend\Form\Container
Definition: AbstractContainer.php:16
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\shallDisplayDebugInformation
‪shallDisplayDebugInformation()
Definition: BackendUserAuthentication.php:2381
‪TYPO3\CMS\Backend\Form\AbstractNode\$data
‪array $data
Definition: AbstractNode.php:43
‪TYPO3\CMS\Backend\Form\Container\AbstractContainer
Definition: AbstractContainer.php:28
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪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\Backend\Form\Container\FlexFormElementContainer\getBackendUserAuthentication
‪BackendUserAuthentication getBackendUserAuthentication()
Definition: FlexFormElementContainer.php:172
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Type\Bitmask\JsConfirmation\TYPE_CHANGE
‪const TYPE_CHANGE
Definition: JsConfirmation.php:29
‪TYPO3\CMS\Backend\Form\Container\FlexFormElementContainer
Definition: FlexFormElementContainer.php:34
‪TYPO3\CMS\Core\Type\Bitmask\JsConfirmation
Definition: JsConfirmation.php:25
‪TYPO3\CMS\Backend\Form\Container\FlexFormElementContainer\getLanguageService
‪LanguageService getLanguageService()
Definition: FlexFormElementContainer.php:164
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\jsConfirmation
‪bool jsConfirmation($bitmask)
Definition: BackendUserAuthentication.php:1071