be5a0899210a2bc502a896a21a1c2e305327eee1
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / Element / FlexElement.php
1 <?php
2 namespace TYPO3\CMS\Backend\Form\Element;
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
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Backend\Utility\IconUtility;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20
21 /**
22 * Generation of TCEform elements of the type "flexform"
23 */
24 class FlexElement extends AbstractFormElement {
25
26 /**
27 * Handler for Flex Forms
28 *
29 * @param string $table The table name of the record
30 * @param string $field The field name which this element is supposed to edit
31 * @param array $row The record data array where the value(s) for the field can be found
32 * @param array $additionalInformation An array with additional configuration options.
33 * @return string The HTML code for the TCEform field
34 */
35 public function render($table, $field, $row, &$additionalInformation) {
36 // Data Structure:
37 $dataStructArray = BackendUtility::getFlexFormDS($additionalInformation['fieldConf']['config'], $row, $table, $field);
38 $item = '';
39 // Manipulate Flexform DS via TSConfig and group access lists
40 if (is_array($dataStructArray)) {
41 $flexFormHelper = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Form\FlexFormsHelper::class);
42 $dataStructArray = $flexFormHelper->modifyFlexFormDS($dataStructArray, $table, $field, $row, $additionalInformation['fieldConf']);
43 unset($flexFormHelper);
44 }
45 // Get data structure:
46 if (is_array($dataStructArray)) {
47 $languageService = $this->getLanguageService();
48 // Get data:
49 $xmlData = $additionalInformation['itemFormElValue'];
50 $xmlHeaderAttributes = GeneralUtility::xmlGetHeaderAttribs($xmlData);
51 $storeInCharset = strtolower($xmlHeaderAttributes['encoding']);
52 if ($storeInCharset) {
53 $currentCharset = $languageService->charSet;
54 $xmlData = $languageService->csConvObj->conv($xmlData, $storeInCharset, $currentCharset, 1);
55 }
56 $editData = GeneralUtility::xml2array($xmlData);
57 // Must be XML parsing error...
58 if (!is_array($editData)) {
59 $editData = array();
60 } elseif (!isset($editData['meta']) || !is_array($editData['meta'])) {
61 $editData['meta'] = array();
62 }
63 // Find the data structure if sheets are found:
64 $sheet = $editData['meta']['currentSheetId'] ? $editData['meta']['currentSheetId'] : 'sDEF';
65 // Sheet to display
66 // Create language menu:
67 $langChildren = $dataStructArray['meta']['langChildren'] ? 1 : 0;
68 $langDisabled = $dataStructArray['meta']['langDisable'] ? 1 : 0;
69 $editData['meta']['currentLangId'] = array();
70 // Look up page overlays:
71 $checkPageLanguageOverlay = $this->getBackendUserAuthentication()->getTSConfigVal('options.checkPageLanguageOverlay') ? TRUE : FALSE;
72 if ($checkPageLanguageOverlay) {
73 $where_clause = 'pid=' . (int)$row['pid'] . BackendUtility::deleteClause('pages_language_overlay')
74 . BackendUtility::versioningPlaceholderClause('pages_language_overlay');
75 $pageOverlays = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'pages_language_overlay', $where_clause, '', '', '', 'sys_language_uid');
76 }
77 $languages = $this->formEngine->getAvailableLanguages();
78 foreach ($languages as $lInfo) {
79 if (
80 $this->getBackendUserAuthentication()->checkLanguageAccess($lInfo['uid'])
81 && (!$checkPageLanguageOverlay || $lInfo['uid'] <= 0 || is_array($pageOverlays[$lInfo['uid']]))
82 ) {
83 $editData['meta']['currentLangId'][] = $lInfo['ISOcode'];
84 }
85 }
86 if (!is_array($editData['meta']['currentLangId']) || !count($editData['meta']['currentLangId'])) {
87 $editData['meta']['currentLangId'] = array('DEF');
88 }
89 $editData['meta']['currentLangId'] = array_unique($editData['meta']['currentLangId']);
90 $additionalInformation['_noEditDEF'] = FALSE;
91 if ($langChildren || $langDisabled) {
92 $rotateLang = array('DEF');
93 } else {
94 if (!in_array('DEF', $editData['meta']['currentLangId'])) {
95 array_unshift($editData['meta']['currentLangId'], 'DEF');
96 $additionalInformation['_noEditDEF'] = TRUE;
97 }
98 $rotateLang = $editData['meta']['currentLangId'];
99 }
100 // Tabs sheets
101 if (is_array($dataStructArray['sheets'])) {
102 $tabsToTraverse = array_keys($dataStructArray['sheets']);
103 } else {
104 $tabsToTraverse = array($sheet);
105 }
106
107 $this->getControllerDocumentTemplate()->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/FormEngineFlexForm');
108
109 /** @var $elementConditionMatcher \TYPO3\CMS\Backend\Form\ElementConditionMatcher */
110 $elementConditionMatcher = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Form\ElementConditionMatcher::class);
111
112 foreach ($rotateLang as $lKey) {
113 if (!$langChildren && !$langDisabled) {
114 $item .= '<strong>' . $this->formEngine->getLanguageIcon($table, $row, ('v' . $lKey)) . $lKey . ':</strong>';
115 }
116 // Default language, other options are "lUK" or whatever country code (independent of system!!!)
117 $lang = 'l' . $lKey;
118 $tabParts = array();
119 $sheetContent = '';
120 foreach ($tabsToTraverse as $sheet) {
121 list($dataStruct, $sheet) = GeneralUtility::resolveSheetDefInDS($dataStructArray, $sheet);
122 // If sheet has displayCond
123 if ($dataStruct['ROOT']['TCEforms']['displayCond']) {
124 $splitCondition = GeneralUtility::trimExplode(':', $dataStruct['ROOT']['TCEforms']['displayCond']);
125 $skipCondition = FALSE;
126 $fakeRow = array();
127 switch ($splitCondition[0]) {
128 case 'FIELD':
129 list($sheetName, $fieldName) = GeneralUtility::trimExplode('.', $splitCondition[1]);
130 $fieldValue = $editData['data'][$sheetName][$lang][$fieldName];
131 $splitCondition[1] = $fieldName;
132 $dataStruct['ROOT']['TCEforms']['displayCond'] = join(':', $splitCondition);
133 $fakeRow = array($fieldName => $fieldValue);
134 break;
135 case 'HIDE_FOR_NON_ADMINS':
136
137 case 'VERSION':
138
139 case 'HIDE_L10N_SIBLINGS':
140
141 case 'EXT':
142 break;
143 case 'REC':
144 $fakeRow = array('uid' => $row['uid']);
145 break;
146 default:
147 $skipCondition = TRUE;
148 }
149 $displayConditionResult = TRUE;
150 if ($dataStruct['ROOT']['TCEforms']['displayCond']) {
151 $displayConditionResult = $elementConditionMatcher->match($dataStruct['ROOT']['TCEforms']['displayCond'], $fakeRow, 'vDEF');
152 }
153 // If sheets displayCond leads to false
154 if (!$skipCondition && !$displayConditionResult) {
155 // Don't create this sheet
156 continue;
157 }
158 }
159 // Render sheet:
160 if (is_array($dataStruct['ROOT']) && is_array($dataStruct['ROOT']['el'])) {
161 // Default language, other options are "lUK" or whatever country code (independent of system!!!)
162 $additionalInformation['_valLang'] = $langChildren && !$langDisabled ? $editData['meta']['currentLangId'] : 'DEF';
163 $additionalInformation['_lang'] = $lang;
164 // Assemble key for loading the correct CSH file
165 $dsPointerFields = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['columns'][$field]['config']['ds_pointerField'], TRUE);
166 $additionalInformation['_cshKey'] = $table . '.' . $field;
167 foreach ($dsPointerFields as $key) {
168 $additionalInformation['_cshKey'] .= '.' . $row[$key];
169 }
170 // Push the sheet level tab to DynNestedStack
171 $tabIdentString = '';
172 if (is_array($dataStructArray['sheets'])) {
173 $tabIdentString = $this->getDocumentTemplate()->getDynTabMenuId('TCEFORMS:flexform:' . $additionalInformation['itemFormElName'] . $additionalInformation['_lang']);
174 $this->formEngine->pushToDynNestedStack('tab', $tabIdentString . '-' . (count($tabParts) + 1));
175 }
176 // Render flexform:
177 $tRows = $this->getSingleField_typeFlex_draw($dataStruct['ROOT']['el'], $editData['data'][$sheet][$lang], $table, $field, $row, $additionalInformation, '[data][' . $sheet . '][' . $lang . ']');
178 $sheetContent = '<div class="typo3-TCEforms-flexForm t3-form-flexform">' . $tRows . '</div>';
179 // Pop the sheet level tab from DynNestedStack
180 if (is_array($dataStructArray['sheets'])) {
181 $this->formEngine->popFromDynNestedStack('tab', $tabIdentString . '-' . (count($tabParts) + 1));
182 }
183 } else {
184 $sheetContent = 'Data Structure ERROR: No ROOT element found for sheet "' . $sheet . '".';
185 }
186 // Add to tab:
187 $tabParts[] = array(
188 'label' => $dataStruct['ROOT']['TCEforms']['sheetTitle'] ? $languageService->sL($dataStruct['ROOT']['TCEforms']['sheetTitle']) : $sheet,
189 'description' => $dataStruct['ROOT']['TCEforms']['sheetDescription'] ? $languageService->sL($dataStruct['ROOT']['TCEforms']['sheetDescription']) : '',
190 'linkTitle' => $dataStruct['ROOT']['TCEforms']['sheetShortDescr'] ? $languageService->sL($dataStruct['ROOT']['TCEforms']['sheetShortDescr']) : '',
191 'content' => $sheetContent
192 );
193 }
194 if (is_array($dataStructArray['sheets'])) {
195 $item .= $this->formEngine->getDynTabMenu($tabParts, 'TCEFORMS:flexform:' . $additionalInformation['itemFormElName'] . $additionalInformation['_lang']);
196 } else {
197 $item .= $sheetContent;
198 }
199 }
200 } else {
201 $item = 'Data Structure ERROR: ' . $dataStructArray;
202 }
203 return $item;
204 }
205
206
207 /**
208 * Recursive rendering of flexforms
209 *
210 * @param array $dataStruct (part of) Data Structure for which to render. Keys on first level is flex-form fields
211 * @param array $editData (part of) Data array of flexform corresponding to the input DS. Keys on first level is flex-form field names
212 * @param string $table Table name, eg. tt_content
213 * @param string $field Field name, eg. tx_templavoila_flex
214 * @param array $row The particular record from $table in which the field $field is found
215 * @param array $PA Array of standard information for rendering of a form field in TCEforms, see other rendering functions too
216 * @param string $formPrefix Form field prefix, eg. "[data][sDEF][lDEF][...][...]
217 * @param int $level Indicates nesting level for the function call
218 * @param string $idPrefix Prefix for ID-values
219 * @param bool $toggleClosed Defines whether the next flexform level is open or closed. Comes from _TOGGLE pseudo field in FlexForm xml.
220 * @return string HTMl code for form.
221 */
222 public function getSingleField_typeFlex_draw($dataStruct, $editData, $table, $field, $row, &$PA, $formPrefix = '', $level = 0, $idPrefix = 'ID', $toggleClosed = FALSE) {
223 $output = '';
224 $mayRestructureFlexforms = $this->getBackendUserAuthentication()->checkLanguageAccess(0);
225 // Data Structure array must be ... and array of course...
226 if (is_array($dataStruct)) {
227 $languageService = $this->getLanguageService();
228 foreach ($dataStruct as $key => $value) {
229 // Traversing fields in structure:
230 if (is_array($value)) {
231 // The value of each entry must be an array.
232 // ********************
233 // Making the row:
234 // ********************
235 // Title of field:
236 // <title>LLL:EXT:cms/locallang_ttc.xml:media.sources</title>
237 $theTitle = $value['title'];
238
239 // If there is a title, check for LLL label
240 if (strlen($theTitle) > 0) {
241 $theTitle = htmlspecialchars(GeneralUtility::fixed_lgd_cs($languageService->sL($theTitle),
242 (int)$this->getBackendUserAuthentication()->uc['titleLen']));
243 }
244 // If it's a "section" or "container":
245 if ($value['type'] == 'array') {
246 // Creating IDs for form fields:
247 // It's important that the IDs "cascade" - otherwise we can't dynamically expand the flex form
248 // because this relies on simple string substitution of the first parts of the id values.
249 // This is a suffix used for forms on this level
250 $thisId = GeneralUtility::shortMd5(uniqid('id', TRUE));
251 // $idPrefix is the prefix for elements on lower levels in the hierarchy and we combine this
252 // with the thisId value to form a new ID on this level.
253 $idTagPrefix = $idPrefix . '-' . $thisId;
254 // If it's a "section" containing other elements:
255 if ($value['section']) {
256 // Load script.aculo.us if flexform sections can be moved by drag'n'drop:
257 $this->getControllerDocumentTemplate()->getPageRenderer()->loadScriptaculous();
258 // Render header of section:
259 $output .= '<div class="t3-form-field-label-flexsection"><strong>' . $theTitle . '</strong></div>';
260 // Render elements in data array for section:
261 $tRows = array();
262 if (is_array($editData[$key]['el'])) {
263 foreach ($editData[$key]['el'] as $k3 => $v3) {
264 $cc = $k3;
265 if (is_array($v3)) {
266 $theType = key($v3);
267 $theDat = $v3[$theType];
268 $newSectionEl = $value['el'][$theType];
269 if (is_array($newSectionEl)) {
270 $tRows[] = $this->getSingleField_typeFlex_draw(array($theType => $newSectionEl),
271 array($theType => $theDat), $table, $field, $row, $PA,
272 $formPrefix . '[' . $key . '][el][' . $cc . ']', $level + 1,
273 $idTagPrefix, $v3['_TOGGLE']);
274 }
275 }
276 }
277 }
278 // Now, we generate "templates" for new elements that could be added to this section
279 // by traversing all possible types of content inside the section:
280 // We have to handle the fact that requiredElements and such may be set during this
281 // rendering process and therefore we save and reset the state of some internal variables
282 // ... little crude, but works...
283 // Preserving internal variables we don't want to change:
284 $TEMP_requiredElements = $this->formEngine->requiredElements;
285 // Traversing possible types of new content in the section:
286 $newElementsLinks = array();
287 foreach ($value['el'] as $nnKey => $nCfg) {
288 $additionalJS_post_saved = $this->formEngine->additionalJS_post;
289 $this->formEngine->additionalJS_post = array();
290 $additionalJS_submit_saved = $this->formEngine->additionalJS_submit;
291 $this->formEngine->additionalJS_submit = array();
292 $newElementTemplate = $this->getSingleField_typeFlex_draw(array($nnKey => $nCfg),
293 array(), $table, $field, $row, $PA,
294 $formPrefix . '[' . $key . '][el][' . $idTagPrefix . '-form]', $level + 1,
295 $idTagPrefix);
296 // Makes a "Add new" link:
297 $var = str_replace('.', '', uniqid('idvar', TRUE));
298 $replace = 'replace(/' . $idTagPrefix . '-/g,"' . $idTagPrefix . '-"+' . $var . '+"-")';
299 $replace .= '.replace(/(tceforms-(datetime|date)field-)/g,"$1" + (new Date()).getTime())';
300 $onClickInsert = 'var ' . $var . ' = "' . 'idx"+(new Date()).getTime();'
301 // Do not replace $isTagPrefix in setActionStatus() because it needs section id!
302 . 'new Insertion.Bottom($("' . $idTagPrefix . '"), ' . json_encode($newElementTemplate)
303 . '.' . $replace . '); TYPO3.jQuery("#' . $idTagPrefix . '").t3FormEngineFlexFormElement();'
304 . 'eval(unescape("' . rawurlencode(implode(';', $this->formEngine->additionalJS_post)) . '").' . $replace . ');'
305 . 'TBE_EDITOR.addActionChecks("submit", unescape("'
306 . rawurlencode(implode(';', $this->formEngine->additionalJS_submit)) . '").' . $replace . ');'
307 . 'TYPO3.TCEFORMS.update();'
308 . 'return false;';
309 // Kasper's comment (kept for history):
310 // Maybe there is a better way to do this than store the HTML for the new element
311 // in rawurlencoded format - maybe it even breaks with certain charsets?
312 // But for now this works...
313 $this->formEngine->additionalJS_post = $additionalJS_post_saved;
314 $this->formEngine->additionalJS_submit = $additionalJS_submit_saved;
315 $title = '';
316 if (isset($nCfg['title'])) {
317 $title = $languageService->sL($nCfg['title']);
318 }
319 $newElementsLinks[] = '<a href="#" onclick="' . htmlspecialchars($onClickInsert) . '">'
320 . IconUtility::getSpriteIcon('actions-document-new')
321 . htmlspecialchars(GeneralUtility::fixed_lgd_cs($title, 30)) . '</a>';
322 }
323 // Reverting internal variables we don't want to change:
324 $this->formEngine->requiredElements = $TEMP_requiredElements;
325 // Adding the sections
326
327 // add the "toggle all" button for the sections
328 $toggleAll = $languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.toggleall', TRUE);
329 $output .= '
330 <div class="t3-form-field-toggle-flexsection t3-form-flexsection-toggle">
331 <a href="#">'. IconUtility::getSpriteIcon('actions-move-right', array('title' => $toggleAll)) . $toggleAll . '</a>
332 </div>
333 <div id="' . $idTagPrefix . '" class="t3-form-field-container-flexsection t3-flex-container" data-t3-flex-allow-restructure="' . ($mayRestructureFlexforms ? 1 : 0) . '">' . implode('', $tRows) . '</div>';
334
335 // add the "new" link
336 if ($mayRestructureFlexforms) {
337 $output .= '<div class="t3-form-field-add-flexsection"><strong>'
338 . $languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.addnew', TRUE)
339 . ':</strong> ' . implode(' | ', $newElementsLinks) . '</div>';
340 }
341
342 $output = '<div class="t3-form-field-container t3-form-flex">' . $output . '</div>';
343 } else {
344 // It is a container of a single section
345 $toggleIconOpenState = ($toggleClosed ? 'display: none;' : '');
346 $toggleIconCloseState = (!$toggleClosed ? 'display: none;' : '');
347
348 $toggleIcons = IconUtility::getSpriteIcon('actions-move-down', array('class' => 't3-flex-control-toggle-icon-open', 'style' => $toggleIconOpenState));
349 $toggleIcons .= IconUtility::getSpriteIcon('actions-move-right', array('class' => 't3-flex-control-toggle-icon-close', 'style' => $toggleIconCloseState));
350
351 // Notice: Creating "new" elements after others seemed to be too difficult to do
352 // and since moving new elements created in the bottom is now so easy
353 // with drag'n'drop I didn't see the need.
354 // Putting together header of a section. Sections can be removed, copied, opened/closed, moved up and down:
355 // I didn't know how to make something right-aligned without a table, so I put it in a table.
356 // can be made into <div>'s if someone like to.
357 // Notice: The fact that I make a "Sortable.create" right onmousedown is that if we
358 // initialize this when rendering the form in PHP new and copied elements will not
359 // be possible to move as a sortable. But this way a new sortable is initialized every time
360 // someone tries to move and it will always work.
361 $ctrlHeader = '
362 <div class="pull-left">
363 <a href="#" class="t3-flex-control-toggle-button">' . $toggleIcons . '</a>
364 <span class="t3-record-title">' . $theTitle . '</span>
365 </div>';
366
367 if ($mayRestructureFlexforms) {
368 $ctrlHeader .= '<div class="pull-right">'
369 . IconUtility::getSpriteIcon('actions-move-move', array('title' => 'Drag to Move', 'class' => 't3-js-sortable-handle'))
370 . IconUtility::getSpriteIcon('actions-edit-delete', array('title' => 'Delete', 'class' => 't3-delete'))
371 . '</div>';
372 }
373
374 $ctrlHeader = '<div class="t3-form-field-header-flexsection t3-flex-section-header">' . $ctrlHeader . '</div>';
375
376 $s = GeneralUtility::revExplode('[]', $formPrefix, 2);
377 $actionFieldName = '_ACTION_FLEX_FORM' . $PA['itemFormElName'] . $s[0] . '][_ACTION][' . $s[1];
378 // Push the container to DynNestedStack as it may be toggled
379 $this->formEngine->pushToDynNestedStack('flex', $idTagPrefix);
380 // Putting together the container:
381 $this->formEngine->additionalJS_delete = array();
382 $singleField_typeFlex_draw = $this->getSingleField_typeFlex_draw($value['el'],
383 $editData[$key]['el'], $table, $field, $row, $PA,
384 ($formPrefix . '[' . $key . '][el]'), ($level + 1), $idTagPrefix);
385 $output .= '
386 <div id="' . $idTagPrefix . '" class="t3-form-field-container-flexsections t3-flex-section">
387 <input class="t3-flex-control t3-flex-control-action" type="hidden" name="' . htmlspecialchars($actionFieldName) . '" value=""/>
388
389 ' . $ctrlHeader . '
390 <div class="t3-form-field-record-flexsection t3-flex-section-content"'
391 . ($toggleClosed ? ' style="display:none;"' : '') . '>' . $singleField_typeFlex_draw . '
392 </div>
393 <input class="t3-flex-control t3-flex-control-toggle" id="' . $idTagPrefix . '-toggleClosed" type="hidden" name="'
394 . htmlspecialchars('data[' . $table . '][' . $row['uid'] . '][' . $field . ']' . $formPrefix . '[_TOGGLE]')
395 . '" value="' . ($toggleClosed ? 1 : 0) . '" />
396 </div>';
397 $output = str_replace('/*###REMOVE###*/', GeneralUtility::slashJS(htmlspecialchars(implode('', $this->formEngine->additionalJS_delete))), $output);
398 // NOTICE: We are saving the toggle-state directly in the flexForm XML and "unauthorized"
399 // according to the data structure. It means that flexform XML will report unclean and
400 // a cleaning operation will remove the recorded togglestates. This is not a fatal problem.
401 // Ideally we should save the toggle states in meta-data but it is much harder to do that.
402 // And this implementation was easy to make and with no really harmful impact.
403 // Pop the container from DynNestedStack
404 $this->formEngine->popFromDynNestedStack('flex', $idTagPrefix);
405 }
406 } elseif (is_array($value['TCEforms']['config'])) {
407 // Rendering a single form element:
408 if (is_array($PA['_valLang'])) {
409 $rotateLang = $PA['_valLang'];
410 } else {
411 $rotateLang = array($PA['_valLang']);
412 }
413 $conditionData = is_array($editData) ? $editData : array();
414 // Add current $row to data processed by \TYPO3\CMS\Backend\Form\ElementConditionMatcher
415 $conditionData['parentRec'] = $row;
416 $tRows = array();
417
418 /** @var $elementConditionMatcher \TYPO3\CMS\Backend\Form\ElementConditionMatcher */
419 $elementConditionMatcher = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Form\ElementConditionMatcher::class);
420
421 foreach ($rotateLang as $vDEFkey) {
422 $vDEFkey = 'v' . $vDEFkey;
423 $displayConditionResult = TRUE;
424 if ($value['TCEforms']['displayCond']) {
425 $displayConditionResult = $elementConditionMatcher->match($value['TCEforms']['displayCond'], $conditionData, $vDEFkey);
426 }
427 if ($displayConditionResult) {
428 $fakePA = array();
429 $fakePA['fieldConf'] = array(
430 'label' => $languageService->sL(trim($value['TCEforms']['label'])),
431 'config' => $value['TCEforms']['config'],
432 'defaultExtras' => $value['TCEforms']['defaultExtras'],
433 'onChange' => $value['TCEforms']['onChange']
434 );
435 if ($PA['_noEditDEF'] && $PA['_lang'] === 'lDEF') {
436 $fakePA['fieldConf']['config'] = array(
437 'type' => 'none',
438 'rows' => 2
439 );
440 }
441 if (
442 $fakePA['fieldConf']['onChange'] === 'reload'
443 || !empty($GLOBALS['TCA'][$table]['ctrl']['type'])
444 && (string)$key === $GLOBALS['TCA'][$table]['ctrl']['type']
445 || !empty($GLOBALS['TCA'][$table]['ctrl']['requestUpdate'])
446 && GeneralUtility::inList($GLOBALS['TCA'][$table]['ctrl']['requestUpdate'], $key)
447 ) {
448 if ($this->getBackendUserAuthentication()->jsConfirmation(1)) {
449 $alertMsgOnChange = 'if (confirm(TBE_EDITOR.labels.onChangeAlert) && TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm() };';
450 } else {
451 $alertMsgOnChange = 'if(TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm();}';
452 }
453 } else {
454 $alertMsgOnChange = '';
455 }
456 $fakePA['fieldChangeFunc'] = $PA['fieldChangeFunc'];
457 if (strlen($alertMsgOnChange)) {
458 $fakePA['fieldChangeFunc']['alert'] = $alertMsgOnChange;
459 }
460 $fakePA['onFocus'] = $PA['onFocus'];
461 $fakePA['label'] = $PA['label'];
462 $fakePA['itemFormElName'] = $PA['itemFormElName'] . $formPrefix . '[' . $key . '][' . $vDEFkey . ']';
463 $fakePA['itemFormElName_file'] = $PA['itemFormElName_file'] . $formPrefix . '[' . $key . '][' . $vDEFkey . ']';
464 $fakePA['itemFormElID'] = $fakePA['itemFormElName'];
465 if (isset($editData[$key][$vDEFkey])) {
466 $fakePA['itemFormElValue'] = $editData[$key][$vDEFkey];
467 } else {
468 $fakePA['itemFormElValue'] = $fakePA['fieldConf']['config']['default'];
469 }
470 $theFormEl = $this->formEngine->getSingleField_SW($table, $field, $row, $fakePA);
471 $theTitle = htmlspecialchars($fakePA['fieldConf']['label']);
472 if (!in_array('DEF', $rotateLang)) {
473 $defInfo = '<div class="t3-form-original-language">'
474 . $this->formEngine->getLanguageIcon($table, $row, 0)
475 . $this->formEngine->previewFieldValue($editData[$key]['vDEF'], $fakePA['fieldConf'], $field)
476 . '&nbsp;</div>';
477 } else {
478 $defInfo = '';
479 }
480 if (!$PA['_noEditDEF']) {
481 $prLang = $this->formEngine->getAdditionalPreviewLanguages();
482 foreach ($prLang as $prL) {
483 $defInfo .= '<div class="t3-form-original-language">'
484 . $this->formEngine->getLanguageIcon($table, $row, ('v' . $prL['ISOcode']))
485 . $this->formEngine->previewFieldValue($editData[$key][('v' . $prL['ISOcode'])], $fakePA['fieldConf'], $field)
486 . '&nbsp;</div>';
487 }
488 }
489 $languageIcon = '';
490 if ($vDEFkey != 'vDEF') {
491 $languageIcon = $this->formEngine->getLanguageIcon($table, $row, $vDEFkey);
492 }
493 // Put row together
494 // possible linebreaks in the label through xml: \n => <br/>, usage of nl2br()
495 // not possible, so it's done through str_replace
496 $processedTitle = str_replace('\\n', '<br />', $theTitle);
497 $tRows[] = '<div class="t3-form-field-container t3-form-field-container-flex">'
498 . '<div class="t3-form-field-label t3-form-field-label-flex">' . $languageIcon
499 . BackendUtility::wrapInHelp($PA['_cshKey'], $key, $processedTitle) . '</div>
500 <div class="t3-form-field t3-form-field-flex">' . $theFormEl . $defInfo
501 . $this->formEngine->renderVDEFDiff($editData[$key], $vDEFkey) . '</div>
502 </div>';
503 }
504 }
505 if (count($tRows)) {
506 $output .= implode('', $tRows);
507 }
508 }
509 }
510 }
511 }
512 return $output;
513 }
514 }