TYPO3 CMS  TYPO3_7-6
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 
22 
32 {
38  public function render()
39  {
40  $table = $this->data['tableName'];
41  $flexFormDataStructureArray = $this->data['flexFormDataStructureArray'];
42  $flexFormRowData = $this->data['flexFormRowData'];
43  $flexFormFormPrefix = $this->data['flexFormFormPrefix'];
44  $parameterArray = $this->data['parameterArray'];
45 
46  $languageService = $this->getLanguageService();
47  $resultArray = $this->initializeResultArray();
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'] === 'array') {
59  // Section
60  if (empty($flexFormFieldArray['section'])) {
61  $resultArray['html'] = LF . 'Section expected at ' . $flexFormFieldName . ' but not found';
62  continue;
63  }
64 
65  $sectionTitle = '';
66  if (!empty(trim($flexFormFieldArray['title']))) {
67  $sectionTitle = $languageService->sL(trim($flexFormFieldArray['title']));
68  }
69 
70  $options = $this->data;
71  $options['flexFormDataStructureArray'] = $flexFormFieldArray['el'];
72  $options['flexFormRowData'] = isset($flexFormRowData[$flexFormFieldName]['el']) ? $flexFormRowData[$flexFormFieldName]['el'] : [];
73  $options['flexFormSectionType'] = $flexFormFieldName;
74  $options['flexFormSectionTitle'] = $sectionTitle;
75  $options['renderType'] = 'flexFormSectionContainer';
76  $sectionContainerResult = $this->nodeFactory->create($options)->render();
77  $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $sectionContainerResult);
78  } else {
79  // Set up options for single element
80  $fakeParameterArray = [
81  'fieldConf' => [
82  'label' => $languageService->sL(trim($flexFormFieldArray['label'])),
83  'config' => $flexFormFieldArray['config'],
84  'children' => $flexFormFieldArray['children'],
85  'defaultExtras' => $flexFormFieldArray['defaultExtras'],
86  'onChange' => $flexFormFieldArray['onChange'],
87  ],
88  'fieldChangeFunc' => $parameterArray['fieldChangeFunc'],
89  'onFocus' => $parameterArray['onFocus'],
90  'label' => $parameterArray['label'],
91  ];
92 
93  $alertMsgOnChange = '';
94  if (
95  $fakeParameterArray['fieldConf']['onChange'] === 'reload'
96  || !empty($GLOBALS['TCA'][$table]['ctrl']['type']) && $GLOBALS['TCA'][$table]['ctrl']['type'] === $flexFormFieldName
97  || !empty($GLOBALS['TCA'][$table]['ctrl']['requestUpdate']) && GeneralUtility::inList($GLOBALS['TCA'][$table]['ctrl']['requestUpdate'], $flexFormFieldName)
98  ) {
99  if ($this->getBackendUserAuthentication()->jsConfirmation(JsConfirmation::TYPE_CHANGE)) {
100  $alertMsgOnChange = 'top.TYPO3.Modal.confirm(TBE_EDITOR.labels.refreshRequired.title, TBE_EDITOR.labels.refreshRequired.content).on("button.clicked", function(e) { if (e.target.name == "ok" && TBE_EDITOR.checkSubmit(-1)) { TBE_EDITOR.submitForm() } top.TYPO3.Modal.dismiss(); });';
101  } else {
102  $alertMsgOnChange = 'if (TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm();}';
103  }
104  }
105  if ($alertMsgOnChange) {
106  $fakeParameterArray['fieldChangeFunc']['alert'] = $alertMsgOnChange;
107  }
108 
109  $originalFieldName = $parameterArray['itemFormElName'];
110  $fakeParameterArray['itemFormElName'] = $parameterArray['itemFormElName'] . $flexFormFormPrefix . '[' . $flexFormFieldName . '][vDEF]';
111  if ($fakeParameterArray['itemFormElName'] !== $originalFieldName) {
112  // If calculated itemFormElName is different from originalFieldName
113  // change the originalFieldName in TBE_EDITOR_fieldChanged. This is
114  // especially relevant for wizards writing their content back to hidden fields
115  if (!empty($fakeParameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged'])) {
116  $fakeParameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = str_replace($originalFieldName, $fakeParameterArray['itemFormElName'], $fakeParameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged']);
117  }
118  }
119  $fakeParameterArray['itemFormElID'] = $fakeParameterArray['itemFormElName'];
120  if (isset($flexFormRowData[$flexFormFieldName]['vDEF'])) {
121  $fakeParameterArray['itemFormElValue'] = $flexFormRowData[$flexFormFieldName]['vDEF'];
122  } else {
123  $fakeParameterArray['itemFormElValue'] = $fakeParameterArray['fieldConf']['config']['default'];
124  }
125 
126  $options = $this->data;
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="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  $childResult['html'] = '';
154  $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childResult);
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 }
mergeChildReturnIntoExistingResult(array $existing, array $childReturn)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']