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