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