[BUGFIX] Unused TDParams in ColumnsContentObject()
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / FormEngine.php
1 <?php
2 namespace TYPO3\CMS\Backend\Form;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Backend\Form\Element\InlineElement;
31 use TYPO3\CMS\Backend\Utility\BackendUtility;
32 use TYPO3\CMS\Backend\Utility\IconUtility;
33 use TYPO3\CMS\Core\Html\HtmlParser;
34 use TYPO3\CMS\Core\Messaging\FlashMessage;
35 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
36 use TYPO3\CMS\Core\Utility\GeneralUtility;
37 use TYPO3\CMS\Core\Utility\MathUtility;
38
39 /**
40 * 'TCEforms' - Class for creating the backend editing forms.
41 *
42 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
43 * @coauthor René Fritz <r.fritz@colorcube.de>
44 */
45 class FormEngine {
46
47 // variables not commented yet.... (do so...)
48 /**
49 * @todo Define visibility
50 */
51 public $palFieldArr = array();
52
53 /**
54 * @todo Define visibility
55 */
56 public $disableWizards = 0;
57
58 /**
59 * @todo Define visibility
60 */
61 public $isPalettedoc = 0;
62
63 /**
64 * @todo Define visibility
65 */
66 public $paletteMargin = 1;
67
68 /**
69 * @todo Define visibility
70 */
71 public $defStyle = '';
72
73 /**
74 * @todo Define visibility
75 */
76 public $cachedTSconfig = array();
77
78 /**
79 * @todo Define visibility
80 */
81 public $cachedTSconfig_fieldLevel = array();
82
83 /**
84 * @todo Define visibility
85 */
86 public $cachedLanguageFlag = array();
87
88 /**
89 * @todo Define visibility
90 */
91 public $cachedAdditionalPreviewLanguages = NULL;
92
93 /**
94 * @todo Define visibility
95 */
96 public $transformedRow = array();
97
98 /**
99 * @todo Define visibility
100 */
101 public $extJSCODE = '';
102
103 /**
104 * @todo Define visibility
105 */
106 public $printNeededJS = array();
107
108 /**
109 * @todo Define visibility
110 */
111 public $hiddenFieldAccum = array();
112
113 /**
114 * @todo Define visibility
115 */
116 public $TBE_EDITOR_fieldChanged_func = '';
117
118 /**
119 * @todo Define visibility
120 */
121 public $loadMD5_JS = 1;
122
123 // Something unique...
124 /**
125 * @todo Define visibility
126 */
127 public $prevBorderStyle = '[nothing here...]';
128
129 // If set direct upload fields will be shown
130 /**
131 * @todo Define visibility
132 */
133 public $allowUpload = 0;
134
135 // Array where records in the default language is stored. (processed by transferdata)
136 /**
137 * @todo Define visibility
138 */
139 public $defaultLanguageData = array();
140
141 // Array where records in the default language is stored (raw without any processing. used for making diff)
142 /**
143 * @todo Define visibility
144 */
145 public $defaultLanguageData_diff = array();
146
147 /**
148 * @todo Define visibility
149 */
150 public $additionalPreviewLanguageData = array();
151
152 // EXTERNAL, static
153 // Set this to the 'backPath' pointing back to the typo3 admin directory from the script where this form is displayed.
154 /**
155 * @todo Define visibility
156 */
157 public $backPath = '';
158
159 // Alternative return URL path (default is \TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript())
160 /**
161 * @todo Define visibility
162 */
163 public $returnUrl = '';
164
165 // Can be set to point to a field name in the form which will be set to '1' when the form is submitted with a *save* button. This way the recipient script can determine that the form was submitted for save and not "close" for example.
166 /**
167 * @todo Define visibility
168 */
169 public $doSaveFieldName = '';
170
171 // Can be set TRUE/FALSE to whether palettes (secondary options) are in the topframe or in form. TRUE means they are NOT IN-form. So a collapsed palette is one, which is shown in the top frame, not in the page.
172 /**
173 * @todo Define visibility
174 */
175 public $palettesCollapsed = 0;
176
177 // If set, the RTE is disabled (from form display, eg. by checkbox in the bottom of the page!)
178 /**
179 * @todo Define visibility
180 */
181 public $disableRTE = 0;
182
183 // If FALSE, then all CSH will be disabled, regardless of settings in $this->edit_showFieldHelp
184 /**
185 * @todo Define visibility
186 */
187 public $globalShowHelp = 1;
188
189 // If TRUE, the forms are rendering only localization relevant fields of the records.
190 /**
191 * @todo Define visibility
192 */
193 public $localizationMode = '';
194
195 // Overrule the field order set in TCA[types][showitem], eg for tt_content this value, 'bodytext,image', would make first the 'bodytext' field, then the 'image' field (if set for display)... and then the rest in the old order.
196 /**
197 * @todo Define visibility
198 */
199 public $fieldOrder = '';
200
201 // If set to FALSE, palettes will NEVER be rendered.
202 /**
203 * @todo Define visibility
204 */
205 public $doPrintPalette = 1;
206
207 /**
208 * Set to initialized clipboard object; Then the element browser will offer a link to paste in records from clipboard.
209 *
210 * @var \TYPO3\CMS\Backend\Clipboard\Clipboard
211 * @todo Define visibility
212 */
213 public $clipObj = FALSE;
214
215 // Enable click menu on reference icons.
216 /**
217 * @todo Define visibility
218 */
219 public $enableClickMenu = FALSE;
220
221 // Enable Tab Menus.
222 /**
223 * @todo Define visibility
224 */
225 public $enableTabMenu = FALSE;
226
227 // When enabled all fields are rendered non-editable.
228 /**
229 * @todo Define visibility
230 */
231 public $renderReadonly = FALSE;
232
233 // Form field width compensation: Factor from NN4 form field widths to style-aware browsers (like NN6+ and MSIE, with the $GLOBALS['CLIENT']['FORMSTYLE'] value set)
234 /**
235 * @todo Define visibility
236 */
237 public $form_rowsToStylewidth = 9.58;
238
239 /**
240 * Value that gets added for style="width: ...px" for textareas compared to input fields.
241 *
242 * @var integer
243 */
244 protected $form_additionalTextareaStyleWidth = 23;
245
246 // Form field width compensation: Compensation for large documents, doc-tab (editing)
247 /**
248 * @todo Define visibility
249 */
250 public $form_largeComp = 1.33;
251
252 // The number of chars expected per row when the height of a text area field is automatically calculated based on the number of characters found in the field content.
253 /**
254 * @todo Define visibility
255 */
256 public $charsPerRow = 40;
257
258 // The maximum abstract value for textareas
259 /**
260 * @todo Define visibility
261 */
262 public $maxTextareaWidth = 48;
263
264 // The maximum abstract value for input fields
265 /**
266 * @todo Define visibility
267 */
268 public $maxInputWidth = 48;
269
270 // Default style for the selector boxes used for multiple items in "select" and "group" types.
271 /**
272 * @todo Define visibility
273 */
274 public $defaultMultipleSelectorStyle = 'width:310px;';
275
276 // INTERNAL, static
277 // The string to prepend formfield names with.
278 /**
279 * @todo Define visibility
280 */
281 public $prependFormFieldNames = 'data';
282
283 // The string to prepend commands for tcemain::process_cmdmap with.
284 /**
285 * @todo Define visibility
286 */
287 public $prependCmdFieldNames = 'cmd';
288
289 // The string to prepend FILE form field names with.
290 /**
291 * @todo Define visibility
292 */
293 public $prependFormFieldNames_file = 'data_files';
294
295 /**
296 * The string to prepend form field names that are active (not NULL).
297 *
298 * @var string
299 */
300 protected $prependFormFieldNamesActive = 'control[active]';
301
302 // The name attribute of the form.
303 /**
304 * @todo Define visibility
305 */
306 public $formName = 'editform';
307
308 // Whitelist that allows TCA field configuration to be overridden by TSconfig, @see overrideFieldConf()
309 /**
310 * @todo Define visibility
311 */
312 public $allowOverrideMatrix = array();
313
314 // INTERNAL, dynamic
315 // Set by readPerms() (caching)
316 /**
317 * @todo Define visibility
318 */
319 public $perms_clause = '';
320
321 // Set by readPerms() (caching-flag)
322 /**
323 * @todo Define visibility
324 */
325 public $perms_clause_set = 0;
326
327 // Used to indicate the mode of CSH (Context Sensitive Help), whether it should be icons-only ('icon') or not at all (blank).
328 /**
329 * @todo Define visibility
330 */
331 public $edit_showFieldHelp = '';
332
333 /**
334 * @var bool
335 */
336 public $edit_docModuleUpload = FALSE;
337
338 // If set, the forms will be rendered a little wider, more precisely with a factor of $this->form_largeComp.
339 /**
340 * @todo Define visibility
341 */
342 public $docLarge = 0;
343
344 // Loaded with info about the browser when class is instantiated.
345 /**
346 * @todo Define visibility
347 */
348 public $clientInfo = array();
349
350 // TRUE, if RTE is possible for the current user (based on result from BE_USER->isRTE())
351 /**
352 * @todo Define visibility
353 */
354 public $RTEenabled = 0;
355
356 // If $this->RTEenabled was FALSE, you can find the reasons listed in this array which is filled with reasons why the RTE could not be loaded)
357 /**
358 * @todo Define visibility
359 */
360 public $RTEenabled_notReasons = '';
361
362 // Counter that is incremented before an RTE is created. Can be used for unique ids etc.
363 /**
364 * @todo Define visibility
365 */
366 public $RTEcounter = 0;
367
368 // Contains current color scheme
369 /**
370 * @todo Define visibility
371 */
372 public $colorScheme;
373
374 // Contains current class scheme
375 /**
376 * @todo Define visibility
377 */
378 public $classScheme;
379
380 // Contains the default color scheme
381 /**
382 * @todo Define visibility
383 */
384 public $defColorScheme;
385
386 // Contains the default class scheme
387 /**
388 * @todo Define visibility
389 */
390 public $defClassScheme;
391
392 // Contains field style values
393 /**
394 * @todo Define visibility
395 */
396 public $fieldStyle;
397
398 // Contains border style values.
399 /**
400 * @todo Define visibility
401 */
402 public $borderStyle;
403
404 // An accumulation of messages from the class.
405 /**
406 * @todo Define visibility
407 */
408 public $commentMessages = array();
409
410 // INTERNAL, templates
411 // Total wrapping for the table rows.
412 /**
413 * @todo Define visibility
414 */
415 public $totalWrap = '<hr />|<hr />';
416
417 // Field template
418 /**
419 * @todo Define visibility
420 */
421 public $fieldTemplate = '<strong>###FIELD_NAME###</strong><br />###FIELD_ITEM###<hr />';
422
423 /**
424 * Template subpart for palette fields.
425 *
426 * @var string
427 */
428 protected $paletteFieldTemplate;
429
430 // Wrapping template code for a section
431 /**
432 * @todo Define visibility
433 */
434 public $sectionWrap = '';
435
436 // Template for palette headers
437 /**
438 * @todo Define visibility
439 */
440 public $palFieldTemplateHeader = '';
441
442 // Template for palettes
443 /**
444 * @todo Define visibility
445 */
446 public $palFieldTemplate = '';
447
448 // INTERNAL, working memory
449 // Set to the fields NOT to display, if any.
450 /**
451 * @todo Define visibility
452 */
453 public $excludeElements = '';
454
455 // During rendering of forms this will keep track of which palettes has already been rendered (so they are not rendered twice by mistake)
456 /**
457 * @todo Define visibility
458 */
459 public $palettesRendered = array();
460
461 // This array of fields will be set as hidden-fields instead of rendered normally! For instance palette fields edited in the top frame are set as hidden fields since the main form has to submit the values. The top frame actually just sets the value in the main form!
462 /**
463 * @todo Define visibility
464 */
465 public $hiddenFieldListArr = array();
466
467 // Used to register input-field names, which are required. (Done during rendering of the fields). This information is then used later when the JavaScript is made.
468 /**
469 * @todo Define visibility
470 */
471 public $requiredFields = array();
472
473 // Used to register input-field names, which are required an have additional requirements (e.g. like a date/time must be positive integer). The information of this array is merged with $this->requiredFields later.
474 /**
475 * @todo Define visibility
476 */
477 public $requiredAdditional = array();
478
479 // Used to register the min and max number of elements for selectorboxes where that apply (in the "group" type for instance)
480 /**
481 * @todo Define visibility
482 */
483 public $requiredElements = array();
484
485 // Used to determine where $requiredFields or $requiredElements are nested (in Tabs or IRRE)
486 /**
487 * @todo Define visibility
488 */
489 public $requiredNested = array();
490
491 // Keeps track of the rendering depth of nested records.
492 /**
493 * @todo Define visibility
494 */
495 public $renderDepth = 0;
496
497 // Color scheme buffer.
498 /**
499 * @todo Define visibility
500 */
501 public $savedSchemes = array();
502
503 // holds the path an element is nested in (e.g. required for RTEhtmlarea)
504 /**
505 * @todo Define visibility
506 */
507 public $dynNestedStack = array();
508
509 // Internal, registers for user defined functions etc.
510 // Additional HTML code, printed before the form.
511 /**
512 * @todo Define visibility
513 */
514 public $additionalCode_pre = array();
515
516 // Additional JavaScript, printed before the form
517 /**
518 * @todo Define visibility
519 */
520 public $additionalJS_pre = array();
521
522 // Additional JavaScript printed after the form
523 /**
524 * @todo Define visibility
525 */
526 public $additionalJS_post = array();
527
528 // Additional JavaScript executed on submit; If you set "OK" variable it will raise an error about RTEs not being loaded and offer to block further submission.
529 /**
530 * @todo Define visibility
531 */
532 public $additionalJS_submit = array();
533
534 // Additional JavaScript executed when section element is deleted. This is necessary, for example, to correctly clean up HTMLArea RTE (bug #8232)
535 /**
536 * @todo Define visibility
537 */
538 public $additionalJS_delete = array();
539
540 /**
541 * @var \TYPO3\CMS\Backend\Form\Element\InlineElement
542 * @todo Define visibility
543 */
544 public $inline;
545
546 // Array containing hook class instances called once for a form
547 /**
548 * @todo Define visibility
549 */
550 public $hookObjectsMainFields = array();
551
552 // Array containing hook class instances called for each field
553 /**
554 * @todo Define visibility
555 */
556 public $hookObjectsSingleField = array();
557
558 // Rows gettings inserted into the alt_doc headers (when called from alt_doc.php)
559 /**
560 * @todo Define visibility
561 */
562 public $extraFormHeaders = array();
563
564 public $templateFile = '';
565
566 /**
567 * @var integer
568 */
569 protected $multiSelectFilterCount = 0;
570
571 /**
572 * @var \TYPO3\CMS\Backend\Form\Element\SuggestElement
573 */
574 protected $suggest;
575
576 // Form templates, relative to typo3 directory
577 /**
578 * Constructor function, setting internal variables, loading the styles used.
579 *
580 * @return void
581 * @todo Define visibility
582 */
583 public function __construct() {
584 $this->clientInfo = GeneralUtility::clientInfo();
585 $this->RTEenabled = $GLOBALS['BE_USER']->isRTE();
586 if (!$this->RTEenabled) {
587 $this->RTEenabled_notReasons = implode(LF, $GLOBALS['BE_USER']->RTE_errors);
588 $this->commentMessages[] = 'RTE NOT ENABLED IN SYSTEM due to:' . LF . $this->RTEenabled_notReasons;
589 }
590 // Default color+class scheme
591 $this->defColorScheme = array(
592 $GLOBALS['SOBE']->doc->bgColor,
593 // Background for the field AND palette
594 GeneralUtility::modifyHTMLColorAll($GLOBALS['SOBE']->doc->bgColor, -20),
595 // Background for the field header
596 GeneralUtility::modifyHTMLColorAll($GLOBALS['SOBE']->doc->bgColor, -10),
597 // Background for the palette field header
598 'black',
599 // Field header font color
600 '#666666'
601 );
602 $this->defColorScheme = array();
603 // Override / Setting defaults from TBE_STYLES array
604 $this->resetSchemes();
605 // Setting the current colorScheme to default.
606 $this->defColorScheme = $this->colorScheme;
607 $this->defClassScheme = $this->classScheme;
608 // Define whitelist that allows TCA field configuration to be overridden by TSconfig, @see overrideFieldConf():
609 $this->allowOverrideMatrix = array(
610 'input' => array('size', 'max', 'readOnly'),
611 'text' => array('cols', 'rows', 'wrap', 'readOnly'),
612 'check' => array('cols', 'showIfRTE', 'readOnly'),
613 'select' => array('size', 'autoSizeMax', 'maxitems', 'minitems', 'readOnly', 'treeConfig'),
614 'group' => array('size', 'autoSizeMax', 'max_size', 'show_thumbs', 'maxitems', 'minitems', 'disable_controls', 'readOnly'),
615 'inline' => array('appearance', 'behaviour', 'foreign_label', 'foreign_selector', 'foreign_unique', 'maxitems', 'minitems', 'size', 'autoSizeMax', 'symmetric_label', 'readOnly')
616 );
617 // Create instance of InlineElement only if this a non-IRRE-AJAX call:
618 if (!isset($GLOBALS['ajaxID']) || strpos($GLOBALS['ajaxID'], 'TYPO3\\CMS\\Backend\\Form\\Element\\InlineElement::') !== 0) {
619 $this->inline = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\Element\\InlineElement');
620 }
621 // Create instance of \TYPO3\CMS\Backend\Form\Element\SuggestElement only if this a non-Suggest-AJAX call:
622 if (!isset($GLOBALS['ajaxID']) || strpos($GLOBALS['ajaxID'], 'TYPO3\\CMS\\Backend\\Form\\Element\\SuggestElement::') !== 0) {
623 $this->suggest = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\Element\\SuggestElement');
624 }
625 // Prepare user defined objects (if any) for hooks which extend this function:
626 $this->hookObjectsMainFields = array();
627 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tceforms.php']['getMainFieldsClass'])) {
628 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tceforms.php']['getMainFieldsClass'] as $classRef) {
629 $this->hookObjectsMainFields[] = GeneralUtility::getUserObj($classRef);
630 }
631 }
632 $this->hookObjectsSingleField = array();
633 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tceforms.php']['getSingleFieldClass'])) {
634 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tceforms.php']['getSingleFieldClass'] as $classRef) {
635 $this->hookObjectsSingleField[] = GeneralUtility::getUserObj($classRef);
636 }
637 }
638 $this->templateFile = 'sysext/backend/Resources/Private/Templates/FormEngine.html';
639 }
640
641 /**
642 * Initialize various internal variables.
643 *
644 * @return void
645 * @todo Define visibility
646 */
647 public function initDefaultBEmode() {
648 $this->prependFormFieldNames = 'data';
649 $this->formName = 'editform';
650 $this->setNewBEDesign();
651 $this->docLarge = $GLOBALS['BE_USER']->uc['edit_wideDocument'] ? 1 : 0;
652 $this->edit_showFieldHelp = $GLOBALS['BE_USER']->uc['edit_showFieldHelp'];
653 $this->edit_docModuleUpload = (bool)$GLOBALS['BE_USER']->uc['edit_docModuleUpload'];
654 $this->inline->init($this);
655 $this->suggest->init($this);
656 }
657
658 /*******************************************************
659 *
660 * Rendering the forms, fields etc
661 *
662 *******************************************************/
663 /**
664 * Will return the TCEform element for just a single field from a record.
665 * The field must be listed in the currently displayed fields (as found in [types][showitem]) for the record.
666 * This also means that the $table/$row supplied must be complete so the list of fields to show can be found correctly
667 *
668 * @param string $table The table name
669 * @param array $row The record from the table for which to render a field.
670 * @param string $theFieldToReturn The field name to return the TCEform element for.
671 * @return string HTML output
672 * @see getMainFields()
673 * @todo Define visibility
674 */
675 public function getSoloField($table, $row, $theFieldToReturn) {
676 if ($GLOBALS['TCA'][$table]) {
677 $typeNum = $this->getRTypeNum($table, $row);
678 if ($GLOBALS['TCA'][$table]['types'][$typeNum]) {
679 $itemList = $GLOBALS['TCA'][$table]['types'][$typeNum]['showitem'];
680 if ($itemList) {
681 $fields = GeneralUtility::trimExplode(',', $itemList, TRUE);
682 $excludeElements = ($this->excludeElements = $this->getExcludeElements($table, $row, $typeNum));
683 foreach ($fields as $fieldInfo) {
684 $parts = explode(';', $fieldInfo);
685 $theField = trim($parts[0]);
686 if (!in_array($theField, $excludeElements) && (string)$theField === (string)$theFieldToReturn) {
687 if ($GLOBALS['TCA'][$table]['columns'][$theField]) {
688 $sField = $this->getSingleField($table, $theField, $row, $parts[1], 1, $parts[3], $parts[2]);
689 return $sField['ITEM'];
690 }
691 }
692 }
693 }
694 }
695 }
696 }
697
698 /**
699 * Based on the $table and $row of content, this displays the complete TCEform for the record.
700 * The input-$row is required to be preprocessed if necessary by eg.
701 * the \TYPO3\CMS\Backend\Form\DataPreprocessor class. For instance the RTE content
702 * should be transformed through this class first.
703 *
704 * @param string $table The table name
705 * @param array $row The record from the table for which to render a field.
706 * @param integer $depth Depth level
707 * @param array $overruleTypesArray Overrule types array. Can be used to override the showitem etc. configuration for the TCA types of the table. Can contain all settings which are possible in the TCA 'types' section. See e.g. $TCA['tt_content']['types'].
708 * @return string HTML output
709 * @see getSoloField()
710 * @todo Define visibility
711 */
712 public function getMainFields($table, array $row, $depth = 0, array $overruleTypesArray = array()) {
713 $this->renderDepth = $depth;
714 // Init vars:
715 $out_array = array(array());
716 $out_array_meta = array(
717 array(
718 'title' => $this->getLL('l_generalTab')
719 )
720 );
721 $out_pointer = 0;
722 $out_sheet = 0;
723 $this->palettesRendered = array();
724 $this->palettesRendered[$this->renderDepth][$table] = array();
725 // Hook: getMainFields_preProcess (requested by Thomas Hempel for use with the "dynaflex" extension)
726 foreach ($this->hookObjectsMainFields as $hookObj) {
727 if (method_exists($hookObj, 'getMainFields_preProcess')) {
728 $hookObj->getMainFields_preProcess($table, $row, $this);
729 }
730 }
731 if ($GLOBALS['TCA'][$table]) {
732 // Get dividers2tabs setting from TCA of the current table:
733 $dividers2tabs = &$GLOBALS['TCA'][$table]['ctrl']['dividers2tabs'];
734 // Load the description content for the table.
735 if ($this->edit_showFieldHelp || $this->doLoadTableDescr($table)) {
736 $GLOBALS['LANG']->loadSingleTableDescription($table);
737 }
738 // Get the current "type" value for the record.
739 $typeNum = $this->getRTypeNum($table, $row);
740 // Find the list of fields to display:
741 if ($GLOBALS['TCA'][$table]['types'][$typeNum]) {
742 $itemList = $GLOBALS['TCA'][$table]['types'][$typeNum]['showitem'];
743 if (is_array($overruleTypesArray) && isset($overruleTypesArray[$typeNum]['showitem'])) {
744 $itemList = $overruleTypesArray[$typeNum]['showitem'];
745 }
746 // If such a list existed...
747 if ($itemList) {
748 // Explode the field list and possibly rearrange the order of the fields, if configured for
749 $fields = GeneralUtility::trimExplode(',', $itemList, TRUE);
750 if ($this->fieldOrder) {
751 $fields = $this->rearrange($fields);
752 }
753 // Get excluded fields, added fiels and put it together:
754 $excludeElements = ($this->excludeElements = $this->getExcludeElements($table, $row, $typeNum));
755 $fields = $this->mergeFieldsWithAddedFields($fields, $this->getFieldsToAdd($table, $row, $typeNum), $table);
756 // If TCEforms will render a tab menu in the next step, push the name to the tab stack:
757 $tabIdentString = '';
758 $tabIdentStringMD5 = '';
759 if (strstr($itemList, '--div--') !== FALSE && $this->enableTabMenu && $dividers2tabs) {
760 $tabIdentString = 'TCEforms:' . $table . ':' . $row['uid'];
761 $tabIdentStringMD5 = $GLOBALS['TBE_TEMPLATE']->getDynTabMenuId($tabIdentString);
762 // Remember that were currently working on the general tab:
763 if (isset($fields[0]) && strpos($fields[0], '--div--') !== 0) {
764 $this->pushToDynNestedStack('tab', $tabIdentStringMD5 . '-1');
765 }
766 }
767 // Traverse the fields to render:
768 $cc = 0;
769 foreach ($fields as $fieldInfo) {
770 // Exploding subparts of the field configuration:
771 $parts = explode(';', $fieldInfo);
772 // Getting the style information out:
773 $color_style_parts = GeneralUtility::trimExplode('-', $parts[4]);
774 if ($color_style_parts[0] !== '') {
775 $this->setColorScheme($GLOBALS['TBE_STYLES']['colorschemes'][(int)$color_style_parts[0]]);
776 }
777 if ($color_style_parts[1] !== '') {
778 $this->fieldStyle = $GLOBALS['TBE_STYLES']['styleschemes'][(int)$color_style_parts[1]];
779 if (!isset($this->fieldStyle)) {
780 $this->fieldStyle = $GLOBALS['TBE_STYLES']['styleschemes'][0];
781 }
782 }
783 if ($color_style_parts[2] !== '') {
784 $this->wrapBorder($out_array[$out_sheet], $out_pointer);
785 $this->borderStyle = $GLOBALS['TBE_STYLES']['borderschemes'][(int)$color_style_parts[2]];
786 if (!isset($this->borderStyle)) {
787 $this->borderStyle = $GLOBALS['TBE_STYLES']['borderschemes'][0];
788 }
789 }
790 // Render the field:
791 $theField = $parts[0];
792 if (!in_array($theField, $excludeElements)) {
793 if ($GLOBALS['TCA'][$table]['columns'][$theField]) {
794 $sFieldPal = '';
795 if ($parts[2] && !isset($this->palettesRendered[$this->renderDepth][$table][$parts[2]])) {
796 $sFieldPal = $this->getPaletteFields($table, $row, $parts[2]);
797 $this->palettesRendered[$this->renderDepth][$table][$parts[2]] = 1;
798 }
799 $sField = $this->getSingleField($table, $theField, $row, $parts[1], 0, $parts[3], $parts[2]);
800 if ($sField) {
801 $sField .= $sFieldPal;
802 }
803 $out_array[$out_sheet][$out_pointer] .= $sField;
804 } elseif ($theField == '--div--') {
805 if ($cc > 0) {
806 $out_array[$out_sheet][$out_pointer] .= $this->getDivider();
807 if ($this->enableTabMenu && $dividers2tabs) {
808 $this->wrapBorder($out_array[$out_sheet], $out_pointer);
809 // Remove last tab entry from the dynNestedStack:
810 $out_sheet++;
811 // Remove the previous sheet from stack (if any):
812 $this->popFromDynNestedStack('tab', $tabIdentStringMD5 . '-' . $out_sheet);
813 // Remember on which sheet we're currently working:
814 $this->pushToDynNestedStack('tab', $tabIdentStringMD5 . '-' . ($out_sheet + 1));
815 $out_array[$out_sheet] = array();
816 $out_array_meta[$out_sheet]['title'] = $this->sL($parts[1]);
817 // Register newline for Tab
818 $out_array_meta[$out_sheet]['newline'] = $parts[2] == 'newline';
819 }
820 } else {
821 // Setting alternative title for "General" tab if "--div--" is the very first element.
822 $out_array_meta[$out_sheet]['title'] = $this->sL($parts[1]);
823 // Only add the first tab to the dynNestedStack if there are more tabs:
824 if ($tabIdentString && strpos($itemList, '--div--', strlen($fieldInfo))) {
825 $this->pushToDynNestedStack('tab', $tabIdentStringMD5 . '-1');
826 }
827 }
828 } elseif ($theField == '--palette--') {
829 if ($parts[2] && !isset($this->palettesRendered[$this->renderDepth][$table][$parts[2]])) {
830 // Render a 'header' if not collapsed
831 if ($GLOBALS['TCA'][$table]['palettes'][$parts[2]]['canNotCollapse'] && $parts[1]) {
832 $out_array[$out_sheet][$out_pointer] .= $this->getPaletteFields($table, $row, $parts[2], $this->sL($parts[1]));
833 } else {
834 $out_array[$out_sheet][$out_pointer] .= $this->getPaletteFields($table, $row, $parts[2], '', '', $this->sL($parts[1]));
835 }
836 $this->palettesRendered[$this->renderDepth][$table][$parts[2]] = 1;
837 }
838 }
839 }
840 $cc++;
841 }
842 }
843 }
844 }
845 // Hook: getMainFields_postProcess (requested by Thomas Hempel for use with the "dynaflex" extension)
846 foreach ($this->hookObjectsMainFields as $hookObj) {
847 if (method_exists($hookObj, 'getMainFields_postProcess')) {
848 $hookObj->getMainFields_postProcess($table, $row, $this);
849 }
850 }
851 // Wrapping a border around it all:
852 $this->wrapBorder($out_array[$out_sheet], $out_pointer);
853 // Resetting styles:
854 $this->resetSchemes();
855 // Rendering Main palettes, if any
856 $mParr = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['mainpalette']);
857 $i = 0;
858 if (count($mParr)) {
859 foreach ($mParr as $mP) {
860 if (!isset($this->palettesRendered[$this->renderDepth][$table][$mP])) {
861 $temp_palettesCollapsed = $this->palettesCollapsed;
862 $this->palettesCollapsed = 0;
863 $label = $i == 0 ? $this->getLL('l_generalOptions') : $this->getLL('l_generalOptions_more');
864 $out_array[$out_sheet][$out_pointer] .= $this->getPaletteFields($table, $row, $mP, $label);
865 $this->palettesCollapsed = $temp_palettesCollapsed;
866 $this->palettesRendered[$this->renderDepth][$table][$mP] = 1;
867 }
868 $this->wrapBorder($out_array[$out_sheet], $out_pointer);
869 $i++;
870 if ($this->renderDepth) {
871 $this->renderDepth--;
872 }
873 }
874 }
875 // Return the imploded $out_array:
876 // There were --div-- dividers around...
877 if ($out_sheet > 0) {
878 // Create parts array for the tab menu:
879 $parts = array();
880 foreach ($out_array as $idx => $sheetContent) {
881 $content = implode('', $sheetContent);
882 if ($content) {
883 // Wrap content (row) with table-tag, otherwise tab/sheet will be disabled (see getdynTabMenu() )
884 $content = '<table border="0" cellspacing="0" cellpadding="0" width="100%">' . $content . '</table>';
885 }
886 $parts[$idx] = array(
887 'label' => $out_array_meta[$idx]['title'],
888 'content' => $content,
889 'newline' => $out_array_meta[$idx]['newline']
890 );
891 }
892 if (count($parts) > 1) {
893 // Unset the current level of tab menus:
894 $this->popFromDynNestedStack('tab', $tabIdentStringMD5 . '-' . ($out_sheet + 1));
895 $dividersToTabsBehaviour = isset($GLOBALS['TCA'][$table]['ctrl']['dividers2tabs']) ? $GLOBALS['TCA'][$table]['ctrl']['dividers2tabs'] : 1;
896 $output = $this->getDynTabMenu($parts, $tabIdentString, $dividersToTabsBehaviour);
897 } else {
898 // If there is only one tab/part there is no need to wrap it into the dynTab code
899 $output = isset($parts[0]) ? trim($parts[0]['content']) : '';
900 }
901 $output = '
902 <tr>
903 <td colspan="2">
904 ' . $output . '
905 </td>
906 </tr>';
907 } else {
908 // Only one tab, so just implode and wrap the background image (= tab container) around:
909 $output = implode('', $out_array[$out_sheet]);
910 if ($this->inline->inlineCount == 0) {
911 $output = '<div class="typo3-dyntabmenu-divs">' . $output . '</div>';
912 }
913 }
914
915 return $output;
916 }
917
918 /**
919 * Will return the TCEform elements for a pre-defined list of fields.
920 * Notice that this will STILL use the configuration found in the list [types][showitem] for those fields which are found there. So ideally the list of fields given as argument to this function should also be in the current [types][showitem] list of the record.
921 * Used for displaying forms for the frontend edit icons for instance.
922 *
923 * @param string $table The table name
924 * @param array $row The record array.
925 * @param string $list Commalist of fields from the table. These will be shown in the specified order in a form.
926 * @return string TCEform elements in a string.
927 * @todo Define visibility
928 */
929 public function getListedFields($table, $row, $list) {
930 if ($this->edit_showFieldHelp || $this->doLoadTableDescr($table)) {
931 $GLOBALS['LANG']->loadSingleTableDescription($table);
932 }
933 $out = '';
934 $types_fieldConfig = BackendUtility::getTCAtypes($table, $row, 1);
935 $editFieldList = array_unique(GeneralUtility::trimExplode(',', $list, TRUE));
936 foreach ($editFieldList as $theFieldC) {
937 list($theField, $palFields) = preg_split('/\\[|\\]/', $theFieldC);
938 $theField = trim($theField);
939 $palFields = trim($palFields);
940 if ($GLOBALS['TCA'][$table]['columns'][$theField]) {
941 $parts = GeneralUtility::trimExplode(';', $types_fieldConfig[$theField]['origString']);
942 // Don't sent palette pointer - there are no options anyways for a field-list.
943 $sField = $this->getSingleField($table, $theField, $row, $parts[1], 0, $parts[3], 0);
944 $out .= $sField;
945 } elseif ($theField == '--div--') {
946 $out .= $this->getDivider();
947 }
948 if ($palFields) {
949 $out .= $this->getPaletteFields($table, $row, '', '', implode(',', GeneralUtility::trimExplode('|', $palFields, TRUE)));
950 }
951 }
952 return $out;
953 }
954
955 /**
956 * Creates a palette (collection of secondary options).
957 *
958 * @param string $table The table name
959 * @param array $row The row array
960 * @param string $palette The palette number/pointer
961 * @param string $header Header string for the palette (used when in-form). If not set, no header item is made.
962 * @param string $itemList Optional alternative list of fields for the palette
963 * @param string $collapsedHeader Optional Link text for activating a palette (when palettes does not have another form element to belong to).
964 * @return string HTML code.
965 * @todo Define visibility
966 */
967 public function getPaletteFields($table, $row, $palette, $header = '', $itemList = '', $collapsedHeader = NULL) {
968 if (!$this->doPrintPalette) {
969 return '';
970 }
971 $out = '';
972 $parts = $this->loadPaletteElements($table, $row, $palette, $itemList);
973 // Put palette together if there are fields in it:
974 if (count($parts)) {
975 $realFields = 0;
976 foreach ($parts as $part) {
977 if ($part['NAME'] !== '--linebreak--') {
978 $realFields++;
979 }
980 }
981 if ($realFields > 0) {
982 if ($header) {
983 $out .= $this->intoTemplate(array('HEADER' => htmlspecialchars($header)), $this->palFieldTemplateHeader);
984 }
985 $collapsed = $this->isPalettesCollapsed($table, $palette);
986 // Check if the palette is a hidden palette
987 $isHiddenPalette = !empty($GLOBALS['TCA'][$table]['palettes'][$palette]['isHiddenPalette']);
988 $thePalIcon = '';
989 if ($collapsed && $collapsedHeader !== NULL && !$isHiddenPalette) {
990 list($thePalIcon, ) = $this->wrapOpenPalette(IconUtility::getSpriteIcon('actions-system-options-view', array('title' => htmlspecialchars($this->getLL('l_moreOptions')))), $table, $row, $palette, 1);
991 $thePalIcon = '<span style="margin-left: 20px;">' . $thePalIcon . $collapsedHeader . '</span>';
992 }
993 $paletteHtml = $this->wrapPaletteField($this->printPalette($parts), $table, $row, $palette, $collapsed);
994 $out .= $this->intoTemplate(array('PALETTE' => $thePalIcon . $paletteHtml), $this->palFieldTemplate);
995 }
996 }
997 return $out;
998 }
999
1000 /**
1001 * Returns the form HTML code for a database table field.
1002 *
1003 * @param string $table The table name
1004 * @param string $field The field name
1005 * @param array $row The record to edit from the database table.
1006 * @param string $altName Alternative field name label to show.
1007 * @param boolean $palette Set this if the field is on a palette (in top frame), otherwise not. (if set, field will render as a hidden field).
1008 * @param string $extra The "extra" options from "Part 4" of the field configurations found in the "types" "showitem" list. Typically parsed by $this->getSpecConfFromString() in order to get the options as an associative array.
1009 * @param integer $pal The palette pointer.
1010 * @return mixed String (normal) or array (palettes)
1011 * @todo Define visibility
1012 */
1013 public function getSingleField($table, $field, $row, $altName = '', $palette = 0, $extra = '', $pal = 0) {
1014 // Hook: getSingleField_preProcess
1015 foreach ($this->hookObjectsSingleField as $hookObj) {
1016 if (method_exists($hookObj, 'getSingleField_preProcess')) {
1017 $hookObj->getSingleField_preProcess($table, $field, $row, $altName, $palette, $extra, $pal, $this);
1018 }
1019 }
1020 $out = '';
1021 $PA = array();
1022 $PA['altName'] = $altName;
1023 $PA['palette'] = $palette;
1024 $PA['extra'] = $extra;
1025 $PA['pal'] = $pal;
1026 // Get the TCA configuration for the current field:
1027 $PA['fieldConf'] = $GLOBALS['TCA'][$table]['columns'][$field];
1028 $PA['fieldConf']['config']['form_type'] = $PA['fieldConf']['config']['form_type'] ?: $PA['fieldConf']['config']['type'];
1029
1030 // Using "form_type" locally in this script
1031 $skipThisField = $this->inline->skipField($table, $field, $row, $PA['fieldConf']['config']);
1032
1033 // Evaluate display condition
1034 $displayConditionResult = TRUE;
1035 if (is_array($PA['fieldConf']) && $PA['fieldConf']['displayCond'] && is_array($row)) {
1036 /** @var $elementConditionMatcher \TYPO3\CMS\Backend\Form\ElementConditionMatcher */
1037 $elementConditionMatcher = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\ElementConditionMatcher');
1038 $displayConditionResult = $elementConditionMatcher->match($PA['fieldConf']['displayCond'], $row);
1039 }
1040 // Check if this field is configured and editable (according to excludefields + other configuration)
1041 if (
1042 is_array($PA['fieldConf'])
1043 && !$skipThisField
1044 && (!$PA['fieldConf']['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $table . ':' . $field))
1045 && $PA['fieldConf']['config']['form_type'] != 'passthrough'
1046 && ($this->RTEenabled || !$PA['fieldConf']['config']['showIfRTE'])
1047 && $displayConditionResult
1048 && (!$GLOBALS['TCA'][$table]['ctrl']['languageField'] || $PA['fieldConf']['l10n_display'] || ($PA['fieldConf']['l10n_mode'] !== 'exclude') || $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] <= 0)
1049 && (!$GLOBALS['TCA'][$table]['ctrl']['languageField'] || !$this->localizationMode || $this->localizationMode === $PA['fieldConf']['l10n_cat'])
1050 ) {
1051 // Fetching the TSconfig for the current table/field. This includes the $row which means that
1052 $PA['fieldTSConfig'] = $this->setTSconfig($table, $row, $field);
1053 // If the field is NOT disabled from TSconfig (which it could have been) then render it
1054 if (!$PA['fieldTSConfig']['disabled']) {
1055 // Override fieldConf by fieldTSconfig:
1056 $PA['fieldConf']['config'] = $this->overrideFieldConf($PA['fieldConf']['config'], $PA['fieldTSConfig']);
1057 // Init variables:
1058 $PA['itemFormElName'] = $this->prependFormFieldNames . '[' . $table . '][' . $row['uid'] . '][' . $field . ']';
1059 // Form field name, in case of file uploads
1060 $PA['itemFormElName_file'] = $this->prependFormFieldNames_file . '[' . $table . '][' . $row['uid'] . '][' . $field . ']';
1061 // Form field name, to activate elements
1062 // If the "eval" list contains "null", elements can be deactivated which results in storing NULL to database
1063 $PA['itemFormElNameActive'] = $this->prependFormFieldNamesActive . '[' . $table . '][' . $row['uid'] . '][' . $field . ']';
1064 // The value to show in the form field.
1065 $PA['itemFormElValue'] = $row[$field];
1066 $PA['itemFormElID'] = $this->prependFormFieldNames . '_' . $table . '_' . $row['uid'] . '_' . $field;
1067 // Set field to read-only if configured for translated records to show default language content as readonly
1068 if ($PA['fieldConf']['l10n_display'] && GeneralUtility::inList($PA['fieldConf']['l10n_display'], 'defaultAsReadonly') && $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0) {
1069 $PA['fieldConf']['config']['readOnly'] = TRUE;
1070 $PA['itemFormElValue'] = $this->defaultLanguageData[$table . ':' . $row['uid']][$field];
1071 }
1072 if (strpos($GLOBALS['TCA'][$table]['ctrl']['type'], ':') === FALSE) {
1073 $typeField = $GLOBALS['TCA'][$table]['ctrl']['type'];
1074 } else {
1075 $typeField = substr($GLOBALS['TCA'][$table]['ctrl']['type'], 0, strpos($GLOBALS['TCA'][$table]['ctrl']['type'], ':'));
1076 }
1077 // Create a JavaScript code line which will ask the user to save/update the form due to changing the element. This is used for eg. "type" fields and others configured with "requestUpdate"
1078 if (
1079 !empty($GLOBALS['TCA'][$table]['ctrl']['type'])
1080 && $field === $typeField
1081 || !empty($GLOBALS['TCA'][$table]['ctrl']['requestUpdate'])
1082 && GeneralUtility::inList(str_replace(' ', '', $GLOBALS['TCA'][$table]['ctrl']['requestUpdate']), $field)
1083 ) {
1084 if ($GLOBALS['BE_USER']->jsConfirmation(1)) {
1085 $alertMsgOnChange = 'if (confirm(TBE_EDITOR.labels.onChangeAlert) && TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm() };';
1086 } else {
1087 $alertMsgOnChange = 'if (TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm() };';
1088 }
1089 } else {
1090 $alertMsgOnChange = '';
1091 }
1092 // Render as a hidden field?
1093 if (in_array($field, $this->hiddenFieldListArr)) {
1094 $this->hiddenFieldAccum[] = '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($PA['itemFormElValue']) . '" />';
1095 } else {
1096 // Render as a normal field:
1097 // If the field is NOT a palette field, then we might create an icon which links to a palette for the field, if one exists.
1098 if (!$PA['palette']) {
1099 $paletteFields = $this->loadPaletteElements($table, $row, $PA['pal']);
1100 if ($PA['pal'] && $this->isPalettesCollapsed($table, $PA['pal']) && count($paletteFields)) {
1101 list($thePalIcon, $palJSfunc) = $this->wrapOpenPalette(IconUtility::getSpriteIcon('actions-system-options-view', array('title' => htmlspecialchars($this->getLL('l_moreOptions')))), $table, $row, $PA['pal'], 1);
1102 } else {
1103 $thePalIcon = '';
1104 $palJSfunc = '';
1105 }
1106 }
1107 // onFocus attribute to add to the field:
1108 $PA['onFocus'] = $palJSfunc && !$GLOBALS['BE_USER']->uc['dontShowPalettesOnFocusInAB'] ? ' onfocus="' . htmlspecialchars($palJSfunc) . '"' : '';
1109 // Find item
1110 $item = '';
1111 $PA['label'] = $PA['altName'] ?: $PA['fieldConf']['label'];
1112 $PA['label'] = $PA['fieldTSConfig']['label'] ?: $PA['label'];
1113 $PA['label'] = $PA['fieldTSConfig']['label.'][$GLOBALS['LANG']->lang] ?: $PA['label'];
1114 $PA['label'] = $this->sL($PA['label']);
1115 // JavaScript code for event handlers:
1116 $PA['fieldChangeFunc'] = array();
1117 $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = 'TBE_EDITOR.fieldChanged(\'' . $table . '\',\'' . $row['uid'] . '\',\'' . $field . '\',\'' . $PA['itemFormElName'] . '\');';
1118 $PA['fieldChangeFunc']['alert'] = $alertMsgOnChange;
1119 // If this is the child of an inline type and it is the field creating the label
1120 if ($this->inline->isInlineChildAndLabelField($table, $field)) {
1121 $inlineObjectId = implode(InlineElement::Structure_Separator, array(
1122 $this->inline->inlineNames['object'],
1123 $table,
1124 $row['uid']
1125 ));
1126 $PA['fieldChangeFunc']['inline'] = 'inline.handleChangedField(\'' . $PA['itemFormElName'] . '\',\'' . $inlineObjectId . '\');';
1127 }
1128 // Based on the type of the item, call a render function:
1129 $item = $this->getSingleField_SW($table, $field, $row, $PA);
1130 // Add language + diff
1131 if ($PA['fieldConf']['l10n_display'] && (GeneralUtility::inList($PA['fieldConf']['l10n_display'], 'hideDiff') || GeneralUtility::inList($PA['fieldConf']['l10n_display'], 'defaultAsReadonly'))) {
1132 $renderLanguageDiff = FALSE;
1133 } else {
1134 $renderLanguageDiff = TRUE;
1135 }
1136 if ($renderLanguageDiff) {
1137 $item = $this->renderDefaultLanguageContent($table, $field, $row, $item);
1138 $item = $this->renderDefaultLanguageDiff($table, $field, $row, $item);
1139 }
1140 // If the record has been saved and the "linkTitleToSelf" is set, we make the field name into a link, which will load ONLY this field in alt_doc.php
1141 $label = GeneralUtility::deHSCentities(htmlspecialchars($PA['label']));
1142 if (MathUtility::canBeInterpretedAsInteger($row['uid']) && $PA['fieldTSConfig']['linkTitleToSelf'] && !GeneralUtility::_GP('columnsOnly')) {
1143 $lTTS_url = $this->backPath . 'alt_doc.php?edit[' . $table . '][' . $row['uid'] . ']=edit&columnsOnly=' . $field . '&returnUrl=' . rawurlencode($this->thisReturnUrl());
1144 $label = '<a href="' . htmlspecialchars($lTTS_url) . '">' . $label . '</a>';
1145 }
1146
1147 if (isset($PA['fieldConf']['config']['mode']) && $PA['fieldConf']['config']['mode'] == 'useOrOverridePlaceholder') {
1148 $placeholder = $this->getPlaceholderValue($table, $field, $PA['fieldConf']['config'], $row);
1149 $onChange = 'typo3form.fieldTogglePlaceholder(' . GeneralUtility::quoteJSvalue($PA['itemFormElName']) . ', !this.checked)';
1150
1151
1152 $isNull = ($PA['itemFormElValue'] === NULL);
1153 $checked = (($isNull || $this->isNewRecord($table, $row)) ? '' : ' checked="checked"');
1154
1155 $this->additionalJS_post[] = 'typo3form.fieldTogglePlaceholder('
1156 . GeneralUtility::quoteJSvalue($PA['itemFormElName']) . ', ' . ($checked ? 'false' : 'true') . ');';
1157
1158 $item = '<div class="t3-form-field-placeholder-override">'
1159 . '<span class="t3-tceforms-placeholder-override-checkbox">' .
1160 '<input type="hidden" name="' . htmlspecialchars($PA['itemFormElNameActive']) . '" value="0" />' .
1161 '<input type="checkbox" name="' . htmlspecialchars($PA['itemFormElNameActive']) . '" value="1" id="tce-forms-textfield-use-override-' . $field . '-' . $row['uid'] . '" onchange="' . htmlspecialchars($onChange) . '"' . $checked . ' />' .
1162 '<label for="tce-forms-textfield-use-override-' . $field . '-' . $row['uid'] . '">' . htmlspecialchars(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.placeholder.override'), $placeholder)) . '</label>' .
1163 '</span>'
1164 . '<div class="t3-form-placeholder-placeholder">' . $this->getSingleField_typeNone_render($PA['fieldConf']['config'], $placeholder) . '</div>'
1165 . '<div class="t3-form-placeholder-formfield">' . $item . '</div>'
1166 . '</div>';
1167 }
1168
1169 // Wrap the label with help text
1170 $PA['label'] = ($label = BackendUtility::wrapInHelp($table, $field, $label));
1171 // Create output value:
1172 if ($PA['fieldConf']['config']['form_type'] == 'user' && $PA['fieldConf']['config']['noTableWrapping']) {
1173 $out = $item;
1174 } elseif ($PA['palette']) {
1175 // Array:
1176 $out = array(
1177 'NAME' => $label,
1178 'ID' => $row['uid'],
1179 'FIELD' => $field,
1180 'TABLE' => $table,
1181 'ITEM' => $item,
1182 'ITEM_DISABLED' => ($this->isDisabledNullValueField($table, $field, $row, $PA) ? ' disabled' : ''),
1183 'ITEM_NULLVALUE' => $this->renderNullValueWidget($table, $field, $row, $PA),
1184 );
1185 $out = $this->addUserTemplateMarkers($out, $table, $field, $row, $PA);
1186 } else {
1187 // String:
1188 $out = array(
1189 'NAME' => $label,
1190 'ITEM' => $item,
1191 'TABLE' => $table,
1192 'ID' => $row['uid'],
1193 'PAL_LINK_ICON' => $thePalIcon,
1194 'FIELD' => $field,
1195 'ITEM_DISABLED' => ($this->isDisabledNullValueField($table, $field, $row, $PA) ? ' disabled' : ''),
1196 'ITEM_NULLVALUE' => $this->renderNullValueWidget($table, $field, $row, $PA),
1197 );
1198 $out = $this->addUserTemplateMarkers($out, $table, $field, $row, $PA);
1199 // String:
1200 $out = $this->intoTemplate($out);
1201 }
1202 }
1203 } else {
1204 $this->commentMessages[] = $this->prependFormFieldNames . '[' . $table . '][' . $row['uid'] . '][' . $field . ']: Disabled by TSconfig';
1205 }
1206 }
1207 // Hook: getSingleField_postProcess
1208 foreach ($this->hookObjectsSingleField as $hookObj) {
1209 if (method_exists($hookObj, 'getSingleField_postProcess')) {
1210 $hookObj->getSingleField_postProcess($table, $field, $row, $out, $PA, $this);
1211 }
1212 }
1213 // Return value (string or array)
1214 return $out;
1215 }
1216
1217 /**
1218 * Rendering a single item for the form
1219 *
1220 * @param string $table Table name of record
1221 * @param string $field Fieldname to render
1222 * @param array $row The record
1223 * @param array $PA Parameters array containing a lot of stuff. Value by Reference!
1224 * @return string Returns the item as HTML code to insert
1225 * @access private
1226 * @see getSingleField(), getSingleField_typeFlex_draw()
1227 * @todo Define visibility
1228 */
1229 public function getSingleField_SW($table, $field, $row, &$PA) {
1230 $PA['fieldConf']['config']['form_type'] = $PA['fieldConf']['config']['form_type'] ?: $PA['fieldConf']['config']['type'];
1231 // Using "form_type" locally in this script
1232 // Hook: getSingleField_beforeRender
1233 foreach ($this->hookObjectsSingleField as $hookObject) {
1234 if (method_exists($hookObject, 'getSingleField_beforeRender')) {
1235 $hookObject->getSingleField_beforeRender($table, $field, $row, $PA);
1236 }
1237 }
1238 switch ($PA['fieldConf']['config']['form_type']) {
1239 case 'input':
1240 $item = $this->getSingleField_typeInput($table, $field, $row, $PA);
1241 break;
1242 case 'text':
1243 $item = $this->getSingleField_typeText($table, $field, $row, $PA);
1244 break;
1245 case 'check':
1246 $item = $this->getSingleField_typeCheck($table, $field, $row, $PA);
1247 break;
1248 case 'radio':
1249 $item = $this->getSingleField_typeRadio($table, $field, $row, $PA);
1250 break;
1251 case 'select':
1252 $item = $this->getSingleField_typeSelect($table, $field, $row, $PA);
1253 break;
1254 case 'group':
1255 $item = $this->getSingleField_typeGroup($table, $field, $row, $PA);
1256 break;
1257 case 'inline':
1258 $item = $this->inline->getSingleField_typeInline($table, $field, $row, $PA);
1259 break;
1260 case 'none':
1261 $item = $this->getSingleField_typeNone($table, $field, $row, $PA);
1262 break;
1263 case 'user':
1264 $item = $this->getSingleField_typeUser($table, $field, $row, $PA);
1265 break;
1266 case 'flex':
1267 $item = $this->getSingleField_typeFlex($table, $field, $row, $PA);
1268 break;
1269 default:
1270 $item = $this->getSingleField_typeUnknown($table, $field, $row, $PA);
1271 }
1272 return $item;
1273 }
1274
1275 /**********************************************************
1276 *
1277 * Rendering of each TCEform field type
1278 *
1279 ************************************************************/
1280 /**
1281 * Generation of TCEform elements of the type "input"
1282 * This will render a single-line input form field, possibly with various control/validation features
1283 *
1284 * @param string $table The table name of the record
1285 * @param string $field The field name which this element is supposed to edit
1286 * @param array $row The record data array where the value(s) for the field can be found
1287 * @param array $PA An array with additional configuration options.
1288 * @return string The HTML code for the TCEform field
1289 * @todo Define visibility
1290 */
1291 public function getSingleField_typeInput($table, $field, $row, &$PA) {
1292 $config = $PA['fieldConf']['config'];
1293 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
1294 $size = MathUtility::forceIntegerInRange($config['size'] ? $config['size'] : 30, 5, $this->maxInputWidth);
1295 $evalList = GeneralUtility::trimExplode(',', $config['eval'], TRUE);
1296 $classAndStyleAttributes = $this->formWidthAsArray($size);
1297 $fieldAppendix = '';
1298 $item = '';
1299 $cssClasses = array($classAndStyleAttributes['class']);
1300 $cssStyle = $classAndStyleAttributes['style'];
1301 if (!isset($config['checkbox'])) {
1302 $config['checkbox'] = '0';
1303 $checkboxIsset = FALSE;
1304 } else {
1305 $checkboxIsset = TRUE;
1306 }
1307 if (in_array('date', $evalList) || in_array('datetime', $evalList)) {
1308 if (in_array('datetime', $evalList)) {
1309 $class = 'datetime';
1310 } else {
1311 $class = 'date';
1312 }
1313 $dateRange = '';
1314 if (isset($config['range']['lower'])) {
1315 $dateRange .= ' lower-' . (int)$config['range']['lower'];
1316 }
1317 if (isset($config['range']['upper'])) {
1318 $dateRange .= ' upper-' . (int)$config['range']['upper'];
1319 }
1320 $inputId = uniqid('tceforms-' . $class . 'field-');
1321 $cssClasses[] = 'tceforms-textfield tceforms-' . $class . 'field' . $dateRange;
1322 $fieldAppendix = IconUtility::getSpriteIcon('actions-edit-pick-date', array(
1323 'style' => 'cursor:pointer;',
1324 'id' => 'picker-' . $inputId
1325 ));
1326 } elseif (in_array('timesec', $evalList)) {
1327 $inputId = uniqid('tceforms-timesecfield-');
1328 $cssClasses[] = 'tceforms-textfield tceforms-timesecfield';
1329 } elseif (in_array('year', $evalList)) {
1330 $inputId = uniqid('tceforms-yearfield-');
1331 $cssClasses[] = 'tceforms-textfield tceforms-yearfield';
1332 } elseif (in_array('time', $evalList)) {
1333 $inputId = uniqid('tceforms-timefield-');
1334 $cssClasses[] = 'tceforms-textfield tceforms-timefield';
1335 } elseif (in_array('int', $evalList)) {
1336 $inputId = uniqid('tceforms-intfield-');
1337 $cssClasses[] = 'tceforms-textfield tceforms-intfield';
1338 } elseif (in_array('double2', $evalList)) {
1339 $inputId = uniqid('tceforms-double2field-');
1340 $cssClasses[] = 'tceforms-textfield tceforms-double2field';
1341 } else {
1342 $inputId = uniqid('tceforms-textfield-');
1343 $cssClasses[] = 'tceforms-textfield';
1344 if ($checkboxIsset === FALSE) {
1345 $config['checkbox'] = '';
1346 }
1347 }
1348 if (isset($config['wizards']['link'])) {
1349 $inputId = uniqid('tceforms-linkfield-');
1350 $cssClasses[] = 'tceforms-textfield tceforms-linkfield';
1351 } elseif (isset($config['wizards']['color'])) {
1352 $inputId = uniqid('tceforms-colorfield-');
1353 $cssClasses[] = 'tceforms-textfield tceforms-colorfield';
1354 }
1355 if ($this->renderReadonly || $config['readOnly']) {
1356 $itemFormElValue = $PA['itemFormElValue'];
1357 if (in_array('date', $evalList)) {
1358 $config['format'] = 'date';
1359 } elseif (in_array('datetime', $evalList)) {
1360 $config['format'] = 'datetime';
1361 } elseif (in_array('time', $evalList)) {
1362 $config['format'] = 'time';
1363 }
1364 if (in_array('password', $evalList)) {
1365 $itemFormElValue = $itemFormElValue ? '*********' : '';
1366 }
1367 return $this->getSingleField_typeNone_render($config, $itemFormElValue);
1368 }
1369 foreach ($evalList as $func) {
1370 switch ($func) {
1371 case 'required':
1372 $this->registerRequiredProperty('field', $table . '_' . $row['uid'] . '_' . $field, $PA['itemFormElName']);
1373 // Mark this field for date/time disposal:
1374 if (array_intersect($evalList, array('date', 'datetime', 'time'))) {
1375 $this->requiredAdditional[$PA['itemFormElName']]['isPositiveNumber'] = TRUE;
1376 }
1377 break;
1378 default:
1379 // Pair hook to the one in \TYPO3\CMS\Core\DataHandling\DataHandler::checkValue_input_Eval()
1380 $evalObj = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func] . ':&' . $func);
1381 if (is_object($evalObj) && method_exists($evalObj, 'deevaluateFieldValue')) {
1382 $_params = array(
1383 'value' => $PA['itemFormElValue']
1384 );
1385 $PA['itemFormElValue'] = $evalObj->deevaluateFieldValue($_params);
1386 }
1387 }
1388 }
1389 $paramsList = '\'' . $PA['itemFormElName'] . '\',\'' . implode(',', $evalList) . '\',\'' . trim($config['is_in']) . '\',' . (isset($config['checkbox']) ? 1 : 0) . ',\'' . $config['checkbox'] . '\'';
1390 if (in_array('date', $evalList) || in_array('datetime', $evalList)) {
1391 $item .= '<span class="t3-tceforms-input-wrapper-datetime" onmouseOver="if (document.getElementById(\'' . $inputId . '\').value) {this.className=\'t3-tceforms-input-wrapper-datetime-hover\';} else {this.className=\'t3-tceforms-input-wrapper-datetime\';};" onmouseOut="this.className=\'t3-tceforms-input-wrapper-datetime\';">';
1392 // Add server timezone offset to UTC to our stored date
1393 if ($PA['itemFormElValue'] > 0) {
1394 $PA['itemFormElValue'] += date('Z', $PA['itemFormElValue']);
1395 }
1396 } else {
1397 $item .= '<span class="t3-tceforms-input-wrapper" onmouseOver="if (document.getElementById(\'' . $inputId . '\').value) {this.className=\'t3-tceforms-input-wrapper-hover\';} else {this.className=\'t3-tceforms-input-wrapper\';};" onmouseOut="this.className=\'t3-tceforms-input-wrapper\';">';
1398 }
1399 $PA['fieldChangeFunc'] = array_merge(array('typo3form.fieldGet' => 'typo3form.fieldGet(' . $paramsList . ');'), $PA['fieldChangeFunc']);
1400 // Old function "checkbox" now the option to set the date / remove the date
1401 if (isset($config['checkbox'])) {
1402 $item .= IconUtility::getSpriteIcon('actions-input-clear', array('tag' => 'a', 'class' => 't3-tceforms-input-clearer', 'onclick' => 'document.getElementById(\'' . $inputId . '\').value=\'\';document.getElementById(\'' . $inputId . '\').focus();' . implode('', $PA['fieldChangeFunc'])));
1403 }
1404 $mLgd = $config['max'] ?: 256;
1405 $iOnChange = implode('', $PA['fieldChangeFunc']);
1406 $cssClasses[] = 'hasDefaultValue';
1407 $item .= '<input type="text" ' . $this->getPlaceholderAttribute($table, $field, $config, $row) . 'id="' . $inputId . '" ' . 'class="' . implode(' ', $cssClasses) . '" ' . 'name="' . $PA['itemFormElName'] . '_hr" ' . 'value=""' . 'style="' . $cssStyle . '" ' . 'maxlength="' . $mLgd . '" ' . 'onchange="' . htmlspecialchars($iOnChange) . '"' . $PA['onFocus'] . ' />';
1408 // This is the EDITABLE form field.
1409 $item .= '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($PA['itemFormElValue']) . '" />';
1410 // This is the ACTUAL form field - values from the EDITABLE field must be transferred to this field which is the one that is written to the database.
1411 $item .= $fieldAppendix . '</span><div style="clear:both;"></div>';
1412 $this->extJSCODE .= 'typo3form.fieldSet(' . $paramsList . ');';
1413 // Going through all custom evaluations configured for this field
1414 foreach ($evalList as $evalData) {
1415 $evalObj = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$evalData] . ':&' . $evalData);
1416 if (is_object($evalObj) && method_exists($evalObj, 'returnFieldJS')) {
1417 $this->extJSCODE .= '
1418 TBE_EDITOR.customEvalFunctions[\'' . $evalData . '\'] = function(value) {
1419 ' . $evalObj->returnFieldJS() . '
1420 }
1421 ';
1422 }
1423 }
1424 // Creating an alternative item without the JavaScript handlers.
1425 $altItem = '<input type="hidden" name="' . $PA['itemFormElName'] . '_hr" value="" />';
1426 $altItem .= '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($PA['itemFormElValue']) . '" />';
1427 // Wrap a wizard around the item?
1428 $item = $this->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA, $PA['itemFormElName'] . '_hr', $specConf);
1429
1430 return $item;
1431 }
1432
1433 /**
1434 * Renders a view widget to handle and activate NULL values.
1435 * The widget is enabled by using 'null' in the 'eval' TCA definition.
1436 *
1437 * @param string $table Name of the table
1438 * @param string $field Name of the field
1439 * @param array $row Accordant data of the record row
1440 * @param array $PA Parameters array with rendering instructions
1441 * @return string Widget (if any).
1442 */
1443 protected function renderNullValueWidget($table, $field, array $row, array $PA) {
1444 $widget = '';
1445
1446 $config = $PA['fieldConf']['config'];
1447 if (!empty($config['eval']) && GeneralUtility::inList($config['eval'], 'null') && (empty($config['mode']) || $config['mode'] !== 'useOrOverridePlaceholder')) {
1448 $isNull = ($PA['itemFormElValue'] === NULL);
1449
1450 $checked = ($isNull ? '' : ' checked="checked"');
1451 $onChange = htmlspecialchars(
1452 'typo3form.fieldSetNull(\'' . $PA['itemFormElName'] . '\', !this.checked)'
1453 );
1454
1455 $widget = '<span class="t3-tceforms-widget-null-wrapper">' .
1456 '<input type="hidden" name="' . $PA['itemFormElNameActive'] . '" value="0" />' .
1457 '<input type="checkbox" name="' . $PA['itemFormElNameActive'] . '" value="1" onchange="' . $onChange . '"' . $checked . ' />' .
1458 '</span>';
1459 }
1460
1461 return $widget;
1462 }
1463
1464 /**
1465 * Determines whether the current field value is considered as NULL value.
1466 * Using NULL values is enabled by using 'null' in the 'eval' TCA definition.
1467 *
1468 * @param string $table Name of the table
1469 * @param string $field Name of the field
1470 * @param array $row Accordant data
1471 * @param array $PA Parameters array with rendering instructions
1472 * @return boolean
1473 */
1474 protected function isDisabledNullValueField($table, $field, array $row, array $PA) {
1475 $result = FALSE;
1476
1477 $config = $PA['fieldConf']['config'];
1478 if ($PA['itemFormElValue'] === NULL && !empty($config['eval'])
1479 && GeneralUtility::inList($config['eval'], 'null')
1480 && (empty($config['mode']) || $config['mode'] !== 'useOrOverridePlaceholder')) {
1481
1482 $result = TRUE;
1483 }
1484
1485 return $result;
1486 }
1487
1488 /**
1489 * Generation of TCEform elements of the type "text"
1490 * This will render a <textarea> OR RTE area form field, possibly with various control/validation features
1491 *
1492 * @param string $table The table name of the record
1493 * @param string $field The field name which this element is supposed to edit
1494 * @param array $row The record data array where the value(s) for the field can be found
1495 * @param array $PA An array with additional configuration options.
1496 * @return string The HTML code for the TCEform field
1497 * @todo Define visibility
1498 */
1499 public function getSingleField_typeText($table, $field, $row, &$PA) {
1500 // Init config:
1501 $config = $PA['fieldConf']['config'];
1502 $evalList = GeneralUtility::trimExplode(',', $config['eval'], TRUE);
1503 if ($this->renderReadonly || $config['readOnly']) {
1504 return $this->getSingleField_typeNone_render($config, $PA['itemFormElValue']);
1505 }
1506 // Setting columns number:
1507 $cols = MathUtility::forceIntegerInRange($config['cols'] ? $config['cols'] : 30, 5, $this->maxTextareaWidth);
1508 // Setting number of rows:
1509 $origRows = ($rows = MathUtility::forceIntegerInRange($config['rows'] ? $config['rows'] : 5, 1, 20));
1510 if (strlen($PA['itemFormElValue']) > $this->charsPerRow * 2) {
1511 $cols = $this->maxTextareaWidth;
1512 $rows = MathUtility::forceIntegerInRange(round(strlen($PA['itemFormElValue']) / $this->charsPerRow), count(explode(LF, $PA['itemFormElValue'])), 20);
1513 if ($rows < $origRows) {
1514 $rows = $origRows;
1515 }
1516 }
1517 if (in_array('required', $evalList)) {
1518 $this->requiredFields[$table . '_' . $row['uid'] . '_' . $field] = $PA['itemFormElName'];
1519 }
1520 // Init RTE vars:
1521 // Set TRUE, if the RTE is loaded; If not a normal textarea is shown.
1522 $RTEwasLoaded = 0;
1523 // Set TRUE, if the RTE would have been loaded if it wasn't for the disable-RTE flag in the bottom of the page...
1524 $RTEwouldHaveBeenLoaded = 0;
1525 // "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist. Traditionally, this is where RTE configuration has been found.
1526 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
1527 // Setting up the altItem form field, which is a hidden field containing the value
1528 $altItem = '<input type="hidden" name="' . htmlspecialchars($PA['itemFormElName']) . '" value="' . htmlspecialchars($PA['itemFormElValue']) . '" />';
1529 // If RTE is generally enabled (TYPO3_CONF_VARS and user settings)
1530 if ($this->RTEenabled) {
1531 $p = BackendUtility::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']);
1532 // If the field is configured for RTE and if any flag-field is not set to disable it.
1533 if (isset($specConf['richtext']) && (!$p['flag'] || !$row[$p['flag']])) {
1534 BackendUtility::fixVersioningPid($table, $row);
1535 list($tscPID, $thePidValue) = $this->getTSCpid($table, $row['uid'], $row['pid']);
1536 // If the pid-value is not negative (that is, a pid could NOT be fetched)
1537 if ($thePidValue >= 0) {
1538 $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', BackendUtility::getPagesTSconfig($tscPID));
1539 $RTEtypeVal = BackendUtility::getTCAtypeValue($table, $row);
1540 $thisConfig = BackendUtility::RTEsetup($RTEsetup['properties'], $table, $field, $RTEtypeVal);
1541 if (!$thisConfig['disabled']) {
1542 if (!$this->disableRTE) {
1543 $this->RTEcounter++;
1544 // Find alternative relative path for RTE images/links:
1545 $eFile = \TYPO3\CMS\Core\Html\RteHtmlParser::evalWriteFile($specConf['static_write'], $row);
1546 $RTErelPath = is_array($eFile) ? dirname($eFile['relEditFile']) : '';
1547 // Get RTE object, draw form and set flag:
1548 $RTEobj = BackendUtility::RTEgetObj();
1549 $item = $RTEobj->drawRTE($this, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue);
1550 // Wizard:
1551 $item = $this->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA, $PA['itemFormElName'], $specConf, 1);
1552 $RTEwasLoaded = 1;
1553 } else {
1554 $RTEwouldHaveBeenLoaded = 1;
1555 $this->commentMessages[] = $PA['itemFormElName'] . ': RTE is disabled by the on-page RTE-flag (probably you can enable it by the check-box in the bottom of this page!)';
1556 }
1557 } else {
1558 $this->commentMessages[] = $PA['itemFormElName'] . ': RTE is disabled by the Page TSconfig, "RTE"-key (eg. by RTE.default.disabled=0 or such)';
1559 }
1560 } else {
1561 $this->commentMessages[] = $PA['itemFormElName'] . ': PID value could NOT be fetched. Rare error, normally with new records.';
1562 }
1563 } else {
1564 if (!isset($specConf['richtext'])) {
1565 $this->commentMessages[] = $PA['itemFormElName'] . ': RTE was not configured for this field in TCA-types';
1566 }
1567 if (!(!$p['flag'] || !$row[$p['flag']])) {
1568 $this->commentMessages[] = $PA['itemFormElName'] . ': Field-flag (' . $PA['flag'] . ') has been set to disable RTE!';
1569 }
1570 }
1571 }
1572 // Display ordinary field if RTE was not loaded.
1573 if (!$RTEwasLoaded) {
1574 // Show message, if no RTE (field can only be edited with RTE!)
1575 if ($specConf['rte_only']) {
1576 $item = '<p><em>' . htmlspecialchars($this->getLL('l_noRTEfound')) . '</em></p>';
1577 } else {
1578 if ($specConf['nowrap']) {
1579 $wrap = 'off';
1580 } else {
1581 $wrap = $config['wrap'] ?: 'virtual';
1582 }
1583 $classes = array();
1584 if ($specConf['fixed-font']) {
1585 $classes[] = 'fixed-font';
1586 }
1587 if ($specConf['enable-tab']) {
1588 $classes[] = 'enable-tab';
1589 }
1590 $formWidthText = $this->formWidthText($cols, $wrap);
1591 // Extract class attributes from $formWidthText (otherwise it would be added twice to the output)
1592 $res = array();
1593 if (preg_match('/ class="(.+?)"/', $formWidthText, $res)) {
1594 $formWidthText = str_replace(' class="' . $res[1] . '"', '', $formWidthText);
1595 $classes = array_merge($classes, explode(' ', $res[1]));
1596 }
1597 if (count($classes)) {
1598 $class = ' class="tceforms-textarea ' . implode(' ', $classes) . '"';
1599 } else {
1600 $class = 'tceforms-textarea';
1601 }
1602 $evalList = GeneralUtility::trimExplode(',', $config['eval'], TRUE);
1603 foreach ($evalList as $func) {
1604 switch ($func) {
1605 case 'required':
1606 $this->registerRequiredProperty('field', $table . '_' . $row['uid'] . '_' . $field, $PA['itemFormElName']);
1607 break;
1608 default:
1609 // Pair hook to the one in \TYPO3\CMS\Core\DataHandling\DataHandler::checkValue_input_Eval() and \TYPO3\CMS\Core\DataHandling\DataHandler::checkValue_text_Eval()
1610 $evalObj = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func] . ':&' . $func);
1611 if (is_object($evalObj) && method_exists($evalObj, 'deevaluateFieldValue')) {
1612 $_params = array(
1613 'value' => $PA['itemFormElValue']
1614 );
1615 $PA['itemFormElValue'] = $evalObj->deevaluateFieldValue($_params);
1616 }
1617 }
1618 }
1619 $iOnChange = implode('', $PA['fieldChangeFunc']);
1620 $item .= '
1621 <textarea ' . 'id="' . uniqid('tceforms-textarea-') . '" ' . 'name="' . $PA['itemFormElName'] . '"' . $formWidthText . $class . ' ' . 'rows="' . $rows . '" ' . 'wrap="' . $wrap . '" ' . 'onchange="' . htmlspecialchars($iOnChange) . '"' . $this->getPlaceholderAttribute($table, $field, $config, $row) . $PA['onFocus'] . '>' . GeneralUtility::formatForTextarea($PA['itemFormElValue']) . '</textarea>';
1622 $item = $this->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA, $PA['itemFormElName'], $specConf, $RTEwouldHaveBeenLoaded);
1623 }
1624 }
1625 // Return field HTML:
1626 return $item;
1627 }
1628
1629 /**
1630 * Generation of TCEform elements of the type "check"
1631 * This will render a check-box OR an array of checkboxes
1632 *
1633 * @param string $table The table name of the record
1634 * @param string $field The field name which this element is supposed to edit
1635 * @param array $row The record data array where the value(s) for the field can be found
1636 * @param array $PA An array with additional configuration options.
1637 * @return string The HTML code for the TCEform field
1638 * @todo Define visibility
1639 */
1640 public function getSingleField_typeCheck($table, $field, $row, &$PA) {
1641 $config = $PA['fieldConf']['config'];
1642 $item = '';
1643 $disabled = '';
1644 if ($this->renderReadonly || $config['readOnly']) {
1645 $disabled = ' disabled="disabled"';
1646 }
1647 // Traversing the array of items:
1648 $selItems = $this->initItemArray($PA['fieldConf']);
1649 if ($config['itemsProcFunc']) {
1650 $selItems = $this->procItems($selItems, $PA['fieldTSConfig']['itemsProcFunc.'], $config, $table, $row, $field);
1651 }
1652 if (!count($selItems)) {
1653 $selItems[] = array('', '');
1654 }
1655 $thisValue = (int)$PA['itemFormElValue'];
1656 $cols = (int)$config['cols'];
1657 $selItemsCount = count($selItems);
1658 if ($cols > 1) {
1659 $item .= '<table border="0" cellspacing="0" cellpadding="0" class="typo3-TCEforms-checkboxArray">';
1660 for ($c = 0; $c < $selItemsCount; $c++) {
1661 $p = $selItems[$c];
1662 if (!($c % $cols)) {
1663 $item .= '<tr>';
1664 }
1665 $cBP = $this->checkBoxParams($PA['itemFormElName'], $thisValue, $c, count($selItems), implode('', $PA['fieldChangeFunc']));
1666 $cBName = $PA['itemFormElName'] . '_' . $c;
1667 $cBID = $PA['itemFormElID'] . '_' . $c;
1668 $item .= '<td nowrap="nowrap">' . '<input type="checkbox"' . $this->insertDefStyle('check') . ' value="1" name="' . $cBName . '"' . $cBP . $disabled . ' id="' . $cBID . '" />' . $this->wrapLabels(('<label for="' . $cBID . '">' . htmlspecialchars($p[0]) . '</label>&nbsp;')) . '</td>';
1669 if ($c % $cols + 1 == $cols) {
1670 $item .= '</tr>';
1671 }
1672 }
1673 if ($c % $cols) {
1674 $rest = $cols - $c % $cols;
1675 for ($c = 0; $c < $rest; $c++) {
1676 $item .= '<td></td>';
1677 }
1678 if ($c > 0) {
1679 $item .= '</tr>';
1680 }
1681 }
1682 $item .= '</table>';
1683 } else {
1684 for ($c = 0; $c < $selItemsCount; $c++) {
1685 $p = $selItems[$c];
1686 $cBP = $this->checkBoxParams($PA['itemFormElName'], $thisValue, $c, count($selItems), implode('', $PA['fieldChangeFunc']));
1687 $cBName = $PA['itemFormElName'] . '_' . $c;
1688 $cBID = $PA['itemFormElID'] . '_' . $c;
1689 $item .= ($c > 0 ? '<br />' : '') . '<input type="checkbox"' . $this->insertDefStyle('check') . ' value="1" name="' . $cBName . '"' . $cBP . $PA['onFocus'] . $disabled . ' id="' . $cBID . '" />' . $this->wrapLabels(('<label for="' . $cBID . '">' . htmlspecialchars($p[0]) . '</label>'));
1690 }
1691 }
1692 if (!$disabled) {
1693 $item .= '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($thisValue) . '" />';
1694 }
1695 return $item;
1696 }
1697
1698 /**
1699 * Generation of TCEform elements of the type "radio"
1700 * This will render a series of radio buttons.
1701 *
1702 * @param string $table The table name of the record
1703 * @param string $field The field name which this element is supposed to edit
1704 * @param array $row The record data array where the value(s) for the field can be found
1705 * @param array $PA An array with additional configuration options.
1706 * @return string The HTML code for the TCEform field
1707 * @todo Define visibility
1708 */
1709 public function getSingleField_typeRadio($table, $field, $row, &$PA) {
1710 $config = $PA['fieldConf']['config'];
1711 $item = '';
1712 $disabled = '';
1713 if ($this->renderReadonly || $config['readOnly']) {
1714 $disabled = ' disabled="disabled"';
1715 }
1716 // Get items for the array:
1717 $selItems = $this->initItemArray($PA['fieldConf']);
1718 if ($config['itemsProcFunc']) {
1719 $selItems = $this->procItems($selItems, $PA['fieldTSConfig']['itemsProcFunc.'], $config, $table, $row, $field);
1720 }
1721 // Traverse the items, making the form elements:
1722 $selItemsCount = count($selItems);
1723 for ($c = 0; $c < $selItemsCount; $c++) {
1724 $p = $selItems[$c];
1725 $rID = $PA['itemFormElID'] . '_' . $c;
1726 $rOnClick = implode('', $PA['fieldChangeFunc']);
1727 $rChecked = (string)$p[1] === (string)$PA['itemFormElValue'] ? ' checked="checked"' : '';
1728 $item .= '<input type="radio"' . $this->insertDefStyle('radio') . ' name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($p[1]) . '" onclick="' . htmlspecialchars($rOnClick) . '"' . $rChecked . $PA['onFocus'] . $disabled . ' id="' . $rID . '" />
1729 <label for="' . $rID . '">' . htmlspecialchars($p[0]) . '</label>
1730 <br />';
1731 }
1732 return $item;
1733 }
1734
1735 /**
1736 * Generation of TCEform elements of the type "select"
1737 * This will render a selector box element, or possibly a special construction with two selector boxes. That depends on configuration.
1738 *
1739 * @param string $table The table name of the record
1740 * @param string $field The field name which this element is supposed to edit
1741 * @param array $row The record data array where the value(s) for the field can be found
1742 * @param array $PA An array with additional configuration options.
1743 * @return string The HTML code for the TCEform field
1744 * @todo Define visibility
1745 */
1746 public function getSingleField_typeSelect($table, $field, $row, &$PA) {
1747 // Field configuration from TCA:
1748 $config = $PA['fieldConf']['config'];
1749 $disabled = '';
1750 if ($this->renderReadonly || $config['readOnly']) {
1751 $disabled = ' disabled="disabled"';
1752 }
1753 // "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist. See http://typo3.org/documentation/document-library/doc_core_api/Wizards_Configuratio/.
1754 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
1755 $selItems = $this->getSelectItems($table, $field, $row, $PA);
1756
1757 // Creating the label for the "No Matching Value" entry.
1758 $nMV_label = isset($PA['fieldTSConfig']['noMatchingValue_label']) ? $this->sL($PA['fieldTSConfig']['noMatchingValue_label']) : '[ ' . $this->getLL('l_noMatchingValue') . ' ]';
1759 // Prepare some values:
1760 $maxitems = (int)$config['maxitems'];
1761 // If a SINGLE selector box...
1762 if ($maxitems <= 1 && $config['renderMode'] !== 'tree') {
1763 $item = $this->getSingleField_typeSelect_single($table, $field, $row, $PA, $config, $selItems, $nMV_label);
1764 } elseif ($config['renderMode'] === 'checkbox') {
1765 // Checkbox renderMode
1766 $item = $this->getSingleField_typeSelect_checkbox($table, $field, $row, $PA, $config, $selItems, $nMV_label);
1767 } elseif ($config['renderMode'] === 'singlebox') {
1768 // Single selector box renderMode
1769 $item = $this->getSingleField_typeSelect_singlebox($table, $field, $row, $PA, $config, $selItems, $nMV_label);
1770 } elseif ($config['renderMode'] === 'tree') {
1771 // Tree renderMode
1772 $treeClass = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\Element\\TreeElement', $this);
1773 $item = $treeClass->renderField($table, $field, $row, $PA, $config, $selItems, $nMV_label);
1774 // Register the required number of elements
1775 $minitems = MathUtility::forceIntegerInRange($config['minitems'], 0);
1776 $this->registerRequiredProperty('range', $PA['itemFormElName'], array($minitems, $maxitems, 'imgName' => $table . '_' . $row['uid'] . '_' . $field));
1777 } else {
1778 // Traditional multiple selector box:
1779 $item = $this->getSingleField_typeSelect_multiple($table, $field, $row, $PA, $config, $selItems, $nMV_label);
1780 }
1781 // Wizards:
1782 if (!$disabled) {
1783 $altItem = '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($PA['itemFormElValue']) . '" />';
1784 $item = $this->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA, $PA['itemFormElName'], $specConf);
1785 }
1786 return $item;
1787 }
1788
1789 /**
1790 * Collects the items for a select field by reading the configured
1791 * select items from the configuration and / or by collecting them
1792 * from a foreign table.
1793 *
1794 * @param string $table The table name of the record
1795 * @param string $fieldName The select field name
1796 * @param array $row The record data array where the value(s) for the field can be found
1797 * @param array $PA An array with additional configuration options.
1798 * @return array
1799 */
1800 public function getSelectItems($table, $fieldName, array $row, array $PA) {
1801 $config = $PA['fieldConf']['config'];
1802
1803 // Getting the selector box items from the system
1804 $selectItems = $this->addSelectOptionsToItemArray(
1805 $this->initItemArray($PA['fieldConf']),
1806 $PA['fieldConf'],
1807 $this->setTSconfig($table, $row),
1808 $fieldName
1809 );
1810
1811 // Possibly filter some items:
1812 $selectItems = GeneralUtility::keepItemsInArray(
1813 $selectItems,
1814 $PA['fieldTSConfig']['keepItems'],
1815 function ($value) {
1816 return $value[1];
1817 }
1818 );
1819
1820 // Possibly add some items:
1821 $selectItems = $this->addItems($selectItems, $PA['fieldTSConfig']['addItems.']);
1822
1823 // Process items by a user function:
1824 if (isset($config['itemsProcFunc']) && $config['itemsProcFunc']) {
1825 $selectItems = $this->procItems($selectItems, $PA['fieldTSConfig']['itemsProcFunc.'], $config, $table, $row, $fieldName);
1826 }
1827
1828 // Possibly remove some items:
1829 $removeItems = GeneralUtility::trimExplode(',', $PA['fieldTSConfig']['removeItems'], TRUE);
1830 foreach ($selectItems as $selectItemIndex => $selectItem) {
1831
1832 // Checking languages and authMode:
1833 $languageDeny = FALSE;
1834 if (
1835 !empty($GLOBALS['TCA'][$table]['ctrl']['languageField'])
1836 && $GLOBALS['TCA'][$table]['ctrl']['languageField'] === $fieldName
1837 && !$GLOBALS['BE_USER']->checkLanguageAccess($selectItem[1])
1838 ) {
1839 $languageDeny = TRUE;
1840 }
1841
1842 $authModeDeny = FALSE;
1843 if (
1844 ($config['form_type'] === 'select')
1845 && $config['authMode']
1846 && !$GLOBALS['BE_USER']->checkAuthMode($table, $fieldName, $selectItem[1], $config['authMode'])
1847 ) {
1848 $authModeDeny = TRUE;
1849 }
1850
1851 if (in_array($selectItem[1], $removeItems) || $languageDeny || $authModeDeny) {
1852 unset($selectItems[$selectItemIndex]);
1853 } elseif (isset($PA['fieldTSConfig']['altLabels.'][$selectItem[1]])) {
1854 $selectItems[$selectItemIndex][0] = htmlspecialchars($this->sL($PA['fieldTSConfig']['altLabels.'][$selectItem[1]]));
1855 }
1856
1857 // Removing doktypes with no access:
1858 if (($table === 'pages' || $table === 'pages_language_overlay') && $fieldName === 'doktype') {
1859 if (!($GLOBALS['BE_USER']->isAdmin() || GeneralUtility::inList($GLOBALS['BE_USER']->groupData['pagetypes_select'], $selectItem[1]))) {
1860 unset($selectItems[$selectItemIndex]);
1861 }
1862 }
1863 }
1864
1865 return $selectItems;
1866 }
1867
1868 /**
1869 * Creates a single-selector box
1870 * (Render function for getSingleField_typeSelect())
1871 *
1872 * @param string $table See getSingleField_typeSelect()
1873 * @param string $field See getSingleField_typeSelect()
1874 * @param array $row See getSingleField_typeSelect()
1875 * @param array $PA See getSingleField_typeSelect()
1876 * @param array $config (Redundant) content of $PA['fieldConf']['config'] (for convenience)
1877 * @param array $selItems Items available for selection
1878 * @param string $nMV_label Label for no-matching-value
1879 * @return string The HTML code for the item
1880 * @see getSingleField_typeSelect()
1881 * @todo Define visibility
1882 */
1883 public function getSingleField_typeSelect_single($table, $field, $row, &$PA, $config, $selItems, $nMV_label) {
1884 // check against inline uniqueness
1885 $inlineParent = $this->inline->getStructureLevel(-1);
1886 if (is_array($inlineParent) && $inlineParent['uid']) {
1887 if ($inlineParent['config']['foreign_table'] == $table && $inlineParent['config']['foreign_unique'] == $field) {
1888 $uniqueIds = $this->inline->inlineData['unique'][$this->inline->inlineNames['object'] . InlineElement::Structure_Separator . $table]['used'];
1889 $PA['fieldChangeFunc']['inlineUnique'] = 'inline.updateUnique(this,\'' . $this->inline->inlineNames['object'] . InlineElement::Structure_Separator . $table . '\',\'' . $this->inline->inlineNames['form'] . '\',\'' . $row['uid'] . '\');';
1890 }
1891 // hide uid of parent record for symmetric relations
1892 if ($inlineParent['config']['foreign_table'] == $table && ($inlineParent['config']['foreign_field'] == $field || $inlineParent['config']['symmetric_field'] == $field)) {
1893 $uniqueIds[] = $inlineParent['uid'];
1894 }
1895 }
1896 // Initialization:
1897 $c = 0;
1898 $sI = 0;
1899 $noMatchingValue = 1;
1900 $opt = array();
1901 $selicons = array();
1902 $onlySelectedIconShown = 0;
1903 $size = (int)$config['size'];
1904 // Style set on <select/>
1905 $selectedStyle = '';
1906 $item = '';
1907 $disabled = '';
1908 // TODO: icon is used but never assigned
1909 $onChangeIcon = '';
1910 if ($this->renderReadonly || $config['readOnly']) {
1911 $disabled = ' disabled="disabled"';
1912 $onlySelectedIconShown = 1;
1913 }
1914 // Icon configuration:
1915 if ($config['suppress_icons'] == 'IF_VALUE_FALSE') {
1916 $suppressIcons = !$PA['itemFormElValue'] ? 1 : 0;
1917 } elseif ($config['suppress_icons'] == 'ONLY_SELECTED') {
1918 $suppressIcons = 0;
1919 $onlySelectedIconShown = 1;
1920 } elseif ($config['suppress_icons']) {
1921 $suppressIcons = 1;
1922 } else {
1923 $suppressIcons = 0;
1924 }
1925 // Traverse the Array of selector box items:
1926 $optGroupStart = array();
1927 $optGroupOpen = FALSE;
1928 $classesForSelectTag = array();
1929 foreach ($selItems as $p) {
1930 $sM = (string)$PA['itemFormElValue'] === (string)$p[1] ? ' selected="selected"' : '';
1931 if ($sM) {
1932 $sI = $c;
1933 $noMatchingValue = 0;
1934 }
1935 // Getting style attribute value (for icons):
1936 if ($config['iconsInOptionTags']) {
1937 $styleAttrValue = $this->optionTagStyle($p[2]);
1938 if ($sM) {
1939 list($selectIconFile, $selectIconInfo) = $this->getIcon($p[2]);
1940 if (!empty($selectIconInfo)) {
1941 $selectedStyle = ' style="background-image:url(' . $selectIconFile . ');"';
1942 $classesForSelectTag[] = 'typo3-TCEforms-select-selectedItemWithBackgroundImage';
1943 }
1944 }
1945 }
1946 // Compiling the <option> tag:
1947 if (!($p[1] != $PA['itemFormElValue'] && is_array($uniqueIds) && in_array($p[1], $uniqueIds))) {
1948 if ($p[1] === '--div--') {
1949 $optGroupStart[0] = $p[0];
1950 if ($config['iconsInOptionTags']) {
1951 $optGroupStart[1] = $this->optgroupTagStyle($p[2]);
1952 } else {
1953 $optGroupStart[1] = $styleAttrValue;
1954 }
1955 } else {
1956 if (count($optGroupStart)) {
1957 // Closing last optgroup before next one starts
1958 if ($optGroupOpen) {
1959 $opt[] = '</optgroup>' . LF;
1960 }
1961 $opt[] = '<optgroup label="' . GeneralUtility::deHSCentities(htmlspecialchars($optGroupStart[0])) . '"' . ($optGroupStart[1] ? ' style="' . htmlspecialchars($optGroupStart[1]) . '"' : '') . ' class="c-divider">' . LF;
1962 $optGroupOpen = TRUE;
1963 $c--;
1964 $optGroupStart = array();
1965 }
1966 $opt[] = '<option value="' . htmlspecialchars($p[1]) . '"' . $sM . ($styleAttrValue ? ' style="' . htmlspecialchars($styleAttrValue) . '"' : '') . '>' . GeneralUtility::deHSCentities($p[0]) . '</option>' . LF;
1967 }
1968 }
1969 // If there is an icon for the selector box (rendered in selicon-table below)...:
1970 // if there is an icon ($p[2]), icons should be shown, and, if only selected are visible, is it selected
1971 if ($p[2] && !$suppressIcons && (!$onlySelectedIconShown || $sM)) {
1972 list($selIconFile, $selIconInfo) = $this->getIcon($p[2]);
1973 if (!empty($selIconInfo)) {
1974 $iOnClick = $this->elName($PA['itemFormElName']) . '.selectedIndex=' . $c . '; ' . $this->elName($PA['itemFormElName']) . '.style.backgroundImage=' . $this->elName($PA['itemFormElName']) . '.options[' . $c . '].style.backgroundImage; ' . implode('', $PA['fieldChangeFunc']) . $this->blur() . 'return false;';
1975 } else {
1976 $iOnClick = $this->elName($PA['itemFormElName']) . '.selectedIndex=' . $c . '; ' . $this->elName($PA['itemFormElName']) . '.className=' . $this->elName($PA['itemFormElName']) . '.options[' . $c . '].className; ' . implode('', $PA['fieldChangeFunc']) . $this->blur() . 'return false;';
1977 }
1978 $selicons[] = array(
1979 (!$onlySelectedIconShown ? '<a href="#" onclick="' . htmlspecialchars($iOnClick) . '">' : '') . $this->getIconHtml($p[2], htmlspecialchars($p[0]), htmlspecialchars($p[0])) . (!$onlySelectedIconShown ? '</a>' : ''),
1980 $c,
1981 $sM
1982 );
1983 }
1984 $c++;
1985 }
1986 // Closing optgroup if open
1987 if ($optGroupOpen) {
1988 $opt[] = '</optgroup>';
1989 $optGroupOpen = FALSE;
1990 }
1991 // No-matching-value:
1992 if ($PA['itemFormElValue'] && $noMatchingValue && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
1993 $nMV_label = @sprintf($nMV_label, $PA['itemFormElValue']);
1994 $opt[] = '<option value="' . htmlspecialchars($PA['itemFormElValue']) . '" selected="selected">' . htmlspecialchars($nMV_label) . '</option>';
1995 }
1996 // Create item form fields:
1997 $sOnChange = 'if (this.options[this.selectedIndex].value==\'--div--\') {this.selectedIndex=' . $sI . ';} ' . implode('', $PA['fieldChangeFunc']);
1998 if (!$disabled) {
1999 // MUST be inserted before the selector - else is the value of the hiddenfield here mysteriously submitted...
2000 $item .= '<input type="hidden" name="' . $PA['itemFormElName'] . '_selIconVal" value="' . htmlspecialchars($sI) . '" />';
2001 }
2002 if ($config['iconsInOptionTags']) {
2003 $classesForSelectTag[] = 'icon-select';
2004 }
2005 $item .= '<select' . $selectedStyle . ' id="' . uniqid('tceforms-select-') . '" name="' . $PA['itemFormElName'] . '"' . $this->insertDefStyle('select', implode(' ', $classesForSelectTag)) . ($size ? ' size="' . $size . '"' : '') . ' onchange="' . htmlspecialchars(($onChangeIcon . $sOnChange)) . '"' . $PA['onFocus'] . $disabled . '>';
2006 $item .= implode('', $opt);
2007 $item .= '</select>';
2008 // Create icon table:
2009 if (count($selicons) && !$config['noIconsBelowSelect']) {
2010 $item .= '<table border="0" cellpadding="0" cellspacing="0" class="typo3-TCEforms-selectIcons">';
2011 $selicon_cols = (int)$config['selicon_cols'];
2012 if (!$selicon_cols) {
2013 $selicon_cols = count($selicons);
2014 }
2015 $sR = ceil(count($selicons) / $selicon_cols);
2016 $selicons = array_pad($selicons, $sR * $selicon_cols, '');
2017 for ($sa = 0; $sa < $sR; $sa++) {
2018 $item .= '<tr>';
2019 for ($sb = 0; $sb < $selicon_cols; $sb++) {
2020 $sk = $sa * $selicon_cols + $sb;
2021 $imgN = 'selIcon_' . $table . '_' . $row['uid'] . '_' . $field . '_' . $selicons[$sk][1];
2022 $imgS = $selicons[$sk][2] ? $this->backPath . 'gfx/content_selected.gif' : 'clear.gif';
2023 $item .= '<td><img name="' . htmlspecialchars($imgN) . '" src="' . $imgS . '" width="7" height="10" alt="" /></td>';
2024 $item .= '<td>' . $selicons[$sk][0] . '</td>';
2025 }
2026 $item .= '</tr>';
2027 }
2028 $item .= '</table>';
2029 }
2030 return $item;
2031 }
2032
2033 /**
2034 * Creates a checkbox list (renderMode = "checkbox")
2035 * (Render function for getSingleField_typeSelect())
2036 *
2037 * @param string $table See getSingleField_typeSelect()
2038 * @param string $field See getSingleField_typeSelect()
2039 * @param array $row See getSingleField_typeSelect()
2040 * @param array $PA See getSingleField_typeSelect()
2041 * @param array $config (Redundant) content of $PA['fieldConf']['config'] (for convenience)
2042 * @param array $selItems Items available for selection
2043 * @param string $nMV_label Label for no-matching-value
2044 * @return string The HTML code for the item
2045 * @see getSingleField_typeSelect()
2046 * @todo Define visibility
2047 */
2048 public function getSingleField_typeSelect_checkbox($table, $field, $row, &$PA, $config, $selItems, $nMV_label) {
2049 if (empty($selItems)) {
2050 return '';
2051 }
2052 // Get values in an array (and make unique, which is fine because there can be no duplicates anyway):
2053 $itemArray = array_flip($this->extractValuesOnlyFromValueLabelList($PA['itemFormElValue']));
2054 $item = '';
2055 $disabled = '';
2056 if ($this->renderReadonly || $config['readOnly']) {
2057 $disabled = ' disabled="disabled"';
2058 }
2059 // Traverse the Array of selector box items:
2060 $tRows = array();
2061 $c = 0;
2062 if (!$disabled) {
2063 $sOnChange = implode('', $PA['fieldChangeFunc']);
2064 // Used to accumulate the JS needed to restore the original selection.
2065 $setAll = array();
2066 $unSetAll = array();
2067 foreach ($selItems as $p) {
2068 // Non-selectable element:
2069 if ($p[1] === '--div--') {
2070 $selIcon = '';
2071 if (isset($p[2]) && $p[2] != 'empty-emtpy') {
2072 $selIcon = $this->getIconHtml($p[2]);
2073 }
2074 $tRows[] = '
2075 <tr class="c-header">
2076 <td colspan="3">' . $selIcon . htmlspecialchars($p[0]) . '</td>
2077 </tr>';
2078 } else {
2079 // Selected or not by default:
2080 $sM = '';
2081 if (isset($itemArray[$p[1]])) {
2082 $sM = ' checked="checked"';
2083 unset($itemArray[$p[1]]);
2084 }
2085 // Icon:
2086 if ($p[2]) {
2087 $selIcon = $p[2];
2088 } else {
2089 $selIcon = IconUtility::getSpriteIcon('empty-empty');
2090 }
2091 // Compile row:
2092 $rowId = uniqid('select_checkbox_row_');
2093 $onClickCell = $this->elName(($PA['itemFormElName'] . '[' . $c . ']')) . '.checked=!' . $this->elName(($PA['itemFormElName'] . '[' . $c . ']')) . '.checked;';
2094 $onClick = 'this.attributes.getNamedItem("class").nodeValue = ' . $this->elName(($PA['itemFormElName'] . '[' . $c . ']')) . '.checked ? "c-selectedItem" : "c-unselectedItem";';
2095 $setAll[] = $this->elName(($PA['itemFormElName'] . '[' . $c . ']')) . '.checked=1;';
2096 $setAll[] .= '$(\'' . $rowId . '\').removeClassName(\'c-unselectedItem\');$(\'' . $rowId . '\').addClassName(\'c-selectedItem\');';
2097 $unSetAll[] = $this->elName(($PA['itemFormElName'] . '[' . $c . ']')) . '.checked=0;';
2098 $unSetAll[] .= '$(\'' . $rowId . '\').removeClassName(\'c-selectedItem\');$(\'' . $rowId . '\').addClassName(\'c-unselectedItem\');';
2099 $restoreCmd[] = $this->elName(($PA['itemFormElName'] . '[' . $c . ']')) . '.checked=' . ($sM ? 1 : 0) . ';' . '$(\'' . $rowId . '\').removeClassName(\'c-selectedItem\');$(\'' . $rowId . '\').removeClassName(\'c-unselectedItem\');' . '$(\'' . $rowId . '\').addClassName(\'c-' . ($sM ? '' : 'un') . 'selectedItem\');';
2100 // Check if some help text is available
2101 // Since TYPO3 4.5 help text is expected to be an associative array
2102 // with two key, "title" and "description"
2103 // For the sake of backwards compatibility, we test if the help text
2104 // is a string and use it as a description (this could happen if items
2105 // are modified with an itemProcFunc)
2106 $hasHelp = FALSE;
2107 $help = '';
2108 $helpArray = array();
2109 if (is_array($p[3]) && count($p[3]) > 0 || !empty($p[3])) {
2110 $hasHelp = TRUE;
2111 if (is_array($p[3])) {
2112 $helpArray = $p[3];
2113 } else {
2114 $helpArray['description'] = $p[3];
2115 }
2116 }
2117 $label = GeneralUtility::deHSCentities(htmlspecialchars($p[0]));
2118 if ($hasHelp) {
2119 $help = BackendUtility::wrapInHelp('', '', '', $helpArray);
2120 }
2121 $tRows[] = '
2122 <tr id="' . $rowId . '" class="' . ($sM ? 'c-selectedItem' : 'c-unselectedItem') . '" onclick="' . htmlspecialchars($onClick) . '" style="cursor: pointer;">
2123 <td class="c-checkbox"><input type="checkbox"' . $this->insertDefStyle('check') . ' name="' . htmlspecialchars(($PA['itemFormElName'] . '[' . $c . ']')) . '" value="' . htmlspecialchars($p[1]) . '"' . $sM . ' onclick="' . htmlspecialchars($sOnChange) . '"' . $PA['onFocus'] . ' /></td>
2124 <td class="c-labelCell" onclick="' . htmlspecialchars($onClickCell) . '">' . $this->getIconHtml($selIcon) . $label . '</td>
2125 <td class="c-descr" onclick="' . htmlspecialchars($onClickCell) . '">' . (empty($help) ? '' : $help) . '</td>
2126 </tr>';
2127 $c++;
2128 }
2129 }
2130 }
2131 // Remaining values (invalid):
2132 if (count($itemArray) && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
2133 foreach ($itemArray as $theNoMatchValue => $temp) {
2134 // Compile <checkboxes> tag:
2135 array_unshift($tRows, '
2136 <tr class="c-invalidItem">
2137 <td class="c-checkbox"><input type="checkbox"' . $this->insertDefStyle('check') . ' name="' . htmlspecialchars(($PA['itemFormElName'] . '[' . $c . ']')) . '" value="' . htmlspecialchars($theNoMatchValue) . '" checked="checked" onclick="' . htmlspecialchars($sOnChange) . '"' . $PA['onFocus'] . $disabled . ' /></td>
2138 <td class="c-labelCell">' . GeneralUtility::deHSCentities(htmlspecialchars(@sprintf($nMV_label, $theNoMatchValue))) . '</td><td>&nbsp;</td>
2139 </tr>');
2140 $c++;
2141 }
2142 }
2143 // Add an empty hidden field which will send a blank value if all items are unselected.
2144 $item .= '<input type="hidden" class="select-checkbox" name="' . htmlspecialchars($PA['itemFormElName']) . '" value="" />';
2145 // Remaining checkboxes will get their set-all link:
2146 if (count($setAll)) {
2147 $tableHead = '<thead>
2148 <tr class="c-header-checkbox-controls t3-row-header">
2149 <td class="c-checkbox">
2150 <input type="checkbox" class="checkbox" onclick="if (checked) {' . htmlspecialchars((implode('', $setAll) . '} else {' . implode('', $unSetAll) . '}')) . '">
2151 </td>
2152 <td colspan="2">
2153 </td>
2154 </tr></thead>';
2155 }
2156 // Implode rows in table:
2157 $item .= '
2158 <table border="0" cellpadding="0" cellspacing="0" class="typo3-TCEforms-select-checkbox">' . $tableHead . '<tbody>' . implode('', $tRows) . '</tbody>
2159 </table>
2160 ';
2161 // Add revert icon
2162 if (is_array($restoreCmd)) {
2163 $item .= '<a href="#" onclick="' . implode('', $restoreCmd) . ' return false;' . '">' . IconUtility::getSpriteIcon('actions-edit-undo', array('title' => htmlspecialchars($this->getLL('l_revertSelection')))) . '</a>';
2164 }
2165 return $item;
2166 }
2167
2168 /**
2169 * Creates a selectorbox list (renderMode = "singlebox")
2170 * (Render function for getSingleField_typeSelect())
2171 *
2172 * @param string $table See getSingleField_typeSelect()
2173 * @param string $field See getSingleField_typeSelect()
2174 * @param array $row See getSingleField_typeSelect()
2175 * @param array $PA See getSingleField_typeSelect()
2176 * @param array $config (Redundant) content of $PA['fieldConf']['config'] (for convenience)
2177 * @param array $selItems Items available for selection
2178 * @param string $nMV_label Label for no-matching-value
2179 * @return string The HTML code for the item
2180 * @see getSingleField_typeSelect()
2181 * @todo Define visibility
2182 */
2183 public function getSingleField_typeSelect_singlebox($table, $field, $row, &$PA, $config, $selItems, $nMV_label) {
2184 // Get values in an array (and make unique, which is fine because there can be no duplicates anyway):
2185 $itemArray = array_flip($this->extractValuesOnlyFromValueLabelList($PA['itemFormElValue']));
2186 $item = '';
2187 $disabled = '';
2188 if ($this->renderReadonly || $config['readOnly']) {
2189 $disabled = ' disabled="disabled"';
2190 }
2191 // Traverse the Array of selector box items:
2192 $opt = array();
2193 // Used to accumulate the JS needed to restore the original selection.
2194 $restoreCmd = array();
2195 $c = 0;
2196 foreach ($selItems as $p) {
2197 // Selected or not by default:
2198 $sM = '';
2199 if (isset($itemArray[$p[1]])) {
2200 $sM = ' selected="selected"';
2201 $restoreCmd[] = $this->elName(($PA['itemFormElName'] . '[]')) . '.options[' . $c . '].selected=1;';
2202 unset($itemArray[$p[1]]);
2203 }
2204 // Non-selectable element:
2205 $nonSel = '';
2206 if ((string) $p[1] === '--div--') {
2207 $nonSel = ' onclick="this.selected=0;" class="c-divider"';
2208 }
2209 // Icon style for option tag:
2210 if ($config['iconsInOptionTags']) {
2211 $styleAttrValue = $this->optionTagStyle($p[2]);
2212 }
2213 // Compile <option> tag:
2214 $opt[] = '<option value="' . htmlspecialchars($p[1]) . '"' . $sM . $nonSel . ($styleAttrValue ? ' style="' . htmlspecialchars($styleAttrValue) . '"' : '') . '>' . GeneralUtility::deHSCentities(htmlspecialchars($p[0])) . '</option>';
2215 $c++;
2216 }
2217 // Remaining values:
2218 if (count($itemArray) && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
2219 foreach ($itemArray as $theNoMatchValue => $temp) {
2220 // Compile <option> tag:
2221 array_unshift($opt, '<option value="' . htmlspecialchars($theNoMatchValue) . '" selected="selected">' . GeneralUtility::deHSCentities(htmlspecialchars(@sprintf($nMV_label, $theNoMatchValue))) . '</option>');
2222 }
2223 }
2224 // Compile selector box:
2225 $sOnChange = implode('', $PA['fieldChangeFunc']);
2226 $selector_itemListStyle = isset($config['itemListStyle']) ? ' style="' . htmlspecialchars($config['itemListStyle']) . '"' : ' style="' . $this->defaultMultipleSelectorStyle . '"';
2227 $size = (int)$config['size'];
2228 $cssPrefix = $size === 1 ? 'tceforms-select' : 'tceforms-multiselect';
2229 $size = $config['autoSizeMax'] ? MathUtility::forceIntegerInRange(count($selItems) + 1, MathUtility::forceIntegerInRange($size, 1), $config['autoSizeMax']) : $size;
2230 $selectBox = '<select id="' . uniqid($cssPrefix) . '" name="' . $PA['itemFormElName'] . '[]"' . $this->insertDefStyle('select', $cssPrefix) . ($size ? ' size="' . $size . '"' : '') . ' multiple="multiple" onchange="' . htmlspecialchars($sOnChange) . '"' . $PA['onFocus'] . $selector_itemListStyle . $disabled . '>
2231 ' . implode('
2232 ', $opt) . '
2233 </select>';
2234 // Add an empty hidden field which will send a blank value if all items are unselected.
2235 if (!$disabled) {
2236 $item .= '<input type="hidden" name="' . htmlspecialchars($PA['itemFormElName']) . '" value="" />';
2237 }
2238 // Put it all into a table:
2239 $item .= '
2240 <table border="0" cellspacing="0" cellpadding="0" width="1" class="typo3-TCEforms-select-singlebox">
2241 <tr>
2242 <td>
2243 ' . $selectBox . '
2244 <br/>
2245 <em>' . htmlspecialchars($this->getLL('l_holdDownCTRL')) . '</em>
2246 </td>
2247 <td valign="top">
2248 <a href="#" onclick="' . htmlspecialchars(($this->elName(($PA['itemFormElName'] . '[]')) . '.selectedIndex=-1;' . implode('', $restoreCmd) . ' return false;')) . '" title="' . htmlspecialchars($this->getLL('l_revertSelection')) . '">' . IconUtility::getSpriteIcon('actions-edit-undo') . '</a>
2249 </td>
2250 </tr>
2251 </table>
2252 ';
2253 return $item;
2254 }
2255
2256 /**
2257 * Creates a multiple-selector box (two boxes, side-by-side)
2258 * (Render function for getSingleField_typeSelect())
2259 *
2260 * @param string $table See getSingleField_typeSelect()
2261 * @param string $field See getSingleField_typeSelect()
2262 * @param array $row See getSingleField_typeSelect()
2263 * @param array $PA See getSingleField_typeSelect()
2264 * @param array $config (Redundant) content of $PA['fieldConf']['config'] (for convenience)
2265 * @param array $selItems Items available for selection
2266 * @param string $nMV_label Label for no-matching-value
2267 * @return string The HTML code for the item
2268 * @see getSingleField_typeSelect()
2269 * @todo Define visibility
2270 */
2271 public function getSingleField_typeSelect_multiple($table, $field, $row, &$PA, $config, $selItems, $nMV_label) {
2272 $item = '';
2273 $disabled = '';
2274 if ($this->renderReadonly || $config['readOnly']) {
2275 $disabled = ' disabled="disabled"';
2276 }
2277 // Setting this hidden field (as a flag that JavaScript can read out)
2278 if (!$disabled) {
2279 $item .= '<input type="hidden" name="' . $PA['itemFormElName'] . '_mul" value="' . ($config['multiple'] ? 1 : 0) . '" />';
2280 }
2281 // Set max and min items:
2282 $maxitems = MathUtility::forceIntegerInRange($config['maxitems'], 0);
2283 if (!$maxitems) {
2284 $maxitems = 100000;
2285 }
2286 $minitems = MathUtility::forceIntegerInRange($config['minitems'], 0);
2287 // Register the required number of elements:
2288 $this->registerRequiredProperty('range', $PA['itemFormElName'], array($minitems, $maxitems, 'imgName' => $table . '_' . $row['uid'] . '_' . $field));
2289 // Get "removeItems":
2290 $removeItems = GeneralUtility::trimExplode(',', $PA['fieldTSConfig']['removeItems'], TRUE);
2291 // Get the array with selected items:
2292 $itemArray = GeneralUtility::trimExplode(',', $PA['itemFormElValue'], TRUE);
2293
2294 // Possibly filter some items:
2295 $itemArray = GeneralUtility::keepItemsInArray(
2296 $itemArray,
2297 $PA['fieldTSConfig']['keepItems'],
2298 function ($value) {
2299 $parts = explode('|', $value, 2);
2300 return rawurldecode($parts[0]);
2301 }
2302 );
2303
2304 // Perform modification of the selected items array:
2305 foreach ($itemArray as $tk => $tv) {
2306 $tvP = explode('|', $tv, 2);
2307 $evalValue = $tvP[0];
2308 $isRemoved = in_array($evalValue, $removeItems) || $config['form_type'] == 'select' && $config['authMode'] && !$GLOBALS['BE_USER']->checkAuthMode($table, $field, $evalValue, $config['authMode']);
2309 if ($isRemoved && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
2310 $tvP[1] = rawurlencode(@sprintf($nMV_label, $evalValue));
2311 } elseif (isset($PA['fieldTSConfig']['altLabels.'][$evalValue])) {
2312 $tvP[1] = rawurlencode($this->sL($PA['fieldTSConfig']['altLabels.'][$evalValue]));
2313 }
2314 if ($tvP[1] == '') {
2315 // Case: flexform, default values supplied, no label provided (bug #9795)
2316 foreach ($selItems as $selItem) {
2317 if ($selItem[1] == $tvP[0]) {
2318 $tvP[1] = html_entity_decode($selItem[0]);
2319 break;
2320 }
2321 }
2322 }
2323 $itemArray[$tk] = implode('|', $tvP);
2324 }
2325 $itemsToSelect = '';
2326 $filterTextfield = '';
2327 $filterSelectbox = '';
2328 if (!$disabled) {
2329 // Create option tags:
2330 $opt = array();
2331 $styleAttrValue = '';
2332 foreach ($selItems as $p) {
2333 if ($config['iconsInOptionTags']) {
2334 $styleAttrValue = $this->optionTagStyle($p[2]);
2335 }
2336 $opt[] = '<option value="' . htmlspecialchars($p[1]) . '"' . ($styleAttrValue ? ' style="' . htmlspecialchars($styleAttrValue) . '"' : '') . ' title="' . $p[0] . '">' . $p[0] . '</option>';
2337 }
2338 // Put together the selector box:
2339 $selector_itemListStyle = isset($config['itemListStyle']) ? ' style="' . htmlspecialchars($config['itemListStyle']) . '"' : ' style="' . $this->defaultMultipleSelectorStyle . '"';
2340 $size = (int)$config['size'];
2341 $size = $config['autoSizeMax'] ? MathUtility::forceIntegerInRange(count($itemArray) + 1, MathUtility::forceIntegerInRange($size, 1), $config['autoSizeMax']) : $size;
2342 if ($config['exclusiveKeys']) {
2343 $sOnChange = 'setFormValueFromBrowseWin(\'' . $PA['itemFormElName'] . '\',this.options[this.selectedIndex].value, this.options[this.selectedIndex].text, this.options[this.selectedIndex].title,\'' . $config['exclusiveKeys'] . '\'); ';
2344 } else {
2345 $sOnChange = 'setFormValueFromBrowseWin(\'' . $PA['itemFormElName'] . '\',this.options[this.selectedIndex].value, this.options[this.selectedIndex].text, this.options[this.selectedIndex].title); ';
2346 }
2347 $sOnChange .= implode('', $PA['fieldChangeFunc']);
2348 $multiSelectId = uniqid('tceforms-multiselect-');
2349 $itemsToSelect = '
2350 <select id="' . $multiSelectId . '" name="' . $PA['itemFormElName'] . '_sel"' . $this->insertDefStyle('select', 'tceforms-multiselect tceforms-itemstoselect') . ($size ? ' size="' . $size . '"' : '') . ' onchange="' . htmlspecialchars($sOnChange) . '"' . $PA['onFocus'] . $selector_itemListStyle . '>
2351 ' . implode('
2352 ', $opt) . '
2353 </select>';
2354
2355 if ($config['enableMultiSelectFilterTextfield'] || $config['multiSelectFilterItems']) {
2356 $this->multiSelectFilterCount++;
2357 $jsSelectBoxFilterName = str_replace(' ', '', ucwords(str_replace('-', ' ', GeneralUtility::strtolower($multiSelectId))));
2358 $this->additionalJS_post[] = '
2359 var '. $jsSelectBoxFilterName . ' = new TCEForms.SelectBoxFilter("' . $multiSelectId . '");
2360 ';
2361 }
2362
2363 if ($config['enableMultiSelectFilterTextfield']) {
2364 // add input field for filter
2365 $filterTextfield = '<input class="typo3-TCEforms-suggest-search typo3-TCEforms-multiselect-filter" id="' . $multiSelectId . '_filtertextfield" value="" style="width: 104px;" />';
2366 }
2367
2368 if (isset($config['multiSelectFilterItems']) && is_array($config['multiSelectFilterItems']) && count($config['multiSelectFilterItems']) > 1) {
2369 $filterDropDownOptions = array();
2370 foreach ($config['multiSelectFilterItems'] as $optionElement) {
2371 $filterDropDownOptions[] = '<option value="' . htmlspecialchars($this->sL($optionElement[0])) . '">' . htmlspecialchars((isset($optionElement[1]) && $optionElement[1] != '') ? $this->sL($optionElement[1]) : $this->sL($optionElement[0])) . '</option>';
2372 }
2373 $filterSelectbox = '
2374 <select id="' . $multiSelectId . '_filterdropdown">
2375 ' . implode('
2376 ', $filterDropDownOptions) . '
2377 </select>';
2378 }
2379 }
2380 // Pass to "dbFileIcons" function:
2381 $params = array(
2382 'size' => $size,
2383 'autoSizeMax' => MathUtility::forceIntegerInRange($config['autoSizeMax'], 0),
2384 'style' => isset($config['selectedListStyle']) ? ' style="' . htmlspecialchars($config['selectedListStyle']) . '"' : ' style="' . $this->defaultMultipleSelectorStyle . '"',
2385 'dontShowMoveIcons' => $maxitems <= 1,
2386 'maxitems' => $maxitems,
2387 'info' => '',
2388 'headers' => array(
2389 'selector' => $this->getLL('l_selected') . ':<br />',
2390 'items' => $this->getLL('l_items') . ': ' . $filterSelectbox . $filterTextfield . '<br />'
2391 ),
2392 'noBrowser' => 1,
2393 'thumbnails' => $itemsToSelect,
2394 'readOnly' => $disabled
2395 );
2396 $item .= $this->dbFileIcons($PA['itemFormElName'], '', '', $itemArray, '', $params, $PA['onFocus']);
2397 return $item;
2398 }
2399
2400 /**
2401 * Generation of TCEform elements of the type "group"
2402 * This will render a selectorbox into which elements from either the file system or database can be inserted. Relations.
2403 *
2404 * @param string $table The table name of the record
2405 * @param string $field The field name which this element is supposed to edit
2406 * @param array $row The record data array where the value(s) for the field can be found
2407 * @param array $PA An array with additional configuration options.
2408 * @return string The HTML code for the TCEform field
2409 * @todo Define visibility
2410 */
2411 public function getSingleField_typeGroup($table, $field, $row, &$PA) {
2412 // Init:
2413 $config = $PA['fieldConf']['config'];
2414 $internal_type = $config['internal_type'];
2415 $show_thumbs = $config['show_thumbs'];
2416 $size = (int)$config['size'];
2417 $maxitems = MathUtility::forceIntegerInRange($config['maxitems'], 0);
2418 if (!$maxitems) {
2419 $maxitems = 100000;
2420 }
2421 $minitems = MathUtility::forceIntegerInRange($config['minitems'], 0);
2422 $allowed = trim($config['allowed']);
2423 $disallowed = trim($config['disallowed']);
2424 $item = '';
2425 $disabled = '';
2426 if ($this->renderReadonly || $config['readOnly']) {
2427 $disabled = ' disabled="disabled"';
2428 }
2429 $item .= '<input type="hidden" name="' . $PA['itemFormElName'] . '_mul" value="' . ($config['multiple'] ? 1 : 0) . '"' . $disabled . ' />';
2430 $this->registerRequiredProperty('range', $PA['itemFormElName'], array($minitems, $maxitems, 'imgName' => $table . '_' . $row['uid'] . '_' . $field));
2431 $info = '';
2432 // "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist. See http://typo3.org/documentation/document-library/doc_core_api/Wizards_Configuratio/.
2433 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
2434 $PA['itemFormElID_file'] = $PA['itemFormElID'] . '_files';
2435 // whether the list and delete controls should be disabled
2436 $noList = isset($config['disable_controls']) && GeneralUtility::inList($config['disable_controls'], 'list');
2437 $noDelete = isset($config['disable_controls']) && GeneralUtility::inList($config['disable_controls'], 'delete');
2438 // if maxitems==1 then automatically replace the current item (in list and file selector)
2439 if ($maxitems === 1) {
2440 $this->additionalJS_post[] = 'TBE_EDITOR.clearBeforeSettingFormValueFromBrowseWin[\'' . $PA['itemFormElName'] . '\'] = {
2441 itemFormElID_file: \'' . $PA['itemFormElID_file'] . '\'
2442 }';
2443 $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = 'setFormValueManipulate(\'' . $PA['itemFormElName'] . '\', \'Remove\'); ' . $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'];
2444 } elseif ($noList) {
2445 // If the list controls have been removed and the maximum number is reached, remove the first entry to avoid "write once" field
2446 $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = 'setFormValueManipulate(\'' . $PA['itemFormElName'] . '\', \'RemoveFirstIfFull\', \'' . $maxitems . '\'); ' . $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'];
2447 }
2448 // Acting according to either "file" or "db" type:
2449 switch ((string) $config['internal_type']) {
2450 case 'file_reference':
2451 $config['uploadfolder'] = '';
2452 // Fall through
2453 case 'file':
2454 // Creating string showing allowed types:
2455 $tempFT = GeneralUtility::trimExplode(',', $allowed, TRUE);
2456 if (!count($tempFT)) {
2457 $info .= '*';
2458 }
2459 foreach ($tempFT as $ext) {
2460 if ($ext) {
2461 $info .= strtoupper($ext) . ' ';
2462 }
2463 }
2464 // Creating string, showing disallowed types:
2465 $tempFT_dis = GeneralUtility::trimExplode(',', $disallowed, TRUE);
2466 if (count($tempFT_dis)) {
2467 $info .= '<br />';
2468 }
2469 foreach ($tempFT_dis as $ext) {
2470 if ($ext) {
2471 $info .= '-' . strtoupper($ext) . ' ';
2472 }
2473 }
2474 // Making the array of file items:
2475 $itemArray = GeneralUtility::trimExplode(',', $PA['itemFormElValue'], TRUE);
2476 $fileFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
2477 // Correct the filename for the FAL items
2478 foreach ($itemArray as &$fileItem) {
2479 list($fileUid, $fileLabel) = explode('|', $fileItem);
2480 if (MathUtility::canBeInterpretedAsInteger($fileUid)) {
2481 $fileObject = $fileFactory->getFileObject($fileUid);
2482 $fileLabel = $fileObject->getName();
2483 }
2484 $fileItem = $fileUid . '|' . $fileLabel;
2485 }
2486 // Showing thumbnails:
2487 $thumbsnail = '';
2488 if ($show_thumbs) {
2489 $imgs = array();
2490 foreach ($itemArray as $imgRead) {
2491 $imgP = explode('|', $imgRead);
2492 $imgPath = rawurldecode($imgP[0]);
2493 // FAL icon production
2494 if (MathUtility::canBeInterpretedAsInteger($imgP[0])) {
2495 $fileObject = $fileFactory->getFileObject($imgP[0]);
2496
2497 if ($fileObject->isMissing()) {
2498 $flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($fileObject);
2499 $imgs[] = $flashMessage->render();
2500 } elseif (GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileObject->getExtension())) {
2501 $imageUrl = $fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array())->getPublicUrl(TRUE);
2502 $imgTag = '<img src="' . $imageUrl . '" alt="' . htmlspecialchars($fileObject->getName()) . '" />';
2503 $imgs[] = '<span class="nobr">' . $imgTag . htmlspecialchars($fileObject->getName()) . '</span>';
2504 } else {
2505 // Icon
2506 $imgTag = IconUtility::getSpriteIconForFile(strtolower($fileObject->getExtension()), array('title' => $fileObject->getName()));
2507 $imgs[] = '<span class="nobr">' . $imgTag . htmlspecialchars($fileObject->getName()) . '</span>';
2508 }
2509 } else {
2510 $rowCopy = array();
2511 $rowCopy[$field] = $imgPath;
2512 $thumbnailCode = '';
2513 try {
2514 $thumbnailCode = BackendUtility::thumbCode(
2515 $rowCopy, $table, $field, $this->backPath, 'thumbs.php',
2516 $config['uploadfolder'], 0, ' align="middle"'
2517 );
2518 $thumbnailCode = '<span class="nobr">' . $thumbnailCode . $imgPath . '</span>';
2519
2520 } catch (\Exception $exception) {
2521 /** @var $flashMessage FlashMessage */
2522 $message = $exception->getMessage();
2523 $flashMessage = GeneralUtility::makeInstance(
2524 'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
2525 htmlspecialchars($message), '', FlashMessage::ERROR, TRUE
2526 );
2527 $class = 'TYPO3\\CMS\\Core\\Messaging\\FlashMessageService';
2528 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
2529 $flashMessageService = GeneralUtility::makeInstance($class);
2530 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
2531 $defaultFlashMessageQueue->enqueue($flashMessage);
2532
2533 $logMessage = $message . ' (' . $table . ':' . $row['uid'] . ')';
2534 GeneralUtility::sysLog($logMessage, 'core', GeneralUtility::SYSLOG_SEVERITY_WARNING);
2535 }
2536
2537 $imgs[] = $thumbnailCode;
2538 }
2539 }
2540 $thumbsnail = implode('<br />', $imgs);
2541 }
2542 // Creating the element:
2543 $params = array(
2544 'size' => $size,
2545 'dontShowMoveIcons' => $maxitems <= 1,
2546 'autoSizeMax' => MathUtility::forceIntegerInRange($config['autoSizeMax'], 0),
2547 'maxitems' => $maxitems,
2548 'style' => isset($config['selectedListStyle']) ? ' style="' . htmlspecialchars($config['selectedListStyle']) . '"' : ' style="' . $this->defaultMultipleSelectorStyle . '"',
2549 'info' => $info,
2550 'thumbnails' => $thumbsnail,
2551 'readOnly' => $disabled,
2552 'noBrowser' => $noList || isset($config['disable_controls']) && GeneralUtility::inList($config['disable_controls'], 'browser'),
2553 'noList' => $noList,
2554 'noDelete' => $noDelete
2555 );
2556 $item .= $this->dbFileIcons($PA['itemFormElName'], 'file', implode(',', $tempFT), $itemArray, '', $params, $PA['onFocus'], '', '', '', $config);
2557 if (!$disabled && !(isset($config['disable_controls']) && GeneralUtility::inList($config['disable_controls'], 'upload'))) {
2558 // Adding the upload field:
2559 if ($this->edit_docModuleUpload && $config['uploadfolder']) {
2560 // Insert the multiple attribute to enable HTML5 multiple file upload
2561 $multipleAttribute = '';
2562 $multipleFilenameSuffix = '';
2563 if (isset($config['maxitems']) && $config['maxitems'] > 1) {
2564 $multipleAttribute = ' multiple="multiple"';
2565 $multipleFilenameSuffix = '[]';
2566 }
2567 $item .= '<div id="' . $PA['itemFormElID_file'] . '"><input type="file"' . $multipleAttribute . ' name="' . $PA['itemFormElName_file'] . $multipleFilenameSuffix . '" size="35" onchange="' . implode('', $PA['fieldChangeFunc']) . '" /></div>';
2568 }
2569 }
2570 break;
2571 case 'folder':
2572 // If the element is of the internal type "folder":
2573 // Array of folder items:
2574 $itemArray = GeneralUtility::trimExplode(',', $PA['itemFormElValue'], TRUE);
2575 // Creating the element:
2576 $params = array(
2577 'size' => $size,
2578 'dontShowMoveIcons' => $maxitems <= 1,
2579