TYPO3 CMS  TYPO3_8-7
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  $table = $this->data['tableName'];
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  foreach ($flexFormDataStructureArray as $flexFormFieldName => $flexFormFieldArray) {
48  if (
49  // No item array found at all
50  !is_array($flexFormFieldArray)
51  // Not a section or container and not a list of single items
52  || (!isset($flexFormFieldArray['type']) && !is_array($flexFormFieldArray['config']))
53  ) {
54  continue;
55  }
56 
57  if ($flexFormFieldArray['type'] === 'array') {
58  // Section
59  if (empty($flexFormFieldArray['section'])) {
60  $resultArray['html'] = LF . 'Section expected at ' . $flexFormFieldName . ' but not found';
61  continue;
62  }
63 
64  $options = $this->data;
65  $options['flexFormDataStructureArray'] = $flexFormFieldArray;
66  $options['flexFormRowData'] = isset($flexFormRowData[$flexFormFieldName]['el']) ? $flexFormRowData[$flexFormFieldName]['el'] : [];
67  $options['flexFormFieldName'] = $flexFormFieldName;
68  $options['renderType'] = 'flexFormSectionContainer';
69  $sectionContainerResult = $this->nodeFactory->create($options)->render();
70  $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $sectionContainerResult);
71  } else {
72  // Set up options for single element
73  $fakeParameterArray = [
74  'fieldConf' => [
75  'label' => $languageService->sL(trim($flexFormFieldArray['label'])),
76  'config' => $flexFormFieldArray['config'],
77  'children' => $flexFormFieldArray['children'],
78  'onChange' => $flexFormFieldArray['onChange'],
79  ],
80  'fieldChangeFunc' => $parameterArray['fieldChangeFunc'],
81  'label' => $parameterArray['label'],
82  ];
83 
84  $alertMsgOnChange = '';
85  if (isset($fakeParameterArray['fieldConf']['onChange']) && $fakeParameterArray['fieldConf']['onChange'] === 'reload') {
86  if ($this->getBackendUserAuthentication()->jsConfirmation(JsConfirmation::TYPE_CHANGE)) {
87  $alertMsgOnChange = 'top.TYPO3.Modal.confirm('
88  . 'TYPO3.lang["FormEngine.refreshRequiredTitle"],'
89  . ' TYPO3.lang["FormEngine.refreshRequiredContent"]'
90  . ')'
91  . '.on('
92  . '"button.clicked",'
93  . ' function(e) { if (e.target.name == "ok" && TBE_EDITOR.checkSubmit(-1)) { TBE_EDITOR.submitForm() } top.TYPO3.Modal.dismiss(); }'
94  . ');';
95  } else {
96  $alertMsgOnChange = 'if (TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm();}';
97  }
98  }
99  if ($alertMsgOnChange) {
100  $fakeParameterArray['fieldChangeFunc']['alert'] = $alertMsgOnChange;
101  }
102 
103  $originalFieldName = $parameterArray['itemFormElName'];
104  $fakeParameterArray['itemFormElName'] = $parameterArray['itemFormElName'] . $flexFormFormPrefix . '[' . $flexFormFieldName . '][vDEF]';
105  if ($fakeParameterArray['itemFormElName'] !== $originalFieldName) {
106  // If calculated itemFormElName is different from originalFieldName
107  // change the originalFieldName in TBE_EDITOR_fieldChanged. This is
108  // especially relevant for wizards writing their content back to hidden fields
109  if (!empty($fakeParameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged'])) {
110  $fakeParameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = str_replace($originalFieldName, $fakeParameterArray['itemFormElName'], $fakeParameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged']);
111  }
112  }
113  $fakeParameterArray['itemFormElID'] = $parameterArray['itemFormElID'] . '_' . preg_replace('/[^a-zA-Z0-9_-]/', '_', $flexFormFieldName);
114  if (isset($flexFormRowData[$flexFormFieldName]['vDEF'])) {
115  $fakeParameterArray['itemFormElValue'] = $flexFormRowData[$flexFormFieldName]['vDEF'];
116  } else {
117  $fakeParameterArray['itemFormElValue'] = $fakeParameterArray['fieldConf']['config']['default'];
118  }
119 
120  $options = $this->data;
121  // Set either flexFormFieldName or flexFormContainerFieldName, depending on if we are a "regular" field or a flex container section field
122  if (empty($options['flexFormFieldName'])) {
123  $options['flexFormFieldName'] = $flexFormFieldName;
124  } else {
125  $options['flexFormContainerFieldName'] = $flexFormFieldName;
126  }
127  $options['parameterArray'] = $fakeParameterArray;
128  $options['elementBaseName'] = $this->data['elementBaseName'] . $flexFormFormPrefix . '[' . $flexFormFieldName . '][vDEF]';
129 
130  if (!empty($flexFormFieldArray['config']['renderType'])) {
131  $options['renderType'] = $flexFormFieldArray['config']['renderType'];
132  } else {
133  // Fallback to type if no renderType is given
134  $options['renderType'] = $flexFormFieldArray['config']['type'];
135  }
136  $childResult = $this->nodeFactory->create($options)->render();
137 
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[] = '</label>';
146  $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
147  $html[] = $childResult['html'];
148  $html[] = '</div>';
149  $html[] = '</div>';
150  $html[] = '</div>';
151 
152  $resultArray['html'] .= implode(LF, $html);
153  $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childResult, false);
154  }
155  }
156 
157  return $resultArray;
158  }
159 
163  protected function getLanguageService()
164  {
165  return $GLOBALS['LANG'];
166  }
167 
171  protected function getBackendUserAuthentication()
172  {
173  return $GLOBALS['BE_USER'];
174  }
175 }
mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']