‪TYPO3CMS  9.5
FlexFormElementContainer.php
Go to the documentation of this file.
1 <?php
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 
21 
31 {
37  public function ‪render()
38  {
39  $flexFormDataStructureArray = $this->data['flexFormDataStructureArray'];
40  $flexFormRowData = $this->data['flexFormRowData'];
41  $flexFormFormPrefix = $this->data['flexFormFormPrefix'];
42  $parameterArray = $this->data['parameterArray'];
43 
44  $languageService = $this->‪getLanguageService();
45  $resultArray = $this->‪initializeResultArray();
46  foreach ($flexFormDataStructureArray as $flexFormFieldName => $flexFormFieldArray) {
47  if (
48  // No item array found at all
49  !is_array($flexFormFieldArray)
50  // Not a section or container and not a list of single items
51  || (!isset($flexFormFieldArray['type']) && !is_array($flexFormFieldArray['config']))
52  ) {
53  continue;
54  }
55 
56  if ($flexFormFieldArray['type'] === 'array') {
57  // Section
58  if (empty($flexFormFieldArray['section'])) {
59  $resultArray['html'] = LF . 'Section expected at ' . $flexFormFieldName . ' but not found';
60  continue;
61  }
62 
63  $options = ‪$this->data;
64  $options['flexFormDataStructureArray'] = $flexFormFieldArray;
65  $options['flexFormRowData'] = $flexFormRowData[$flexFormFieldName]['el'] ?? [];
66  $options['flexFormFieldName'] = $flexFormFieldName;
67  $options['renderType'] = 'flexFormSectionContainer';
68  $sectionContainerResult = $this->nodeFactory->create($options)->render();
69  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $sectionContainerResult);
70  } else {
71  // Set up options for single element
72  $fakeParameterArray = [
73  'fieldConf' => [
74  'label' => $languageService->sL(trim($flexFormFieldArray['label'])),
75  'config' => $flexFormFieldArray['config'],
76  'children' => $flexFormFieldArray['children'],
77  'onChange' => $flexFormFieldArray['onChange'],
78  ],
79  'fieldChangeFunc' => $parameterArray['fieldChangeFunc'],
80  'label' => $parameterArray['label'],
81  ];
82 
83  if (isset($flexFormFieldArray['description']) && !empty($flexFormFieldArray['description'])) {
84  $fakeParameterArray['fieldConf']['description'] = $flexFormFieldArray['description'];
85  }
86 
87  $alertMsgOnChange = '';
88  if (isset($fakeParameterArray['fieldConf']['onChange']) && $fakeParameterArray['fieldConf']['onChange'] === 'reload') {
90  $alertMsgOnChange = 'top.TYPO3.Modal.confirm('
91  . 'TYPO3.lang["FormEngine.refreshRequiredTitle"],'
92  . ' TYPO3.lang["FormEngine.refreshRequiredContent"]'
93  . ')'
94  . '.on('
95  . '"button.clicked",'
96  . ' function(e) { if (e.target.name == "ok" && TBE_EDITOR.checkSubmit(-1)) { TBE_EDITOR.submitForm() } top.TYPO3.Modal.dismiss(); }'
97  . ');';
98  } else {
99  $alertMsgOnChange = 'if (TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm();}';
100  }
101  }
102  if ($alertMsgOnChange) {
103  $fakeParameterArray['fieldChangeFunc']['alert'] = $alertMsgOnChange;
104  }
105 
106  $originalFieldName = $parameterArray['itemFormElName'];
107  $fakeParameterArray['itemFormElName'] = $parameterArray['itemFormElName'] . $flexFormFormPrefix . '[' . $flexFormFieldName . '][vDEF]';
108  if ($fakeParameterArray['itemFormElName'] !== $originalFieldName) {
109  // If calculated itemFormElName is different from originalFieldName
110  // change the originalFieldName in TBE_EDITOR_fieldChanged. This is
111  // especially relevant for wizards writing their content back to hidden fields
112  if (!empty($fakeParameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged'])) {
113  $fakeParameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = str_replace($originalFieldName, $fakeParameterArray['itemFormElName'], $fakeParameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged']);
114  }
115  }
116  $fakeParameterArray['itemFormElID'] = $parameterArray['itemFormElID'] . '_' . preg_replace('/[^a-zA-Z0-9_-]/', '_', $flexFormFieldName) . '_' . md5($fakeParameterArray['itemFormElName']);
117  if (isset($flexFormRowData[$flexFormFieldName]['vDEF'])) {
118  $fakeParameterArray['itemFormElValue'] = $flexFormRowData[$flexFormFieldName]['vDEF'];
119  } else {
120  $fakeParameterArray['itemFormElValue'] = $fakeParameterArray['fieldConf']['config']['default'];
121  }
122 
123  $options = ‪$this->data;
124  // Set either flexFormFieldName or flexFormContainerFieldName, depending on if we are a "regular" field or a flex container section field
125  if (empty($options['flexFormFieldName'])) {
126  $options['flexFormFieldName'] = $flexFormFieldName;
127  } else {
128  $options['flexFormContainerFieldName'] = $flexFormFieldName;
129  }
130  $options['parameterArray'] = $fakeParameterArray;
131  $options['elementBaseName'] = $this->data['elementBaseName'] . $flexFormFormPrefix . '[' . $flexFormFieldName . '][vDEF]';
132 
133  if (!empty($flexFormFieldArray['config']['renderType'])) {
134  $options['renderType'] = $flexFormFieldArray['config']['renderType'];
135  } else {
136  // Fallback to type if no renderType is given
137  $options['renderType'] = $flexFormFieldArray['config']['type'];
138  }
139  $childResult = $this->nodeFactory->create($options)->render();
140 
141  if (!empty($childResult['html'])) {
142  // Possible line breaks in the label through xml: \n => <br/>, usage of nl2br() not possible, so it's done through str_replace (?!)
143  $processedTitle = str_replace('\\n', '<br />', htmlspecialchars($fakeParameterArray['fieldConf']['label']));
144  $html = [];
145  $html[] = '<div class="form-section">';
146  $html[] = '<div class="form-group t3js-formengine-palette-field t3js-formengine-validation-marker">';
147  $html[] = '<label class="t3js-formengine-label">';
148  $html[] = ‪BackendUtility::wrapInHelp($parameterArray['_cshKey'], $flexFormFieldName, $processedTitle);
149  $html[] = '</label>';
150  $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
151  $html[] = $childResult['html'];
152  $html[] = '</div>';
153  $html[] = '</div>';
154  $html[] = '</div>';
155  $resultArray['html'] .= implode(LF, $html);
156  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $childResult, false);
157  }
158  }
159  }
160 
161  return $resultArray;
162  }
163 
167  protected function ‪getLanguageService()
168  {
169  return ‪$GLOBALS['LANG'];
170  }
171 
175  protected function ‪getBackendUserAuthentication()
176  {
177  return ‪$GLOBALS['BE_USER'];
178  }
179 }
‪TYPO3\CMS\Backend\Form\AbstractNode\mergeChildReturnIntoExistingResult
‪array mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
Definition: AbstractNode.php:115
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:88
‪TYPO3\CMS\Backend\Form\Container\FlexFormElementContainer\render
‪array render()
Definition: FlexFormElementContainer.php:37
‪TYPO3\CMS\Backend\Form\Container
Definition: AbstractContainer.php:2
‪TYPO3\CMS\Backend\Utility\BackendUtility\wrapInHelp
‪static string wrapInHelp($table, $field, $text='', array $overloadHelpText=[])
Definition: BackendUtility.php:2519
‪TYPO3\CMS\Backend\Form\AbstractNode\$data
‪array $data
Definition: AbstractNode.php:40
‪TYPO3\CMS\Backend\Form\Container\AbstractContainer
Definition: AbstractContainer.php:27
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Form\Container\FlexFormElementContainer\getBackendUserAuthentication
‪BackendUserAuthentication getBackendUserAuthentication()
Definition: FlexFormElementContainer.php:175
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Core\Type\Bitmask\JsConfirmation\TYPE_CHANGE
‪const TYPE_CHANGE
Definition: JsConfirmation.php:28
‪TYPO3\CMS\Backend\Form\Container\FlexFormElementContainer
Definition: FlexFormElementContainer.php:31
‪TYPO3\CMS\Core\Type\Bitmask\JsConfirmation
Definition: JsConfirmation.php:24
‪TYPO3\CMS\Backend\Form\Container\FlexFormElementContainer\getLanguageService
‪LanguageService getLanguageService()
Definition: FlexFormElementContainer.php:167