[BUGFIX] Fix PHP warning with date function in FormEngine
[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|NULL HTML output
822 * @see getMainFields()
823 * @todo Define visibility
824 */
825 public function getSoloField($table, $row, $theFieldToReturn) {
826 if (!isset($GLOBALS['TCA'][$table])) {
827 return NULL;
828 }
829 $typeNum = $this->getRTypeNum($table, $row);
830 if (isset($GLOBALS['TCA'][$table]['types'][$typeNum])) {
831 $itemList = $GLOBALS['TCA'][$table]['types'][$typeNum]['showitem'];
832 if ($itemList) {
833 $fields = GeneralUtility::trimExplode(',', $itemList, TRUE);
834 $excludeElements = ($this->excludeElements = $this->getExcludeElements($table, $row, $typeNum));
835 foreach ($fields as $fieldInfo) {
836 $parts = explode(';', $fieldInfo);
837 $theField = trim($parts[0]);
838 if (!in_array($theField, $excludeElements) && (string)$theField === (string)$theFieldToReturn) {
839 if ($GLOBALS['TCA'][$table]['columns'][$theField]) {
840 $sField = $this->getSingleField($table, $theField, $row, $parts[1], 1, $parts[3], $parts[2]);
841 return $sField['ITEM'];
842 }
843 }
844 }
845 }
846 }
847 return NULL;
848 }
849
850 /**
851 * Based on the $table and $row of content, this displays the complete TCEform for the record.
852 * The input-$row is required to be preprocessed if necessary by eg.
853 * the \TYPO3\CMS\Backend\Form\DataPreprocessor class. For instance the RTE content
854 * should be transformed through this class first.
855 *
856 * @param string $table The table name
857 * @param array $row The record from the table for which to render a field.
858 * @param integer $depth Depth level
859 * @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'].
860 * @return string HTML output
861 * @see getSoloField()
862 * @todo Define visibility
863 */
864 public function getMainFields($table, array $row, $depth = 0, array $overruleTypesArray = array()) {
865 $this->renderDepth = $depth;
866 // Init vars:
867 $out_array = array(array());
868 $out_array_meta = array(
869 array(
870 'title' => $this->getLL('l_generalTab')
871 )
872 );
873 $out_pointer = 0;
874 $out_sheet = 0;
875 $this->palettesRendered = array();
876 $this->palettesRendered[$this->renderDepth][$table] = array();
877 // Hook: getMainFields_preProcess (requested by Thomas Hempel for use with the "dynaflex" extension)
878 foreach ($this->hookObjectsMainFields as $hookObj) {
879 if (method_exists($hookObj, 'getMainFields_preProcess')) {
880 $hookObj->getMainFields_preProcess($table, $row, $this);
881 }
882 }
883 $tabIdentString = '';
884 $tabIdentStringMD5 = '';
885 if ($GLOBALS['TCA'][$table]) {
886 // Get dividers2tabs setting from TCA of the current table:
887 $dividers2tabs = &$GLOBALS['TCA'][$table]['ctrl']['dividers2tabs'];
888 // Load the description content for the table.
889 if ($this->edit_showFieldHelp || $this->doLoadTableDescr($table)) {
890 $this->getLanguageService()->loadSingleTableDescription($table);
891 }
892 // Get the current "type" value for the record.
893 $typeNum = $this->getRTypeNum($table, $row);
894 // Find the list of fields to display:
895 if ($GLOBALS['TCA'][$table]['types'][$typeNum]) {
896 $itemList = $GLOBALS['TCA'][$table]['types'][$typeNum]['showitem'];
897 if (is_array($overruleTypesArray) && isset($overruleTypesArray[$typeNum]['showitem'])) {
898 $itemList = $overruleTypesArray[$typeNum]['showitem'];
899 }
900 // If such a list existed...
901 if ($itemList) {
902 // Explode the field list and possibly rearrange the order of the fields, if configured for
903 $fields = GeneralUtility::trimExplode(',', $itemList, TRUE);
904 if ($this->fieldOrder) {
905 $fields = $this->rearrange($fields);
906 }
907 // Get excluded fields, added fiels and put it together:
908 $excludeElements = ($this->excludeElements = $this->getExcludeElements($table, $row, $typeNum));
909 $fields = $this->mergeFieldsWithAddedFields($fields, $this->getFieldsToAdd($table, $row, $typeNum), $table);
910 // If TCEforms will render a tab menu in the next step, push the name to the tab stack:
911 if (strstr($itemList, '--div--') !== FALSE && $this->enableTabMenu && $dividers2tabs) {
912 $tabIdentString = 'TCEforms:' . $table . ':' . $row['uid'];
913 $tabIdentStringMD5 = $this->getDocumentTemplate()->getDynTabMenuId($tabIdentString);
914 // Remember that were currently working on the general tab:
915 if (isset($fields[0]) && strpos($fields[0], '--div--') !== 0) {
916 $this->pushToDynNestedStack('tab', $tabIdentStringMD5 . '-1');
917 }
918 }
919 // Traverse the fields to render:
920 $cc = 0;
921 foreach ($fields as $fieldInfo) {
922 // Exploding subparts of the field configuration:
923 $parts = explode(';', $fieldInfo);
924 // Getting the style information out:
925 $color_style_parts = GeneralUtility::trimExplode('-', $parts[4]);
926 if ($color_style_parts[0] !== '') {
927 $this->setColorScheme($GLOBALS['TBE_STYLES']['colorschemes'][(int)$color_style_parts[0]]);
928 }
929 if ($color_style_parts[1] !== '') {
930 $this->fieldStyle = $GLOBALS['TBE_STYLES']['styleschemes'][(int)$color_style_parts[1]];
931 if (!isset($this->fieldStyle)) {
932 $this->fieldStyle = $GLOBALS['TBE_STYLES']['styleschemes'][0];
933 }
934 }
935 if ($color_style_parts[2] !== '') {
936 $this->wrapBorder($out_array[$out_sheet], $out_pointer);
937 $this->borderStyle = $GLOBALS['TBE_STYLES']['borderschemes'][(int)$color_style_parts[2]];
938 if (!isset($this->borderStyle)) {
939 $this->borderStyle = $GLOBALS['TBE_STYLES']['borderschemes'][0];
940 }
941 }
942 // Render the field:
943 $theField = $parts[0];
944 if (!in_array($theField, $excludeElements)) {
945 if ($GLOBALS['TCA'][$table]['columns'][$theField]) {
946 $sFieldPal = '';
947 if ($parts[2] && !isset($this->palettesRendered[$this->renderDepth][$table][$parts[2]])) {
948 $sFieldPal = $this->getPaletteFields($table, $row, $parts[2]);
949 $this->palettesRendered[$this->renderDepth][$table][$parts[2]] = 1;
950 }
951 $sField = $this->getSingleField($table, $theField, $row, $parts[1], 0, $parts[3], $parts[2]);
952 if ($sField) {
953 $sField .= $sFieldPal;
954 }
955 $out_array[$out_sheet][$out_pointer] .= $sField;
956 } elseif ($theField == '--div--') {
957 if ($cc > 0) {
958 $out_array[$out_sheet][$out_pointer] .= $this->getDivider();
959 if ($this->enableTabMenu && $dividers2tabs) {
960 $this->wrapBorder($out_array[$out_sheet], $out_pointer);
961 // Remove last tab entry from the dynNestedStack:
962 $out_sheet++;
963 // Remove the previous sheet from stack (if any):
964 $this->popFromDynNestedStack('tab', $tabIdentStringMD5 . '-' . $out_sheet);
965 // Remember on which sheet we're currently working:
966 $this->pushToDynNestedStack('tab', $tabIdentStringMD5 . '-' . ($out_sheet + 1));
967 $out_array[$out_sheet] = array();
968 $out_array_meta[$out_sheet]['title'] = $this->sL($parts[1]);
969 // Register newline for Tab
970 $out_array_meta[$out_sheet]['newline'] = $parts[2] == 'newline';
971 }
972 } else {
973 // Setting alternative title for "General" tab if "--div--" is the very first element.
974 $out_array_meta[$out_sheet]['title'] = $this->sL($parts[1]);
975 // Only add the first tab to the dynNestedStack if there are more tabs:
976 if ($tabIdentString && strpos($itemList, '--div--', strlen($fieldInfo))) {
977 $this->pushToDynNestedStack('tab', $tabIdentStringMD5 . '-1');
978 }
979 }
980 } elseif ($theField == '--palette--') {
981 if ($parts[2] && !isset($this->palettesRendered[$this->renderDepth][$table][$parts[2]])) {
982 // Render a 'header' if not collapsed
983 if ($GLOBALS['TCA'][$table]['palettes'][$parts[2]]['canNotCollapse'] && $parts[1]) {
984 $out_array[$out_sheet][$out_pointer] .= $this->getPaletteFields($table, $row, $parts[2], $this->sL($parts[1]));
985 } else {
986 $out_array[$out_sheet][$out_pointer] .= $this->getPaletteFields($table, $row, $parts[2], '', '', $this->sL($parts[1]));
987 }
988 $this->palettesRendered[$this->renderDepth][$table][$parts[2]] = 1;
989 }
990 }
991 }
992 $cc++;
993 }
994 }
995 }
996 }
997 // Hook: getMainFields_postProcess (requested by Thomas Hempel for use with the "dynaflex" extension)
998 foreach ($this->hookObjectsMainFields as $hookObj) {
999 if (method_exists($hookObj, 'getMainFields_postProcess')) {
1000 $hookObj->getMainFields_postProcess($table, $row, $this);
1001 }
1002 }
1003 // Wrapping a border around it all:
1004 $this->wrapBorder($out_array[$out_sheet], $out_pointer);
1005 // Resetting styles:
1006 $this->resetSchemes();
1007 // Rendering Main palettes, if any
1008 $mParr = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['mainpalette']);
1009 $i = 0;
1010 if (count($mParr)) {
1011 foreach ($mParr as $mP) {
1012 if (!isset($this->palettesRendered[$this->renderDepth][$table][$mP])) {
1013 $temp_palettesCollapsed = $this->palettesCollapsed;
1014 $this->palettesCollapsed = FALSE;
1015 $label = $i == 0 ? $this->getLL('l_generalOptions') : $this->getLL('l_generalOptions_more');
1016 $out_array[$out_sheet][$out_pointer] .= $this->getPaletteFields($table, $row, $mP, $label);
1017 $this->palettesCollapsed = $temp_palettesCollapsed;
1018 $this->palettesRendered[$this->renderDepth][$table][$mP] = 1;
1019 }
1020 $this->wrapBorder($out_array[$out_sheet], $out_pointer);
1021 $i++;
1022 if ($this->renderDepth) {
1023 $this->renderDepth--;
1024 }
1025 }
1026 }
1027 // Return the imploded $out_array:
1028 // There were --div-- dividers around...
1029 if ($out_sheet > 0) {
1030 // Create parts array for the tab menu:
1031 $parts = array();
1032 foreach ($out_array as $idx => $sheetContent) {
1033 $content = implode('', $sheetContent);
1034 if ($content) {
1035 // Wrap content (row) with table-tag, otherwise tab/sheet will be disabled (see getdynTabMenu() )
1036 $content = '<table border="0" cellspacing="0" cellpadding="0" width="100%">' . $content . '</table>';
1037 }
1038 $parts[$idx] = array(
1039 'label' => $out_array_meta[$idx]['title'],
1040 'content' => $content,
1041 'newline' => $out_array_meta[$idx]['newline']
1042 );
1043 }
1044 if (count($parts) > 1) {
1045 // Unset the current level of tab menus:
1046 $this->popFromDynNestedStack('tab', $tabIdentStringMD5 . '-' . ($out_sheet + 1));
1047 $dividersToTabsBehaviour = isset($GLOBALS['TCA'][$table]['ctrl']['dividers2tabs']) ? $GLOBALS['TCA'][$table]['ctrl']['dividers2tabs'] : 1;
1048 $output = $this->getDynTabMenu($parts, $tabIdentString, $dividersToTabsBehaviour);
1049 } else {
1050 // If there is only one tab/part there is no need to wrap it into the dynTab code
1051 $output = isset($parts[0]) ? trim($parts[0]['content']) : '';
1052 }
1053 $output = '
1054 <tr>
1055 <td colspan="2">
1056 ' . $output . '
1057 </td>
1058 </tr>';
1059 } else {
1060 // Only one tab, so just implode and wrap the background image (= tab container) around:
1061 $output = implode('', $out_array[$out_sheet]);
1062 $output = '<div class="typo3-dyntabmenu-divs">' . $output . '</div>';
1063 }
1064
1065 return $output;
1066 }
1067
1068 /**
1069 * Will return the TCEform elements for a pre-defined list of fields.
1070 * 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.
1071 * Used for displaying forms for the frontend edit icons for instance.
1072 *
1073 * @param string $table The table name
1074 * @param array $row The record array.
1075 * @param string $list Commalist of fields from the table. These will be shown in the specified order in a form.
1076 * @return string TCEform elements in a string.
1077 * @todo Define visibility
1078 */
1079 public function getListedFields($table, $row, $list) {
1080 if ($this->edit_showFieldHelp || $this->doLoadTableDescr($table)) {
1081 $this->getLanguageService()->loadSingleTableDescription($table);
1082 }
1083 $out = '';
1084 $types_fieldConfig = BackendUtility::getTCAtypes($table, $row, 1);
1085 $editFieldList = array_unique(GeneralUtility::trimExplode(',', $list, TRUE));
1086 foreach ($editFieldList as $theFieldC) {
1087 list($theField, $palFields) = preg_split('/\\[|\\]/', $theFieldC);
1088 $theField = trim($theField);
1089 $palFields = trim($palFields);
1090 if ($GLOBALS['TCA'][$table]['columns'][$theField]) {
1091 $parts = GeneralUtility::trimExplode(';', $types_fieldConfig[$theField]['origString']);
1092 // Don't sent palette pointer - there are no options anyways for a field-list.
1093 $sField = $this->getSingleField($table, $theField, $row, $parts[1], 0, $parts[3], 0);
1094 $out .= $sField;
1095 } elseif ($theField == '--div--') {
1096 $out .= $this->getDivider();
1097 }
1098 if ($palFields) {
1099 $out .= $this->getPaletteFields($table, $row, '', '', implode(',', GeneralUtility::trimExplode('|', $palFields, TRUE)));
1100 }
1101 }
1102 return $out;
1103 }
1104
1105 /**
1106 * Creates a palette (collection of secondary options).
1107 *
1108 * @param string $table The table name
1109 * @param array $row The row array
1110 * @param string $palette The palette number/pointer
1111 * @param string $header Header string for the palette (used when in-form). If not set, no header item is made.
1112 * @param string $itemList Optional alternative list of fields for the palette
1113 * @param string $collapsedHeader Optional Link text for activating a palette (when palettes does not have another form element to belong to).
1114 * @return string HTML code.
1115 * @todo Define visibility
1116 */
1117 public function getPaletteFields($table, $row, $palette, $header = '', $itemList = '', $collapsedHeader = NULL) {
1118 if (!$this->doPrintPalette) {
1119 return '';
1120 }
1121 $out = '';
1122 $parts = $this->loadPaletteElements($table, $row, $palette, $itemList);
1123 // Put palette together if there are fields in it:
1124 if (count($parts)) {
1125 $realFields = 0;
1126 foreach ($parts as $part) {
1127 if ($part['NAME'] !== '--linebreak--') {
1128 $realFields++;
1129 }
1130 }
1131 if ($realFields > 0) {
1132 if ($header) {
1133 $out .= $this->intoTemplate(array('HEADER' => htmlspecialchars($header)), $this->palFieldTemplateHeader);
1134 }
1135 $collapsed = $this->isPalettesCollapsed($table, $palette);
1136 // Check if the palette is a hidden palette
1137 $isHiddenPalette = !empty($GLOBALS['TCA'][$table]['palettes'][$palette]['isHiddenPalette']);
1138 $thePalIcon = '';
1139 if ($collapsed && $collapsedHeader !== NULL && !$isHiddenPalette) {
1140 list($thePalIcon, ) = $this->wrapOpenPalette(IconUtility::getSpriteIcon('actions-system-options-view', array('title' => htmlspecialchars($this->getLL('l_moreOptions')))), $table, $row, $palette, 1);
1141 $thePalIcon = '<span style="margin-left: 20px;">' . $thePalIcon . $collapsedHeader . '</span>';
1142 }
1143 $paletteHtml = $this->wrapPaletteField($this->printPalette($parts), $table, $row, $palette, $collapsed);
1144 $out .= $this->intoTemplate(array('PALETTE' => $thePalIcon . $paletteHtml), $this->palFieldTemplate);
1145 }
1146 }
1147 return $out;
1148 }
1149
1150 /**
1151 * Returns the form HTML code for a database table field.
1152 *
1153 * @param string $table The table name
1154 * @param string $field The field name
1155 * @param array $row The record to edit from the database table.
1156 * @param string $altName Alternative field name label to show.
1157 * @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).
1158 * @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.
1159 * @param integer $pal The palette pointer.
1160 * @return mixed String (normal) or array (palettes)
1161 * @todo Define visibility
1162 */
1163 public function getSingleField($table, $field, $row, $altName = '', $palette = FALSE, $extra = '', $pal = 0) {
1164 // Hook: getSingleField_preProcess
1165 foreach ($this->hookObjectsSingleField as $hookObj) {
1166 if (method_exists($hookObj, 'getSingleField_preProcess')) {
1167 $hookObj->getSingleField_preProcess($table, $field, $row, $altName, $palette, $extra, $pal, $this);
1168 }
1169 }
1170 $out = '';
1171 $PA = array();
1172 $PA['altName'] = $altName;
1173 $PA['palette'] = $palette;
1174 $PA['extra'] = $extra;
1175 $PA['pal'] = $pal;
1176 // Get the TCA configuration for the current field:
1177 $PA['fieldConf'] = $GLOBALS['TCA'][$table]['columns'][$field];
1178 $PA['fieldConf']['config']['form_type'] = $PA['fieldConf']['config']['form_type'] ?: $PA['fieldConf']['config']['type'];
1179
1180 // Using "form_type" locally in this script
1181 $skipThisField = $this->inline->skipField($table, $field, $row, $PA['fieldConf']['config']);
1182
1183 // Evaluate display condition
1184 $displayConditionResult = TRUE;
1185 if (is_array($PA['fieldConf']) && $PA['fieldConf']['displayCond'] && is_array($row)) {
1186 /** @var $elementConditionMatcher \TYPO3\CMS\Backend\Form\ElementConditionMatcher */
1187 $elementConditionMatcher = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\ElementConditionMatcher');
1188 $displayConditionResult = $elementConditionMatcher->match($PA['fieldConf']['displayCond'], $row);
1189 }
1190 // Check if this field is configured and editable (according to excludefields + other configuration)
1191 if (
1192 is_array($PA['fieldConf'])
1193 && !$skipThisField
1194 && (!$PA['fieldConf']['exclude'] || $this->getBackendUserAuthentication()->check('non_exclude_fields', $table . ':' . $field))
1195 && $PA['fieldConf']['config']['form_type'] != 'passthrough'
1196 && ($this->RTEenabled || !$PA['fieldConf']['config']['showIfRTE'])
1197 && $displayConditionResult
1198 && (!$GLOBALS['TCA'][$table]['ctrl']['languageField'] || $PA['fieldConf']['l10n_display'] || ($PA['fieldConf']['l10n_mode'] !== 'exclude') || $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] <= 0)
1199 && (!$GLOBALS['TCA'][$table]['ctrl']['languageField'] || !$this->localizationMode || $this->localizationMode === $PA['fieldConf']['l10n_cat'])
1200 ) {
1201 // Fetching the TSconfig for the current table/field. This includes the $row which means that
1202 $PA['fieldTSConfig'] = $this->setTSconfig($table, $row, $field);
1203 // If the field is NOT disabled from TSconfig (which it could have been) then render it
1204 if (!$PA['fieldTSConfig']['disabled']) {
1205 // Override fieldConf by fieldTSconfig:
1206 $PA['fieldConf']['config'] = $this->overrideFieldConf($PA['fieldConf']['config'], $PA['fieldTSConfig']);
1207 // Init variables:
1208 $PA['itemFormElName'] = $this->prependFormFieldNames . '[' . $table . '][' . $row['uid'] . '][' . $field . ']';
1209 // Form field name, in case of file uploads
1210 $PA['itemFormElName_file'] = $this->prependFormFieldNames_file . '[' . $table . '][' . $row['uid'] . '][' . $field . ']';
1211 // Form field name, to activate elements
1212 // If the "eval" list contains "null", elements can be deactivated which results in storing NULL to database
1213 $PA['itemFormElNameActive'] = $this->prependFormFieldNamesActive . '[' . $table . '][' . $row['uid'] . '][' . $field . ']';
1214 // The value to show in the form field.
1215 $PA['itemFormElValue'] = $row[$field];
1216 $PA['itemFormElID'] = $this->prependFormFieldNames . '_' . $table . '_' . $row['uid'] . '_' . $field;
1217 // Set field to read-only if configured for translated records to show default language content as readonly
1218 if ($PA['fieldConf']['l10n_display'] && GeneralUtility::inList($PA['fieldConf']['l10n_display'], 'defaultAsReadonly') && $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0) {
1219 $PA['fieldConf']['config']['readOnly'] = TRUE;
1220 $PA['itemFormElValue'] = $this->defaultLanguageData[$table . ':' . $row['uid']][$field];
1221 }
1222 if (strpos($GLOBALS['TCA'][$table]['ctrl']['type'], ':') === FALSE) {
1223 $typeField = $GLOBALS['TCA'][$table]['ctrl']['type'];
1224 } else {
1225 $typeField = substr($GLOBALS['TCA'][$table]['ctrl']['type'], 0, strpos($GLOBALS['TCA'][$table]['ctrl']['type'], ':'));
1226 }
1227 // 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"
1228 if (
1229 !empty($GLOBALS['TCA'][$table]['ctrl']['type'])
1230 && $field === $typeField
1231 || !empty($GLOBALS['TCA'][$table]['ctrl']['requestUpdate'])
1232 && GeneralUtility::inList(str_replace(' ', '', $GLOBALS['TCA'][$table]['ctrl']['requestUpdate']), $field)
1233 ) {
1234 if ($this->getBackendUserAuthentication()->jsConfirmation(1)) {
1235 $alertMsgOnChange = 'if (confirm(TBE_EDITOR.labels.onChangeAlert) && TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm() };';
1236 } else {
1237 $alertMsgOnChange = 'if (TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm() };';
1238 }
1239 } else {
1240 $alertMsgOnChange = '';
1241 }
1242 // Render as a hidden field?
1243 if (in_array($field, $this->hiddenFieldListArr)) {
1244 $this->hiddenFieldAccum[] = '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($PA['itemFormElValue']) . '" />';
1245 } else {
1246 // Render as a normal field:
1247 // 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.
1248 $palJSfunc = '';
1249 $thePalIcon = '';
1250 if (!$PA['palette']) {
1251 $paletteFields = $this->loadPaletteElements($table, $row, $PA['pal']);
1252 if ($PA['pal'] && $this->isPalettesCollapsed($table, $PA['pal']) && count($paletteFields)) {
1253 list($thePalIcon, $palJSfunc) = $this->wrapOpenPalette(IconUtility::getSpriteIcon('actions-system-options-view', array('title' => htmlspecialchars($this->getLL('l_moreOptions')))), $table, $row, $PA['pal'], 1);
1254 }
1255 }
1256 // onFocus attribute to add to the field:
1257 $PA['onFocus'] = $palJSfunc && !$this->getBackendUserAuthentication()->uc['dontShowPalettesOnFocusInAB'] ? ' onfocus="' . htmlspecialchars($palJSfunc) . '"' : '';
1258 $PA['label'] = $PA['altName'] ?: $PA['fieldConf']['label'];
1259 $PA['label'] = $PA['fieldTSConfig']['label'] ?: $PA['label'];
1260 $PA['label'] = $PA['fieldTSConfig']['label.'][$this->getLanguageService()->lang] ?: $PA['label'];
1261 $PA['label'] = $this->sL($PA['label']);
1262 // JavaScript code for event handlers:
1263 $PA['fieldChangeFunc'] = array();
1264 $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = 'TBE_EDITOR.fieldChanged(\'' . $table . '\',\'' . $row['uid'] . '\',\'' . $field . '\',\'' . $PA['itemFormElName'] . '\');';
1265 $PA['fieldChangeFunc']['alert'] = $alertMsgOnChange;
1266 // If this is the child of an inline type and it is the field creating the label
1267 if ($this->inline->isInlineChildAndLabelField($table, $field)) {
1268 $inlineObjectId = implode(InlineElement::Structure_Separator, array(
1269 $this->inline->inlineNames['object'],
1270 $table,
1271 $row['uid']
1272 ));
1273 $PA['fieldChangeFunc']['inline'] = 'inline.handleChangedField(\'' . $PA['itemFormElName'] . '\',\'' . $inlineObjectId . '\');';
1274 }
1275 // Based on the type of the item, call a render function:
1276 $item = $this->getSingleField_SW($table, $field, $row, $PA);
1277 // Add language + diff
1278 if ($PA['fieldConf']['l10n_display'] && (GeneralUtility::inList($PA['fieldConf']['l10n_display'], 'hideDiff') || GeneralUtility::inList($PA['fieldConf']['l10n_display'], 'defaultAsReadonly'))) {
1279 $renderLanguageDiff = FALSE;
1280 } else {
1281 $renderLanguageDiff = TRUE;
1282 }
1283 if ($renderLanguageDiff) {
1284 $item = $this->renderDefaultLanguageContent($table, $field, $row, $item);
1285 $item = $this->renderDefaultLanguageDiff($table, $field, $row, $item);
1286 }
1287 // 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
1288 $label = htmlspecialchars($PA['label'], ENT_COMPAT, 'UTF-8', FALSE);
1289 if (MathUtility::canBeInterpretedAsInteger($row['uid']) && $PA['fieldTSConfig']['linkTitleToSelf'] && !GeneralUtility::_GP('columnsOnly')) {
1290 $lTTS_url = $this->backPath . 'alt_doc.php?edit[' . $table . '][' . $row['uid'] . ']=edit&columnsOnly=' . $field . '&returnUrl=' . rawurlencode($this->thisReturnUrl());
1291 $label = '<a href="' . htmlspecialchars($lTTS_url) . '">' . $label . '</a>';
1292 }
1293
1294 if (isset($PA['fieldConf']['config']['mode']) && $PA['fieldConf']['config']['mode'] == 'useOrOverridePlaceholder') {
1295 $placeholder = $this->getPlaceholderValue($table, $field, $PA['fieldConf']['config'], $row);
1296 $onChange = 'typo3form.fieldTogglePlaceholder(' . GeneralUtility::quoteJSvalue($PA['itemFormElName']) . ', !this.checked)';
1297 $checked = $PA['itemFormElValue'] === NULL ? '' : ' checked="checked"';
1298
1299 $this->additionalJS_post[] = 'typo3form.fieldTogglePlaceholder('
1300 . GeneralUtility::quoteJSvalue($PA['itemFormElName']) . ', ' . ($checked ? 'false' : 'true') . ');';
1301
1302 $item = '<div class="t3-form-field-placeholder-override">'
1303 . '<span class="t3-tceforms-placeholder-override-checkbox">' .
1304 '<input type="hidden" name="' . htmlspecialchars($PA['itemFormElNameActive']) . '" value="0" />' .
1305 '<input type="checkbox" name="' . htmlspecialchars($PA['itemFormElNameActive']) . '" value="1" id="tce-forms-textfield-use-override-' . $field . '-' . $row['uid'] . '" onchange="' . htmlspecialchars($onChange) . '"' . $checked . ' />' .
1306 '<label for="tce-forms-textfield-use-override-' . $field . '-' . $row['uid'] . '">' .
1307 sprintf($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.placeholder.override'),
1308 BackendUtility::getRecordTitlePrep($placeholder, 20)) . '</label>' .
1309 '</span>'
1310 . '<div class="t3-form-placeholder-placeholder">' . $this->getSingleField_typeNone_render(
1311 $PA['fieldConf']['config'], GeneralUtility::fixed_lgd_cs($placeholder, 30)
1312 ) . '</div>'
1313 . '<div class="t3-form-placeholder-formfield">' . $item . '</div>'
1314 . '</div>';
1315 }
1316
1317 // Wrap the label with help text
1318 $PA['label'] = ($label = BackendUtility::wrapInHelp($table, $field, $label));
1319 // Create output value:
1320 if ($PA['fieldConf']['config']['form_type'] == 'user' && $PA['fieldConf']['config']['noTableWrapping']) {
1321 $out = $item;
1322 } elseif ($PA['palette']) {
1323 // Array:
1324 $out = array(
1325 'NAME' => $label,
1326 'ID' => $row['uid'],
1327 'FIELD' => $field,
1328 'TABLE' => $table,
1329 'ITEM' => $item,
1330 'ITEM_DISABLED' => ($this->isDisabledNullValueField($table, $field, $row, $PA) ? ' disabled' : ''),
1331 'ITEM_NULLVALUE' => $this->renderNullValueWidget($table, $field, $row, $PA),
1332 );
1333 $out = $this->addUserTemplateMarkers($out, $table, $field, $row, $PA);
1334 } else {
1335 // String:
1336 $out = array(
1337 'NAME' => $label,
1338 'ITEM' => $item,
1339 'TABLE' => $table,
1340 'ID' => $row['uid'],
1341 'PAL_LINK_ICON' => $thePalIcon,
1342 'FIELD' => $field,
1343 'ITEM_DISABLED' => ($this->isDisabledNullValueField($table, $field, $row, $PA) ? ' disabled' : ''),
1344 'ITEM_NULLVALUE' => $this->renderNullValueWidget($table, $field, $row, $PA),
1345 );
1346 $out = $this->addUserTemplateMarkers($out, $table, $field, $row, $PA);
1347 // String:
1348 $out = $this->intoTemplate($out);
1349 }
1350 }
1351 } else {
1352 $this->commentMessages[] = $this->prependFormFieldNames . '[' . $table . '][' . $row['uid'] . '][' . $field . ']: Disabled by TSconfig';
1353 }
1354 }
1355 // Hook: getSingleField_postProcess
1356 foreach ($this->hookObjectsSingleField as $hookObj) {
1357 if (method_exists($hookObj, 'getSingleField_postProcess')) {
1358 $hookObj->getSingleField_postProcess($table, $field, $row, $out, $PA, $this);
1359 }
1360 }
1361 // Return value (string or array)
1362 return $out;
1363 }
1364
1365 /**
1366 * Rendering a single item for the form
1367 *
1368 * @param string $table Table name of record
1369 * @param string $field Fieldname to render
1370 * @param array $row The record
1371 * @param array $PA Parameters array containing a lot of stuff. Value by Reference!
1372 * @return string Returns the item as HTML code to insert
1373 * @access private
1374 * @see getSingleField(), getSingleField_typeFlex_draw()
1375 * @todo Define visibility
1376 */
1377 public function getSingleField_SW($table, $field, $row, &$PA) {
1378 $PA['fieldConf']['config']['form_type'] = $PA['fieldConf']['config']['form_type'] ?: $PA['fieldConf']['config']['type'];
1379 // Using "form_type" locally in this script
1380 // Hook: getSingleField_beforeRender
1381 foreach ($this->hookObjectsSingleField as $hookObject) {
1382 if (method_exists($hookObject, 'getSingleField_beforeRender')) {
1383 $hookObject->getSingleField_beforeRender($table, $field, $row, $PA);
1384 }
1385 }
1386 switch ($PA['fieldConf']['config']['form_type']) {
1387 case 'input':
1388 $item = $this->getSingleField_typeInput($table, $field, $row, $PA);
1389 break;
1390 case 'text':
1391 $item = $this->getSingleField_typeText($table, $field, $row, $PA);
1392 break;
1393 case 'check':
1394 $item = $this->getSingleField_typeCheck($table, $field, $row, $PA);
1395 break;
1396 case 'radio':
1397 $item = $this->getSingleField_typeRadio($table, $field, $row, $PA);
1398 break;
1399 case 'select':
1400 $item = $this->getSingleField_typeSelect($table, $field, $row, $PA);
1401 break;
1402 case 'group':
1403 $item = $this->getSingleField_typeGroup($table, $field, $row, $PA);
1404 break;
1405 case 'inline':
1406 $item = $this->inline->getSingleField_typeInline($table, $field, $row, $PA);
1407 break;
1408 case 'none':
1409 $item = $this->getSingleField_typeNone($table, $field, $row, $PA);
1410 break;
1411 case 'user':
1412 $item = $this->getSingleField_typeUser($table, $field, $row, $PA);
1413 break;
1414 case 'flex':
1415 $item = $this->getSingleField_typeFlex($table, $field, $row, $PA);
1416 break;
1417 default:
1418 $item = $this->getSingleField_typeUnknown($table, $field, $row, $PA);
1419 }
1420 return $item;
1421 }
1422
1423 /**********************************************************
1424 *
1425 * Rendering of each TCEform field type
1426 *
1427 ************************************************************/
1428 /**
1429 * Generation of TCEform elements of the type "input"
1430 * This will render a single-line input form field, possibly with various control/validation features
1431 *
1432 * @param string $table The table name of the record
1433 * @param string $field The field name which this element is supposed to edit
1434 * @param array $row The record data array where the value(s) for the field can be found
1435 * @param array $PA An array with additional configuration options.
1436 * @return string The HTML code for the TCEform field
1437 * @todo Define visibility
1438 */
1439 public function getSingleField_typeInput($table, $field, $row, &$PA) {
1440 $config = $PA['fieldConf']['config'];
1441 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
1442 $size = MathUtility::forceIntegerInRange($config['size'] ? $config['size'] : 30, 5, $this->maxInputWidth);
1443 $evalList = GeneralUtility::trimExplode(',', $config['eval'], TRUE);
1444 $classAndStyleAttributes = $this->formWidthAsArray($size);
1445 $fieldAppendix = '';
1446 $item = '';
1447 $cssClasses = array($classAndStyleAttributes['class']);
1448 $cssStyle = $classAndStyleAttributes['style'];
1449 if (!isset($config['checkbox'])) {
1450 $config['checkbox'] = '0';
1451 $checkboxIsset = FALSE;
1452 } else {
1453 $checkboxIsset = TRUE;
1454 }
1455 if (in_array('date', $evalList) || in_array('datetime', $evalList)) {
1456 if (in_array('datetime', $evalList)) {
1457 $class = 'datetime';
1458 } else {
1459 $class = 'date';
1460 }
1461 $dateRange = '';
1462 if (isset($config['range']['lower'])) {
1463 $dateRange .= ' lower-' . (int)$config['range']['lower'];
1464 }
1465 if (isset($config['range']['upper'])) {
1466 $dateRange .= ' upper-' . (int)$config['range']['upper'];
1467 }
1468 $inputId = uniqid('tceforms-' . $class . 'field-');
1469 $cssClasses[] = 'tceforms-textfield tceforms-' . $class . 'field' . $dateRange;
1470 $fieldAppendix = IconUtility::getSpriteIcon('actions-edit-pick-date', array(
1471 'style' => 'cursor:pointer;',
1472 'id' => 'picker-' . $inputId
1473 ));
1474 } elseif (in_array('timesec', $evalList)) {
1475 $inputId = uniqid('tceforms-timesecfield-');
1476 $cssClasses[] = 'tceforms-textfield tceforms-timesecfield';
1477 } elseif (in_array('year', $evalList)) {
1478 $inputId = uniqid('tceforms-yearfield-');
1479 $cssClasses[] = 'tceforms-textfield tceforms-yearfield';
1480 } elseif (in_array('time', $evalList)) {
1481 $inputId = uniqid('tceforms-timefield-');
1482 $cssClasses[] = 'tceforms-textfield tceforms-timefield';
1483 } elseif (in_array('int', $evalList)) {
1484 $inputId = uniqid('tceforms-intfield-');
1485 $cssClasses[] = 'tceforms-textfield tceforms-intfield';
1486 } elseif (in_array('double2', $evalList)) {
1487 $inputId = uniqid('tceforms-double2field-');
1488 $cssClasses[] = 'tceforms-textfield tceforms-double2field';
1489 } else {
1490 $inputId = uniqid('tceforms-textfield-');
1491 $cssClasses[] = 'tceforms-textfield';
1492 if ($checkboxIsset === FALSE) {
1493 $config['checkbox'] = '';
1494 }
1495 }
1496 if (isset($config['wizards']['link'])) {
1497 $inputId = uniqid('tceforms-linkfield-');
1498 $cssClasses[] = 'tceforms-textfield tceforms-linkfield';
1499 } elseif (isset($config['wizards']['color'])) {
1500 $inputId = uniqid('tceforms-colorfield-');
1501 $cssClasses[] = 'tceforms-textfield tceforms-colorfield';
1502 }
1503 if ($this->renderReadonly || $config['readOnly']) {
1504 $itemFormElValue = $PA['itemFormElValue'];
1505 if (in_array('date', $evalList)) {
1506 $config['format'] = 'date';
1507 } elseif (in_array('datetime', $evalList)) {
1508 $config['format'] = 'datetime';
1509 } elseif (in_array('time', $evalList)) {
1510 $config['format'] = 'time';
1511 }
1512 if (in_array('password', $evalList)) {
1513 $itemFormElValue = $itemFormElValue ? '*********' : '';
1514 }
1515 return $this->getSingleField_typeNone_render($config, $itemFormElValue);
1516 }
1517 foreach ($evalList as $func) {
1518 switch ($func) {
1519 case 'required':
1520 $this->registerRequiredProperty('field', $table . '_' . $row['uid'] . '_' . $field, $PA['itemFormElName']);
1521 // Mark this field for date/time disposal:
1522 if (array_intersect($evalList, array('date', 'datetime', 'time'))) {
1523 $this->requiredAdditional[$PA['itemFormElName']]['isPositiveNumber'] = TRUE;
1524 }
1525 break;
1526 default:
1527 // Pair hook to the one in \TYPO3\CMS\Core\DataHandling\DataHandler::checkValue_input_Eval()
1528 $evalObj = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func] . ':&' . $func);
1529 if (is_object($evalObj) && method_exists($evalObj, 'deevaluateFieldValue')) {
1530 $_params = array(
1531 'value' => $PA['itemFormElValue']
1532 );
1533 $PA['itemFormElValue'] = $evalObj->deevaluateFieldValue($_params);
1534 }
1535 }
1536 }
1537 $paramsList = '\'' . $PA['itemFormElName'] . '\',\'' . implode(',', $evalList) . '\',\'' . trim($config['is_in']) . '\',' . (isset($config['checkbox']) ? 1 : 0) . ',\'' . $config['checkbox'] . '\'';
1538 if (in_array('date', $evalList) || in_array('datetime', $evalList)) {
1539 $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\';">';
1540 // Add server timezone offset to UTC to our stored date
1541 if ($PA['itemFormElValue'] > 0) {
1542 $PA['itemFormElValue'] += date('Z', $PA['itemFormElValue']);
1543 }
1544 } else {
1545 $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\';">';
1546 }
1547 $PA['fieldChangeFunc'] = array_merge(array('typo3form.fieldGet' => 'typo3form.fieldGet(' . $paramsList . ');'), $PA['fieldChangeFunc']);
1548 // Old function "checkbox" now the option to set the date / remove the date
1549 if (isset($config['checkbox'])) {
1550 $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'])));
1551 }
1552 $mLgd = $config['max'] ?: 256;
1553 $iOnChange = implode('', $PA['fieldChangeFunc']);
1554 $cssClasses[] = 'hasDefaultValue';
1555 $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'] . ' />';
1556 // This is the EDITABLE form field.
1557 $item .= '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($PA['itemFormElValue']) . '" />';
1558 // 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.
1559 $item .= $fieldAppendix . '</span><div style="clear:both;"></div>';
1560 $this->extJSCODE .= 'typo3form.fieldSet(' . $paramsList . ');';
1561 // Going through all custom evaluations configured for this field
1562 foreach ($evalList as $evalData) {
1563 $evalObj = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$evalData] . ':&' . $evalData);
1564 if (is_object($evalObj) && method_exists($evalObj, 'returnFieldJS')) {
1565 $this->extJSCODE .= '
1566 TBE_EDITOR.customEvalFunctions[\'' . $evalData . '\'] = function(value) {
1567 ' . $evalObj->returnFieldJS() . '
1568 }
1569 ';
1570 }
1571 }
1572 // Creating an alternative item without the JavaScript handlers.
1573 $altItem = '<input type="hidden" name="' . $PA['itemFormElName'] . '_hr" value="" />';
1574 $altItem .= '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($PA['itemFormElValue']) . '" />';
1575 // Wrap a wizard around the item?
1576 $item = $this->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA, $PA['itemFormElName'] . '_hr', $specConf);
1577
1578 return $item;
1579 }
1580
1581 /**
1582 * Renders a view widget to handle and activate NULL values.
1583 * The widget is enabled by using 'null' in the 'eval' TCA definition.
1584 *
1585 * @param string $table Name of the table
1586 * @param string $field Name of the field
1587 * @param array $row Accordant data of the record row
1588 * @param array $PA Parameters array with rendering instructions
1589 * @return string Widget (if any).
1590 */
1591 protected function renderNullValueWidget($table, $field, array $row, array $PA) {
1592 $widget = '';
1593
1594 $config = $PA['fieldConf']['config'];
1595 if (
1596 !empty($config['eval']) && GeneralUtility::inList($config['eval'], 'null')
1597 && (empty($config['mode']) || $config['mode'] !== 'useOrOverridePlaceholder')
1598 ) {
1599 $checked = $PA['itemFormElValue'] === NULL ? '' : ' checked="checked"';
1600 $onChange = htmlspecialchars(
1601 'typo3form.fieldSetNull(\'' . $PA['itemFormElName'] . '\', !this.checked)'
1602 );
1603
1604 $widget = '<span class="t3-tceforms-widget-null-wrapper">' .
1605 '<input type="hidden" name="' . $PA['itemFormElNameActive'] . '" value="0" />' .
1606 '<input type="checkbox" name="' . $PA['itemFormElNameActive'] . '" value="1" onchange="' . $onChange . '"' . $checked . ' />' .
1607 '</span>';
1608 }
1609
1610 return $widget;
1611 }
1612
1613 /**
1614 * Determines whether the current field value is considered as NULL value.
1615 * Using NULL values is enabled by using 'null' in the 'eval' TCA definition.
1616 *
1617 * @param string $table Name of the table
1618 * @param string $field Name of the field
1619 * @param array $row Accordant data
1620 * @param array $PA Parameters array with rendering instructions
1621 * @return boolean
1622 */
1623 protected function isDisabledNullValueField($table, $field, array $row, array $PA) {
1624 $result = FALSE;
1625
1626 $config = $PA['fieldConf']['config'];
1627 if ($PA['itemFormElValue'] === NULL && !empty($config['eval'])
1628 && GeneralUtility::inList($config['eval'], 'null')
1629 && (empty($config['mode']) || $config['mode'] !== 'useOrOverridePlaceholder')) {
1630
1631 $result = TRUE;
1632 }
1633
1634 return $result;
1635 }
1636
1637 /**
1638 * Generation of TCEform elements of the type "text"
1639 * This will render a <textarea> OR RTE area form field, possibly with various control/validation features
1640 *
1641 * @param string $table The table name of the record
1642 * @param string $field The field name which this element is supposed to edit
1643 * @param array $row The record data array where the value(s) for the field can be found
1644 * @param array $PA An array with additional configuration options.
1645 * @return string The HTML code for the TCEform field
1646 * @todo Define visibility
1647 */
1648 public function getSingleField_typeText($table, $field, $row, &$PA) {
1649 // Init config:
1650 $config = $PA['fieldConf']['config'];
1651 $evalList = GeneralUtility::trimExplode(',', $config['eval'], TRUE);
1652 if ($this->renderReadonly || $config['readOnly']) {
1653 return $this->getSingleField_typeNone_render($config, $PA['itemFormElValue']);
1654 }
1655 // Setting columns number:
1656 $cols = MathUtility::forceIntegerInRange($config['cols'] ? $config['cols'] : 30, 5, $this->maxTextareaWidth);
1657 // Setting number of rows:
1658 $origRows = ($rows = MathUtility::forceIntegerInRange($config['rows'] ? $config['rows'] : 5, 1, 20));
1659 if (strlen($PA['itemFormElValue']) > $this->charsPerRow * 2) {
1660 $cols = $this->maxTextareaWidth;
1661 $rows = MathUtility::forceIntegerInRange(round(strlen($PA['itemFormElValue']) / $this->charsPerRow), count(explode(LF, $PA['itemFormElValue'])), 20);
1662 if ($rows < $origRows) {
1663 $rows = $origRows;
1664 }
1665 }
1666 if (in_array('required', $evalList)) {
1667 $this->requiredFields[$table . '_' . $row['uid'] . '_' . $field] = $PA['itemFormElName'];
1668 }
1669 // Init RTE vars:
1670 // Set TRUE, if the RTE is loaded; If not a normal textarea is shown.
1671 $RTEwasLoaded = 0;
1672 // Set TRUE, if the RTE would have been loaded if it wasn't for the disable-RTE flag in the bottom of the page...
1673 $RTEwouldHaveBeenLoaded = 0;
1674 // "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist. Traditionally, this is where RTE configuration has been found.
1675 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
1676 // Setting up the altItem form field, which is a hidden field containing the value
1677 $altItem = '<input type="hidden" name="' . htmlspecialchars($PA['itemFormElName']) . '" value="' . htmlspecialchars($PA['itemFormElValue']) . '" />';
1678 $item = '';
1679 // If RTE is generally enabled (TYPO3_CONF_VARS and user settings)
1680 if ($this->RTEenabled) {
1681 $p = BackendUtility::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']);
1682 // If the field is configured for RTE and if any flag-field is not set to disable it.
1683 if (isset($specConf['richtext']) && (!$p['flag'] || !$row[$p['flag']])) {
1684 BackendUtility::fixVersioningPid($table, $row);
1685 list($tscPID, $thePidValue) = $this->getTSCpid($table, $row['uid'], $row['pid']);
1686 // If the pid-value is not negative (that is, a pid could NOT be fetched)
1687 if ($thePidValue >= 0) {
1688 $RTEsetup = $this->getBackendUserAuthentication()->getTSConfig('RTE', BackendUtility::getPagesTSconfig($tscPID));
1689 $RTEtypeVal = BackendUtility::getTCAtypeValue($table, $row);
1690 $thisConfig = BackendUtility::RTEsetup($RTEsetup['properties'], $table, $field, $RTEtypeVal);
1691 if (!$thisConfig['disabled']) {
1692 if (!$this->disableRTE) {
1693 $this->RTEcounter++;
1694 // Find alternative relative path for RTE images/links:
1695 $eFile = RteHtmlParser::evalWriteFile($specConf['static_write'], $row);
1696 $RTErelPath = is_array($eFile) ? dirname($eFile['relEditFile']) : '';
1697 // Get RTE object, draw form and set flag:
1698 $RTEobj = BackendUtility::RTEgetObj();
1699 $item = $RTEobj->drawRTE($this, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue);
1700 // Wizard:
1701 $item = $this->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA, $PA['itemFormElName'], $specConf, 1);
1702 $RTEwasLoaded = 1;
1703 } else {
1704 $RTEwouldHaveBeenLoaded = 1;
1705 $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!)';
1706 }
1707 } else {
1708 $this->commentMessages[] = $PA['itemFormElName'] . ': RTE is disabled by the Page TSconfig, "RTE"-key (eg. by RTE.default.disabled=0 or such)';
1709 }
1710 } else {
1711 $this->commentMessages[] = $PA['itemFormElName'] . ': PID value could NOT be fetched. Rare error, normally with new records.';
1712 }
1713 } else {
1714 if (!isset($specConf['richtext'])) {
1715 $this->commentMessages[] = $PA['itemFormElName'] . ': RTE was not configured for this field in TCA-types';
1716 }
1717 if (!(!$p['flag'] || !$row[$p['flag']])) {
1718 $this->commentMessages[] = $PA['itemFormElName'] . ': Field-flag (' . $PA['flag'] . ') has been set to disable RTE!';
1719 }
1720 }
1721 }
1722 // Display ordinary field if RTE was not loaded.
1723 if (!$RTEwasLoaded) {
1724 // Show message, if no RTE (field can only be edited with RTE!)
1725 if ($specConf['rte_only']) {
1726 $item = '<p><em>' . htmlspecialchars($this->getLL('l_noRTEfound')) . '</em></p>';
1727 } else {
1728 if ($specConf['nowrap']) {
1729 $wrap = 'off';
1730 } else {
1731 $wrap = $config['wrap'] ?: 'virtual';
1732 }
1733 $classes = array();
1734 if ($specConf['fixed-font']) {
1735 $classes[] = 'fixed-font';
1736 }
1737 if ($specConf['enable-tab']) {
1738 $classes[] = 'enable-tab';
1739 }
1740 $formWidthText = $this->formWidthText($cols, $wrap);
1741 // Extract class attributes from $formWidthText (otherwise it would be added twice to the output)
1742 $res = array();
1743 if (preg_match('/ class="(.+?)"/', $formWidthText, $res)) {
1744 $formWidthText = str_replace(' class="' . $res[1] . '"', '', $formWidthText);
1745 $classes = array_merge($classes, explode(' ', $res[1]));
1746 }
1747 if (count($classes)) {
1748 $class = ' class="tceforms-textarea ' . implode(' ', $classes) . '"';
1749 } else {
1750 $class = 'tceforms-textarea';
1751 }
1752 $evalList = GeneralUtility::trimExplode(',', $config['eval'], TRUE);
1753 foreach ($evalList as $func) {
1754 switch ($func) {
1755 case 'required':
1756 $this->registerRequiredProperty('field', $table . '_' . $row['uid'] . '_' . $field, $PA['itemFormElName']);
1757 break;
1758 default:
1759 // Pair hook to the one in \TYPO3\CMS\Core\DataHandling\DataHandler::checkValue_input_Eval()
1760 // and \TYPO3\CMS\Core\DataHandling\DataHandler::checkValue_text_Eval()
1761 $evalObj = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func] . ':&' . $func);
1762 if (is_object($evalObj) && method_exists($evalObj, 'deevaluateFieldValue')) {
1763 $_params = array(
1764 'value' => $PA['itemFormElValue']
1765 );
1766 $PA['itemFormElValue'] = $evalObj->deevaluateFieldValue($_params);
1767 }
1768 }
1769 }
1770 $iOnChange = implode('', $PA['fieldChangeFunc']);
1771 $item .= '
1772 <textarea ' . 'id="' . uniqid('tceforms-textarea-') . '" ' . 'name="' . $PA['itemFormElName']
1773 . '"' . $formWidthText . $class . ' ' . 'rows="' . $rows . '" ' . 'wrap="' . $wrap . '" ' . 'onchange="'
1774 . htmlspecialchars($iOnChange) . '"' . $this->getPlaceholderAttribute($table, $field, $config, $row)
1775 . $PA['onFocus'] . '>' . GeneralUtility::formatForTextarea($PA['itemFormElValue']) . '</textarea>';
1776 $item = $this->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA,
1777 $PA['itemFormElName'], $specConf, $RTEwouldHaveBeenLoaded);
1778 }
1779 }
1780 // Return field HTML:
1781 return $item;
1782 }
1783
1784 /**
1785 * Generation of TCEform elements of the type "check"
1786 * This will render a check-box OR an array of checkboxes
1787 *
1788 * @param string $table The table name of the record
1789 * @param string $field The field name which this element is supposed to edit
1790 * @param array $row The record data array where the value(s) for the field can be found
1791 * @param array $PA An array with additional configuration options.
1792 * @return string The HTML code for the TCEform field
1793 * @todo Define visibility
1794 */
1795 public function getSingleField_typeCheck($table, $field, $row, &$PA) {
1796 $config = $PA['fieldConf']['config'];
1797 $item = '';
1798 $disabled = '';
1799 if ($this->renderReadonly || $config['readOnly']) {
1800 $disabled = ' disabled="disabled"';
1801 }
1802 // Traversing the array of items:
1803 $selItems = $this->initItemArray($PA['fieldConf']);
1804 if ($config['itemsProcFunc']) {
1805 $selItems = $this->procItems($selItems, $PA['fieldTSConfig']['itemsProcFunc.'], $config, $table, $row, $field);
1806 }
1807 if (!count($selItems)) {
1808 $selItems[] = array('', '');
1809 }
1810 $thisValue = (int)$PA['itemFormElValue'];
1811 $cols = (int)$config['cols'];
1812 $selItemsCount = count($selItems);
1813 if ($cols > 1) {
1814 $item .= '<table border="0" cellspacing="0" cellpadding="0" class="typo3-TCEforms-checkboxArray">';
1815 for ($c = 0; $c < $selItemsCount; $c++) {
1816 $p = $selItems[$c];
1817 if (!($c % $cols)) {
1818 $item .= '<tr>';
1819 }
1820 $cBP = $this->checkBoxParams($PA['itemFormElName'], $thisValue, $c, count($selItems), implode('', $PA['fieldChangeFunc']));
1821 $cBName = $PA['itemFormElName'] . '_' . $c;
1822 $cBID = $PA['itemFormElID'] . '_' . $c;
1823 $item .= '<td nowrap="nowrap">' . '<input type="checkbox"' . $this->insertDefStyle('check')
1824 . ' value="1" name="' . $cBName . '"' . $cBP . $disabled . ' id="' . $cBID . '" />'
1825 . $this->wrapLabels(('<label for="' . $cBID . '">' . htmlspecialchars($p[0]) . '</label>&nbsp;'))
1826 . '</td>';
1827 if ($c % $cols + 1 == $cols) {
1828 $item .= '</tr>';
1829 }
1830 }
1831 if ($c % $cols) {
1832 $rest = $cols - $c % $cols;
1833 for ($c = 0; $c < $rest; $c++) {
1834 $item .= '<td></td>';
1835 }
1836 if ($c > 0) {
1837 $item .= '</tr>';
1838 }
1839 }
1840 $item .= '</table>';
1841 } else {
1842 for ($c = 0; $c < $selItemsCount; $c++) {
1843 $p = $selItems[$c];
1844 $cBP = $this->checkBoxParams($PA['itemFormElName'], $thisValue, $c, count($selItems), implode('', $PA['fieldChangeFunc']));
1845 $cBName = $PA['itemFormElName'] . '_' . $c;
1846 $cBID = $PA['itemFormElID'] . '_' . $c;
1847 $item .= ($c > 0 ? '<br />' : '') . '<input type="checkbox"' . $this->insertDefStyle('check')
1848 . ' value="1" name="' . $cBName . '"' . $cBP . $PA['onFocus'] . $disabled . ' id="' . $cBID . '" />'
1849 . $this->wrapLabels('<label for="' . $cBID . '">' . htmlspecialchars($p[0]) . '</label>');
1850 }
1851 }
1852 if (!$disabled) {
1853 $item .= '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($thisValue) . '" />';
1854 }
1855 return $item;
1856 }
1857
1858 /**
1859 * Generation of TCEform elements of the type "radio"
1860 * This will render a series of radio buttons.
1861 *
1862 * @param string $table The table name of the record
1863 * @param string $field The field name which this element is supposed to edit
1864 * @param array $row The record data array where the value(s) for the field can be found
1865 * @param array $PA An array with additional configuration options.
1866 * @return string The HTML code for the TCEform field
1867 * @todo Define visibility
1868 */
1869 public function getSingleField_typeRadio($table, $field, $row, &$PA) {
1870 $config = $PA['fieldConf']['config'];
1871 $item = '';
1872 $disabled = '';
1873 if ($this->renderReadonly || $config['readOnly']) {
1874 $disabled = ' disabled="disabled"';
1875 }
1876 // Get items for the array:
1877 $selItems = $this->initItemArray($PA['fieldConf']);
1878 if ($config['itemsProcFunc']) {
1879 $selItems = $this->procItems($selItems, $PA['fieldTSConfig']['itemsProcFunc.'], $config, $table, $row, $field);
1880 }
1881 // Traverse the items, making the form elements:
1882 $selItemsCount = count($selItems);
1883 for ($c = 0; $c < $selItemsCount; $c++) {
1884 $p = $selItems[$c];
1885 $rID = $PA['itemFormElID'] . '_' . $c;
1886 $rOnClick = implode('', $PA['fieldChangeFunc']);
1887 $rChecked = (string)$p[1] === (string)$PA['itemFormElValue'] ? ' checked="checked"' : '';
1888 $item .= '<input type="radio"' . $this->insertDefStyle('radio') . ' name="' . $PA['itemFormElName']
1889 . '" value="' . htmlspecialchars($p[1]) . '" onclick="' . htmlspecialchars($rOnClick) . '"' . $rChecked
1890 . $PA['onFocus'] . $disabled . ' id="' . $rID . '" />
1891 <label for="' . $rID . '">' . htmlspecialchars($p[0]) . '</label>
1892 <br />';
1893 }
1894 return $item;
1895 }
1896
1897 /**
1898 * Generation of TCEform elements of the type "select"
1899 * This will render a selector box element, or possibly a special construction with two selector boxes.
1900 * That depends on configuration.
1901 *
1902 * @param string $table The table name of the record
1903 * @param string $field The field name which this element is supposed to edit
1904 * @param array $row The record data array where the value(s) for the field can be found
1905 * @param array $PA An array with additional configuration options.
1906 * @return string The HTML code for the TCEform field
1907 * @todo Define visibility
1908 */
1909 public function getSingleField_typeSelect($table, $field, $row, &$PA) {
1910 // Field configuration from TCA:
1911 $config = $PA['fieldConf']['config'];
1912 $disabled = '';
1913 if ($this->renderReadonly || $config['readOnly']) {
1914 $disabled = ' disabled="disabled"';
1915 }
1916 // "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist.
1917 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
1918 $selItems = $this->getSelectItems($table, $field, $row, $PA);
1919
1920 // Creating the label for the "No Matching Value" entry.
1921 $nMV_label = isset($PA['fieldTSConfig']['noMatchingValue_label'])
1922 ? $this->sL($PA['fieldTSConfig']['noMatchingValue_label'])
1923 : '[ ' . $this->getLL('l_noMatchingValue') . ' ]';
1924 // Prepare some values:
1925 $maxitems = (int)$config['maxitems'];
1926 // If a SINGLE selector box...
1927 if ($maxitems <= 1 && $config['renderMode'] !== 'tree') {
1928 $item = $this->getSingleField_typeSelect_single($table, $field, $row, $PA, $config, $selItems, $nMV_label);
1929 } elseif ($config['renderMode'] === 'checkbox') {
1930 // Checkbox renderMode
1931 $item = $this->getSingleField_typeSelect_checkbox($table, $field, $row, $PA, $config, $selItems, $nMV_label);
1932 } elseif ($config['renderMode'] === 'singlebox') {
1933 // Single selector box renderMode
1934 $item = $this->getSingleField_typeSelect_singlebox($table, $field, $row, $PA, $config, $selItems, $nMV_label);
1935 } elseif ($config['renderMode'] === 'tree') {
1936 // Tree renderMode
1937 $treeClass = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\Element\\TreeElement', $this);
1938 $item = $treeClass->renderField($table, $field, $row, $PA, $config, $selItems, $nMV_label);
1939 // Register the required number of elements
1940 $minitems = MathUtility::forceIntegerInRange($config['minitems'], 0);
1941 $this->registerRequiredProperty('range', $PA['itemFormElName'], array($minitems, $maxitems, 'imgName' => $table . '_' . $row['uid'] . '_' . $field));
1942 } else {
1943 // Traditional multiple selector box:
1944 $item = $this->getSingleField_typeSelect_multiple($table, $field, $row, $PA, $config, $selItems, $nMV_label);
1945 }
1946 // Wizards:
1947 if (!$disabled) {
1948 $altItem = '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($PA['itemFormElValue']) . '" />';
1949 $item = $this->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA, $PA['itemFormElName'], $specConf);
1950 }
1951 return $item;
1952 }
1953
1954 /**
1955 * Collects the items for a select field by reading the configured
1956 * select items from the configuration and / or by collecting them
1957 * from a foreign table.
1958 *
1959 * @param string $table The table name of the record
1960 * @param string $fieldName The select field name
1961 * @param array $row The record data array where the value(s) for the field can be found
1962 * @param array $PA An array with additional configuration options.
1963 * @return array
1964 */
1965 public function getSelectItems($table, $fieldName, array $row, array $PA) {
1966 $config = $PA['fieldConf']['config'];
1967
1968 // Getting the selector box items from the system
1969 $selectItems = $this->addSelectOptionsToItemArray(
1970 $this->initItemArray($PA['fieldConf']),
1971 $PA['fieldConf'],
1972 $this->setTSconfig($table, $row),
1973 $fieldName
1974 );
1975
1976 // Possibly filter some items:
1977 $selectItems = GeneralUtility::keepItemsInArray(
1978 $selectItems,
1979 $PA['fieldTSConfig']['keepItems'],
1980 function ($value) {
1981 return $value[1];
1982 }
1983 );
1984
1985 // Possibly add some items:
1986 $selectItems = $this->addItems($selectItems, $PA['fieldTSConfig']['addItems.']);
1987
1988 // Process items by a user function:
1989 if (isset($config['itemsProcFunc']) && $config['itemsProcFunc']) {
1990 $selectItems = $this->procItems($selectItems, $PA['fieldTSConfig']['itemsProcFunc.'], $config, $table, $row, $fieldName);
1991 }
1992
1993 // Possibly remove some items:
1994 $removeItems = GeneralUtility::trimExplode(',', $PA['fieldTSConfig']['removeItems'], TRUE);
1995 foreach ($selectItems as $selectItemIndex => $selectItem) {
1996
1997 // Checking languages and authMode:
1998 $languageDeny = FALSE;
1999 $beUserAuth = $this->getBackendUserAuthentication();
2000 if (
2001 !empty($GLOBALS['TCA'][$table]['ctrl']['languageField'])
2002 && $GLOBALS['TCA'][$table]['ctrl']['languageField'] === $fieldName
2003 && !$beUserAuth->checkLanguageAccess($selectItem[1])
2004 ) {
2005 $languageDeny = TRUE;
2006 }
2007
2008 $authModeDeny = FALSE;
2009 if (
2010 ($config['form_type'] === 'select')
2011 && $config['authMode']
2012 && !$beUserAuth->checkAuthMode($table, $fieldName, $selectItem[1], $config['authMode'])
2013 ) {
2014 $authModeDeny = TRUE;
2015 }
2016
2017 if (in_array($selectItem[1], $removeItems) || $languageDeny || $authModeDeny) {
2018 unset($selectItems[$selectItemIndex]);
2019 } elseif (isset($PA['fieldTSConfig']['altLabels.'][$selectItem[1]])) {
2020 $selectItems[$selectItemIndex][0] = htmlspecialchars($this->sL($PA['fieldTSConfig']['altLabels.'][$selectItem[1]]));
2021 }
2022
2023 // Removing doktypes with no access:
2024 if (($table === 'pages' || $table === 'pages_language_overlay') && $fieldName === 'doktype') {
2025 if (!($beUserAuth->isAdmin() || GeneralUtility::inList($beUserAuth->groupData['pagetypes_select'], $selectItem[1]))) {
2026 unset($selectItems[$selectItemIndex]);
2027 }
2028 }
2029 }
2030
2031 return $selectItems;
2032 }
2033
2034 /**
2035 * Creates a single-selector box
2036 * (Render function for getSingleField_typeSelect())
2037 *
2038 * @param string $table See getSingleField_typeSelect()
2039 * @param string $field See getSingleField_typeSelect()
2040 * @param array $row See getSingleField_typeSelect()
2041 * @param array $PA See getSingleField_typeSelect()
2042 * @param array $config (Redundant) content of $PA['fieldConf']['config'] (for convenience)
2043 * @param array $selItems Items available for selection
2044 * @param string $nMV_label Label for no-matching-value
2045 * @return string The HTML code for the item
2046 * @see getSingleField_typeSelect()
2047 * @todo Define visibility
2048 */
2049 public function getSingleField_typeSelect_single($table, $field, $row, &$PA, $config, $selItems, $nMV_label) {
2050 // check against inline uniqueness
2051 $inlineParent = $this->inline->getStructureLevel(-1);
2052 $uniqueIds = NULL;
2053 if (is_array($inlineParent) && $inlineParent['uid']) {
2054 if ($inlineParent['config']['foreign_table'] == $table && $inlineParent['config']['foreign_unique'] == $field) {
2055 $uniqueIds = $this->inline->inlineData['unique'][$this->inline->inlineNames['object']
2056 . InlineElement::Structure_Separator . $table]['used'];
2057 $PA['fieldChangeFunc']['inlineUnique'] = 'inline.updateUnique(this,\'' . $this->inline->inlineNames['object']
2058 . InlineElement::Structure_Separator . $table . '\',\'' . $this->inline->inlineNames['form']
2059 . '\',\'' . $row['uid'] . '\');';
2060 }
2061 // hide uid of parent record for symmetric relations
2062 if (
2063 $inlineParent['config']['foreign_table'] == $table
2064 && ($inlineParent['config']['foreign_field'] == $field || $inlineParent['config']['symmetric_field'] == $field)
2065 ) {
2066 $uniqueIds[] = $inlineParent['uid'];
2067 }
2068 }
2069 // Initialization:
2070 $c = 0;
2071 $sI = 0;
2072 $noMatchingValue = 1;
2073 $opt = array();
2074 $selicons = array();
2075 $onlySelectedIconShown = 0;
2076 $size = (int)$config['size'];
2077 // Style set on <select/>
2078 $selectedStyle = '';
2079 $item = '';
2080 $disabled = '';
2081 if ($this->renderReadonly || $config['readOnly']) {
2082 $disabled = ' disabled="disabled"';
2083 $onlySelectedIconShown = 1;
2084 }
2085 // Register as required if minitems is greater than zero
2086 if (($minItems = MathUtility::forceIntegerInRange($config['minitems'], 0)) > 0) {
2087 $this->registerRequiredProperty('field', $table . '_' . $row['uid'] . '_' . $field, $PA['itemFormElName']);
2088 }
2089
2090 // Icon configuration:
2091 if ($config['suppress_icons'] == 'IF_VALUE_FALSE') {
2092 $suppressIcons = !$PA['itemFormElValue'] ? 1 : 0;
2093 } elseif ($config['suppress_icons'] == 'ONLY_SELECTED') {
2094 $suppressIcons = 0;
2095 $onlySelectedIconShown = 1;
2096 } elseif ($config['suppress_icons']) {
2097 $suppressIcons = 1;
2098 } else {
2099 $suppressIcons = 0;
2100 }
2101 // Traverse the Array of selector box items:
2102 $optGroupStart = array();
2103 $optGroupOpen = FALSE;
2104 $classesForSelectTag = array();
2105 foreach ($selItems as $p) {
2106 $sM = (string)$PA['itemFormElValue'] === (string)$p[1] ? ' selected="selected"' : '';
2107 if ($sM) {
2108 $sI = $c;
2109 $noMatchingValue = 0;
2110 }
2111 // Getting style attribute value (for icons):
2112 $styleAttrValue = '';
2113 if ($config['iconsInOptionTags']) {
2114 $styleAttrValue = $this->optionTagStyle($p[2]);
2115 if ($sM) {
2116 list($selectIconFile, $selectIconInfo) = $this->getIcon($p[2]);
2117 if (!empty($selectIconInfo)) {
2118 $selectedStyle = ' style="background-image:url(' . $selectIconFile . ');"';
2119 $classesForSelectTag[] = 'typo3-TCEforms-select-selectedItemWithBackgroundImage';
2120 }
2121 }
2122 }
2123 // Compiling the <option> tag:
2124 if (!($p[1] != $PA['itemFormElValue'] && is_array($uniqueIds) && in_array($p[1], $uniqueIds))) {
2125 if ($p[1] === '--div--') {
2126 $optGroupStart[0] = $p[0];
2127 if ($config['iconsInOptionTags']) {
2128 $optGroupStart[1] = $this->optgroupTagStyle($p[2]);
2129 } else {
2130 $optGroupStart[1] = $styleAttrValue;
2131 }
2132 } else {
2133 if (count($optGroupStart)) {
2134 // Closing last optgroup before next one starts
2135 if ($optGroupOpen) {
2136 $opt[] = '</optgroup>' . LF;
2137 }
2138 $opt[] = '<optgroup label="' . htmlspecialchars($optGroupStart[0], ENT_COMPAT, 'UTF-8', FALSE)
2139 . '"' . ($optGroupStart[1] ? ' style="' . htmlspecialchars($optGroupStart[1]) . '"' : '')
2140 . ' class="c-divider">' . LF;
2141 $optGroupOpen = TRUE;
2142 $c--;
2143 $optGroupStart = array();
2144 }
2145 $opt[] = '<option value="' . htmlspecialchars($p[1]) . '"' . $sM
2146 . ($styleAttrValue ? ' style="' . htmlspecialchars($styleAttrValue) . '"' : '') . '>'
2147 . htmlspecialchars($p[0], ENT_COMPAT, 'UTF-8', FALSE) . '</option>' . LF;
2148 }
2149 }
2150 // If there is an icon for the selector box (rendered in selicon-table below)...:
2151 // if there is an icon ($p[2]), icons should be shown, and, if only selected are visible, is it selected
2152 if ($p[2] && !$suppressIcons && (!$onlySelectedIconShown || $sM)) {
2153 list($selIconFile, $selIconInfo) = $this->getIcon($p[2]);
2154 $iOnClick = $this->elName($PA['itemFormElName']) . '.selectedIndex=' . $c . '; '. $this->elName($PA['itemFormElName']);
2155 $iOnClickOptions = $this->elName($PA['itemFormElName']) . '.options[' . $c . ']';
2156 if (empty($selIconInfo)) {
2157 $iOnClick .= '.className=' . $iOnClickOptions . '.className; ';
2158 } else {
2159 $iOnClick .= '.style.backgroundImage=' . $iOnClickOptions . '.style.backgroundImage; ';
2160 }
2161 $iOnClick .= implode('', $PA['fieldChangeFunc']) . 'this.blur(); return false;';
2162 $selicons[] = array(
2163 (!$onlySelectedIconShown ? '<a href="#" onclick="' . htmlspecialchars($iOnClick) . '">' : '')
2164 . $this->getIconHtml($p[2], htmlspecialchars($p[0]), htmlspecialchars($p[0]))
2165 . (!$onlySelectedIconShown ? '</a>' : ''),
2166 $c,
2167 $sM
2168 );
2169 }
2170 $c++;
2171 }
2172 // Closing optgroup if open
2173 if ($optGroupOpen) {
2174 $opt[] = '</optgroup>';
2175 }
2176 // No-matching-value:
2177 if ($PA['itemFormElValue'] && $noMatchingValue && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
2178 $nMV_label = @sprintf($nMV_label, $PA['itemFormElValue']);
2179 $opt[] = '<option value="' . htmlspecialchars($PA['itemFormElValue']) . '" selected="selected">' . htmlspecialchars($nMV_label) . '</option>';
2180 }
2181 // Create item form fields:
2182 $sOnChange = 'if (this.options[this.selectedIndex].value==\'--div--\') {this.selectedIndex=' . $sI . ';} ' . implode('', $PA['fieldChangeFunc']);
2183 if (!$disabled) {
2184 // MUST be inserted before the selector - else is the value of the hiddenfield here mysteriously submitted...
2185 $item .= '<input type="hidden" name="' . $PA['itemFormElName'] . '_selIconVal" value="' . htmlspecialchars($sI) . '" />';
2186 }
2187 if ($config['iconsInOptionTags']) {
2188 $classesForSelectTag[] = 'icon-select';
2189 }
2190 $item .= '<select' . $selectedStyle . ' id="' . uniqid('tceforms-select-') . '" name="' . $PA['itemFormElName'] . '"' . $this->insertDefStyle('select', implode(' ', $classesForSelectTag)) . ($size ? ' size="' . $size . '"' : '') . ' onchange="' . htmlspecialchars($sOnChange) . '"' . $PA['onFocus'] . $disabled . '>';
2191 $item .= implode('', $opt);
2192 $item .= '</select>';
2193 // Create icon table:
2194 if (count($selicons) && !$config['noIconsBelowSelect']) {
2195 $item .= '<table border="0" cellpadding="0" cellspacing="0" class="typo3-TCEforms-selectIcons">';
2196 $selicon_cols = (int)$config['selicon_cols'];
2197 if (!$selicon_cols) {
2198 $selicon_cols = count($selicons);
2199 }
2200 $sR = ceil(count($selicons) / $selicon_cols);
2201 $selicons = array_pad($selicons, $sR * $selicon_cols, '');
2202 for ($sa = 0; $sa < $sR; $sa++) {
2203 $item .= '<tr>';
2204 for ($sb = 0; $sb < $selicon_cols; $sb++) {
2205 $sk = $sa * $selicon_cols + $sb;
2206 $imgN = 'selIcon_' . $table . '_' . $row['uid'] . '_' . $field . '_' . $selicons[$sk][1];
2207 $imgS = $selicons[$sk][2] ? $this->backPath . 'gfx/content_selected.gif' : 'clear.gif';
2208 $item .= '<td><img name="' . htmlspecialchars($imgN) . '" src="' . $imgS . '" width="7" height="10" alt="" /></td>';
2209 $item .= '<td>' . $selicons[$sk][0] . '</td>';
2210 }
2211 $item .= '</tr>';
2212 }
2213 $item .= '</table>';
2214 }
2215 return $item;
2216 }
2217
2218 /**
2219 * Creates a checkbox list (renderMode = "checkbox")
2220 * (Render function for getSingleField_typeSelect())
2221 *
2222 * @param string $table See getSingleField_typeSelect()
2223 * @param string $field See getSingleField_typeSelect()
2224 * @param array $row See getSingleField_typeSelect()
2225 * @param array $PA See getSingleField_typeSelect()
2226 * @param array $config (Redundant) content of $PA['fieldConf']['config'] (for convenience)
2227 * @param array $selItems Items available for selection
2228 * @param string $nMV_label Label for no-matching-value
2229 * @return string The HTML code for the item
2230 * @see getSingleField_typeSelect()
2231 * @todo Define visibility
2232 */
2233 public function getSingleField_typeSelect_checkbox($table, $field, $row, &$PA, $config, $selItems, $nMV_label) {
2234 if (empty($selItems)) {
2235 return '';
2236 }
2237 // Get values in an array (and make unique, which is fine because there can be no duplicates anyway):
2238 $itemArray = array_flip($this->extractValuesOnlyFromValueLabelList($PA['itemFormElValue']));
2239 $item = '';
2240 $disabled = '';
2241 if ($this->renderReadonly || $config['readOnly']) {
2242 $disabled = ' disabled="disabled"';
2243 }
2244 // Traverse the Array of selector box items:
2245 $tRows = array();
2246 $c = 0;
2247 $setAll = array();
2248 $unSetAll = array();
2249 $restoreCmd = array();
2250 $sOnChange = '';
2251 if (!$disabled) {
2252 $sOnChange = implode('', $PA['fieldChangeFunc']);
2253 // Used to accumulate the JS needed to restore the original selection.
2254 foreach ($selItems as $p) {
2255 // Non-selectable element:
2256 if ($p[1] === '--div--') {
2257 $selIcon = '';
2258 if (isset($p[2]) && $p[2] != 'empty-emtpy') {
2259 $selIcon = $this->getIconHtml($p[2]);
2260 }
2261 $tRows[] = '
2262 <tr class="c-header">
2263 <td colspan="3">' . $selIcon . htmlspecialchars($p[0]) . '</td>
2264 </tr>';
2265 } else {
2266 // Selected or not by default:
2267 $sM = '';
2268 if (isset($itemArray[$p[1]])) {
2269 $sM = ' checked="checked"';
2270 unset($itemArray[$p[1]]);
2271 }
2272 // Icon:
2273 if (!empty($p[2])) {
2274 $selIcon = $this->getIconHtml($p[2]);
2275 } else {
2276 $selIcon = IconUtility::getSpriteIcon('empty-empty');
2277 }
2278 // Compile row:
2279 $rowId = uniqid('select_checkbox_row_');
2280 $onClickCell = $this->elName(($PA['itemFormElName'] . '[' . $c . ']')) . '.checked=!' . $this->elName(($PA['itemFormElName'] . '[' . $c . ']')) . '.checked;';
2281 $onClick = 'this.attributes.getNamedItem("class").nodeValue = ' . $this->elName(($PA['itemFormElName'] . '[' . $c . ']')) . '.checked ? "c-selectedItem" : "c-unselectedItem";';
2282 $setAll[] = $this->elName(($PA['itemFormElName'] . '[' . $c . ']')) . '.checked=1;';
2283 $setAll[] .= '$(\'' . $rowId . '\').removeClassName(\'c-unselectedItem\');$(\'' . $rowId . '\').addClassName(\'c-selectedItem\');';
2284 $unSetAll[] = $this->elName(($PA['itemFormElName'] . '[' . $c . ']')) . '.checked=0;';
2285 $unSetAll[] .= '$(\'' . $rowId . '\').removeClassName(\'c-selectedItem\');$(\'' . $rowId . '\').addClassName(\'c-unselectedItem\');';
2286 $restoreCmd[] = $this->elName(($PA['itemFormElName'] . '[' . $c . ']')) . '.checked=' . ($sM ? 1 : 0) . ';' . '$(\'' . $rowId . '\').removeClassName(\'c-selectedItem\');$(\'' . $rowId . '\').removeClassName(\'c-unselectedItem\');' . '$(\'' . $rowId . '\').addClassName(\'c-' . ($sM ? '' : 'un') . 'selectedItem\');';
2287 // Check if some help text is available
2288 // Since TYPO3 4.5 help text is expected to be an associative array
2289 // with two key, "title" and "description"
2290 // For the sake of backwards compatibility, we test if the help text
2291 // is a string and use it as a description (this could happen if items
2292 // are modified with an itemProcFunc)
2293 $hasHelp = FALSE;
2294 $help = '';
2295 $helpArray = array();
2296 if (is_array($p[3]) && count($p[3]) > 0 || !empty($p[3])) {
2297 $hasHelp = TRUE;
2298 if (is_array($p[3])) {
2299 $helpArray = $p[3];
2300 } else {
2301 $helpArray['description'] = $p[3];
2302 }
2303 }
2304 $label = htmlspecialchars($p[0], ENT_COMPAT, 'UTF-8', FALSE);
2305 if ($hasHelp) {
2306 $help = BackendUtility::wrapInHelp('', '', '', $helpArray);
2307 }
2308 $tRows[] = '
2309 <tr id="' . $rowId . '" class="' . ($sM ? 'c-selectedItem' : 'c-unselectedItem')
2310 . '" onclick="' . htmlspecialchars($onClick) . '" style="cursor: pointer;">
2311 <td class="c-checkbox"><input type="checkbox"' . $this->insertDefStyle('check')
2312 . ' name="' . htmlspecialchars(($PA['itemFormElName'] . '[' . $c . ']'))
2313 . '" value="' . htmlspecialchars($p[1]) . '"' . $sM . ' onclick="' . htmlspecialchars($sOnChange)
2314 . '"' . $PA['onFocus'] . ' /></td>
2315 <td class="c-labelCell" onclick="' . htmlspecialchars($onClickCell) . '">' . $selIcon . $label . '</td>
2316 <td class="c-descr" onclick="' . htmlspecialchars($onClickCell) . '">' . (empty($help) ? '' : $help) . '</td>
2317 </tr>';
2318 $c++;
2319 }
2320 }
2321 }
2322 // Remaining values (invalid):
2323 if (count($itemArray) && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
2324 foreach ($itemArray as $theNoMatchValue => $temp) {
2325 // Compile <checkboxes> tag:
2326 array_unshift($tRows, '
2327 <tr class="c-invalidItem">
2328 <td class="c-checkbox"><input type="checkbox"' . $this->insertDefStyle('check')
2329 . ' name="' . htmlspecialchars(($PA['itemFormElName'] . '[' . $c . ']'))
2330 . '" value="' . htmlspecialchars($theNoMatchValue) . '" checked="checked" onclick="' . htmlspecialchars($sOnChange) . '"'
2331 . $PA['onFocus'] . $disabled . ' /></td>
2332 <td class="c-labelCell">' . htmlspecialchars(@sprintf($nMV_label, $theNoMatchValue), ENT_COMPAT, 'UTF-8', FALSE) . '</td><td>&nbsp;</td>
2333 </tr>');
2334 $c++;
2335 }
2336 }
2337 // Add an empty hidden field which will send a blank value if all items are unselected.
2338 $item .= '<input type="hidden" class="select-checkbox" name="' . htmlspecialchars($PA['itemFormElName']) . '" value="" />';
2339 // Remaining checkboxes will get their set-all link:
2340 $tableHead = '';
2341 if (count($setAll)) {
2342 $tableHead = '<thead>
2343 <tr class="c-header-checkbox-controls t3-row-header">
2344 <td class="c-checkbox">
2345 <input type="checkbox" class="checkbox" onclick="if (checked) {' . htmlspecialchars(implode('', $setAll) . '} else {' . implode('', $unSetAll) . '}') . '">
2346 </td>
2347 <td colspan="2">
2348 </td>
2349 </tr></thead>';
2350 }
2351 // Implode rows in table:
2352 $item .= '
2353 <table border="0" cellpadding="0" cellspacing="0" class="typo3-TCEforms-select-checkbox">' . $tableHead . '<tbody>' . implode('', $tRows) . '</tbody>
2354 </table>
2355 ';
2356 // Add revert icon
2357 if (!empty($restoreCmd)) {
2358 $item .= '<a href="#" onclick="' . implode('', $restoreCmd) . ' return false;' . '">'
2359 . IconUtility::getSpriteIcon('actions-edit-undo', array('title' => htmlspecialchars($this->getLL('l_revertSelection')))) . '</a>';
2360 }
2361 return $item;
2362 }
2363
2364 /**
2365 * Creates a selectorbox list (renderMode = "singlebox")
2366 * (Render function for getSingleField_typeSelect())
2367 *
2368 * @param string $table See getSingleField_typeSelect()
2369 * @param string $field See getSingleField_typeSelect()
2370 * @param array $row See getSingleField_typeSelect()
2371 * @param array $PA See getSingleField_typeSelect()
2372 * @param array $config (Redundant) content of $PA['fieldConf']['config'] (for convenience)
2373 * @param array $selItems Items available for selection
2374 * @param string $nMV_label Label for no-matching-value
2375 * @return string The HTML code for the item
2376 * @see getSingleField_typeSelect()
2377 * @todo Define visibility
2378 */
2379 public function getSingleField_typeSelect_singlebox($table, $field, $row, &$PA, $config, $selItems, $nMV_label) {
2380 // Get values in an array (and make unique, which is fine because there can be no duplicates anyway):
2381 $itemArray = array_flip($this->extractValuesOnlyFromValueLabelList($PA['itemFormElValue']));
2382 $item = '';
2383 $disabled = '';
2384 if ($this->renderReadonly || $config['readOnly']) {
2385 $disabled = ' disabled="disabled"';
2386 }
2387 // Traverse the Array of selector box items:
2388 $opt = array();
2389 // Used to accumulate the JS needed to restore the original selection.
2390 $restoreCmd = array();
2391 $c = 0;
2392 foreach ($selItems as $p) {
2393 // Selected or not by default:
2394 $sM = '';
2395 if (isset($itemArray[$p[1]])) {
2396 $sM = ' selected="selected"';
2397 $restoreCmd[] = $this->elName(($PA['itemFormElName'] . '[]')) . '.options[' . $c . '].selected=1;';
2398 unset($itemArray[$p[1]]);
2399 }
2400 // Non-selectable element:
2401 $nonSel = '';
2402 if ((string) $p[1] === '--div--') {
2403 $nonSel = ' onclick="this.selected=0;" class="c-divider"';
2404 }
2405 // Icon style for option tag:
2406 $styleAttrValue = '';
2407 if ($config['iconsInOptionTags']) {
2408 $styleAttrValue = $this->optionTagStyle($p[2]);
2409 }
2410 // Compile <option> tag:
2411 $opt[] = '<option value="' . htmlspecialchars($p[1]) . '"' . $sM . $nonSel
2412 . ($styleAttrValue ? ' style="' . htmlspecialchars($styleAttrValue) . '"' : '') . '>'
2413 . htmlspecialchars($p[0], ENT_COMPAT, 'UTF-8', FALSE) . '</option>';
2414 $c++;
2415 }
2416 // Remaining values:
2417 if (count($itemArray) && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
2418 foreach ($itemArray as $theNoMatchValue => $temp) {
2419 // Compile <option> tag:
2420 array_unshift($opt, '<option value="' . htmlspecialchars($theNoMatchValue) . '" selected="selected">'
2421 . htmlspecialchars(@sprintf($nMV_label, $theNoMatchValue), ENT_COMPAT, 'UTF-8', FALSE) . '</option>');
2422 }
2423 }
2424 // Compile selector box:
2425 $sOnChange = implode('', $PA['fieldChangeFunc']);
2426 $selector_itemListStyle = isset($config['itemListStyle'])
2427 ? ' style="' . htmlspecialchars($config['itemListStyle']) . '"'
2428 : ' style="' . $this->defaultMultipleSelectorStyle . '"';
2429 $size = (int)$config['size'];
2430 $cssPrefix = $size === 1 ? 'tceforms-select' : 'tceforms-multiselect';
2431 $size = $config['autoSizeMax']
2432 ? MathUtility::forceIntegerInRange(count($selItems) + 1, MathUtility::forceIntegerInRange($size, 1), $config['autoSizeMax'])
2433 : $size;
2434 $selectBox = '<select id="' . uniqid($cssPrefix) . '" name="' . $PA['itemFormElName'] . '[]"'
2435 . $this->insertDefStyle('select', $cssPrefix) . ($size ? ' size="' . $size . '"' : '')
2436 . ' multiple="multiple" onchange="' . htmlspecialchars($sOnChange) . '"' . $PA['onFocus']
2437 . $selector_itemListStyle . $disabled . '>
2438 ' . implode('
2439 ', $opt) . '
2440 </select>';
2441 // Add an empty hidden field which will send a blank value if all items are unselected.
2442 if (!$disabled) {
2443 $item .= '<input type="hidden" name="' . htmlspecialchars($PA['itemFormElName']) . '" value="" />';
2444 }
2445 // Put it all into a table:
2446 $onClick = htmlspecialchars($this->elName(($PA['itemFormElName'] . '[]')) . '.selectedIndex=-1;' . implode('', $restoreCmd) . ' return false;');
2447 $item .= '
2448 <table border="0" cellspacing="0" cellpadding="0" width="1" class="typo3-TCEforms-select-singlebox">
2449 <tr>
2450 <td>
2451 ' . $selectBox . '
2452 <br/>
2453 <em>' . htmlspecialchars($this->getLL('l_holdDownCTRL')) . '</em>
2454 </td>
2455 <td valign="top">
2456 <a href="#" onclick="' . $onClick . '" title="' . htmlspecialchars($this->getLL('l_revertSelection')) . '">'
2457 . IconUtility::getSpriteIcon('actions-edit-undo') . '</a>
2458 </td>
2459 </tr>
2460 </table>
2461 ';
2462 return $item;
2463 }
2464
2465 /**
2466 * Creates a multiple-selector box (two boxes, side-by-side)
2467 * (Render function for getSingleField_typeSelect())
2468 *
2469 * @param string $table See getSingleField_typeSelect()
2470 * @param string $field See getSingleField_typeSelect()
2471 * @param array $row See getSingleField_typeSelect()
2472 * @param array $PA See getSingleField_typeSelect()
2473 * @param array $config (Redundant) content of $PA['fieldConf']['config'] (for convenience)
2474 * @param array $selItems Items available for selection
2475 * @param string $nMV_label Label for no-matching-value
2476 * @return string The HTML code for the item
2477 * @see getSingleField_typeSelect()
2478 * @todo Define visibility
2479 */
2480 public function getSingleField_typeSelect_multiple($table, $field, $row, &$PA, $config, $selItems, $nMV_label) {
2481 $item = '';
2482 $disabled = '';
2483 if ($this->renderReadonly || $config['readOnly']) {
2484 $disabled = ' disabled="disabled"';
2485 }
2486 // Setting this hidden field (as a flag that JavaScript can read out)
2487 if (!$disabled) {
2488 $item .= '<input type="hidden" name="' . $PA['itemFormElName'] . '_mul" value="' . ($config['multiple'] ? 1 : 0) . '" />';
2489 }
2490 // Set max and min items:
2491 $maxitems = MathUtility::forceIntegerInRange($config['maxitems'], 0);
2492 if (!$maxitems) {
2493 $maxitems = 100000;
2494 }
2495 $minitems = MathUtility::forceIntegerInRange($config['minitems'], 0);
2496 // Register the required number of elements:
2497 $this->registerRequiredProperty('range', $PA['itemFormElName'], array($minitems, $maxitems, 'imgName' => $table . '_' . $row['uid'] . '_' . $field));
2498 // Get "removeItems":
2499 $removeItems = GeneralUtility::trimExplode(',', $PA['fieldTSConfig']['removeItems'], TRUE);
2500 // Get the array with selected items:
2501 $itemArray = GeneralUtility::trimExplode(',', $PA['itemFormElValue'], TRUE);
2502
2503 // Possibly filter some items:
2504 $itemArray = GeneralUtility::keepItemsInArray(
2505 $itemArray,
2506 $PA['fieldTSConfig']['keepItems'],
2507 function ($value) {
2508 $parts = explode('|', $value, 2);
2509 return rawurldecode($parts[0]);
2510 }
2511 );
2512
2513 // Perform modification of the selected items array:
2514 foreach ($itemArray as $tk => $tv) {
2515 $tvP = explode('|', $tv, 2);
2516 $evalValue = $tvP[0];
2517 $isRemoved = in_array($evalValue, $removeItems)
2518 || $config['form_type'] == 'select' && $config['authMode']
2519 && !$this->getBackendUserAuthentication()->checkAuthMode($table, $field, $evalValue, $config['authMode']);
2520 if ($isRemoved && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
2521 $tvP[1] = rawurlencode(@sprintf($nMV_label, $evalValue));
2522 } elseif (isset($PA['fieldTSConfig']['altLabels.'][$evalValue])) {
2523 $tvP[1] = rawurlencode($this->sL($PA['fieldTSConfig']['altLabels.'][$evalValue]));
2524 }
2525 if ($tvP[1] == '') {
2526 // Case: flexform, default values supplied, no label provided (bug #9795)
2527 foreach ($selItems as $selItem) {
2528 if ($selItem[1] == $tvP[0]) {
2529 $tvP[1] = html_entity_decode($selItem[0]);
2530 break;
2531 }
2532 }
2533 }
2534 $itemArray[$tk] = implode('|', $tvP);
2535 }
2536 $itemsToSelect = '';
2537 $filterTextfield = '';
2538 $filterSelectbox = '';
2539 $size = 0;
2540 if (!$disabled) {
2541 // Create option tags:
2542 $opt = array();
2543 $styleAttrValue = '';
2544 foreach ($selItems as $p) {
2545 if ($config['iconsInOptionTags']) {
2546 $styleAttrValue = $this->optionTagStyle($p[2]);
2547 }
2548 $opt[] = '<option value="' . htmlspecialchars($p[1]) . '"'
2549 . ($styleAttrValue ? ' style="' . htmlspecialchars($styleAttrValue) . '"' : '')
2550 . ' title="' . $p[0] . '">' . $p[0] . '</option>';
2551 }
2552 // Put together the selector box:
2553 $selector_itemListStyle = isset($config['itemListStyle'])
2554 ? ' style="' . htmlspecialchars($config['itemListStyle']) . '"'
2555 : ' style="' . $this->defaultMultipleSelectorStyle . '"';
2556 $size = (int)$config['size'];
2557 $size = $config['autoSizeMax']
2558 ? MathUtility::forceIntegerInRange(count($itemArray) + 1, MathUtility::forceIntegerInRange($size, 1), $config['autoSizeMax'])
2559 : $size;
2560 $sOnChange = implode('', $PA['fieldChangeFunc']);
2561
2562 $multiSelectId = uniqid('tceforms-multiselect-');
2563 $itemsToSelect = '
2564 <select data-relatedfieldname="' . htmlspecialchars($PA['itemFormElName']) . '" data-exclusivevalues="'
2565 . htmlspecialchars($config['exclusiveKeys']) . '" id="' . $multiSelectId . '" name="' . $PA['itemFormElName'] . '_sel"'
2566 . $this->insertDefStyle('select', 'tceforms-multiselect tceforms-itemstoselect t3-form-select-itemstoselect')
2567 . ($size ? ' size="' . $size . '"' : '') . ' onchange="' . htmlspecialchars($sOnChange) . '"'
2568 . $PA['onFocus'] . $selector_itemListStyle . '>
2569 ' . implode('
2570 ', $opt) . '
2571 </select>';
2572
2573 if ($config['enableMultiSelectFilterTextfield'] || $config['multiSelectFilterItems']) {
2574 $this->multiSelectFilterCount++;
2575 $jsSelectBoxFilterName = str_replace(' ', '', ucwords(str_replace('-', ' ', GeneralUtility::strtolower($multiSelectId))));
2576 $this->additionalJS_post[] = '
2577 var '. $jsSelectBoxFilterName . ' = new TCEForms.SelectBoxFilter("' . $multiSelectId . '");
2578 ';
2579 }
2580
2581 if ($config['enableMultiSelectFilterTextfield']) {
2582 // add input field for filter
2583 $filterTextfield = '<input class="typo3-TCEforms-suggest-search typo3-TCEforms-multiselect-filter" id="'
2584 . $multiSelectId . '_filtertextfield" value="" style="width: 104px;" />';
2585 }
2586
2587 if (isset($config['multiSelectFilterItems']) && is_array($config['multiSelectFilterItems']) && count($config['multiSelectFilterItems']) > 1) {
2588 $filterDropDownOptions = array();
2589 foreach ($config['multiSelectFilterItems'] as $optionElement) {
2590 $optionValue = $this->sL(isset($optionElement[1]) && $optionElement[1] != '' ? $optionElement[1]
2591 : $optionElement[0]);
2592 $filterDropDownOptions[] = '<option value="' . htmlspecialchars($this->sL($optionElement[0])) . '">'
2593 . htmlspecialchars($optionValue) . '</option>';
2594 }
2595 $filterSelectbox = '
2596 <select id="' . $multiSelectId . '_filterdropdown">
2597 ' . implode('
2598 ', $filterDropDownOptions) . '
2599 </select>';
2600 }
2601 }
2602 // Pass to "dbFileIcons" function:
2603 $params = array(
2604 'size' => $size,
2605 'autoSizeMax' => MathUtility::forceIntegerInRange($config['autoSizeMax'], 0),
2606 'style' => isset($config['selectedListStyle'])
2607 ? ' style="' . htmlspecialchars($config['selectedListStyle']) . '"'
2608 : ' style="' . $this->defaultMultipleSelectorStyle . '"',
2609 'dontShowMoveIcons' => $maxitems <= 1,
2610 'maxitems' => $maxitems,
2611 'info' => '',
2612 'headers' => array(
2613 'selector' => $this->getLL('l_selected') . ':<br />',
2614 'items' => $this->getLL('l_items') . ': ' . $filterSelectbox . $filterTextfield . '<br />'
2615 ),
2616 'noBrowser' => 1,
2617 'thumbnails' => $itemsToSelect,
2618 'readOnly' => $disabled
2619 );
2620 $item .= $this->dbFileIcons($PA['itemFormElName'], '', '', $itemArray, '', $params, $PA['onFocus']);
2621 return $item;
2622 }
2623
2624 /**
2625 * Generation of TCEform elements of the type "group"
2626 * This will render a selectorbox into which elements from either the file system or database can be inserted. Relations.
2627 *
2628 * @param string $table The table name of the record
2629 * @param string $field The field name which this element is supposed to edit
2630 * @param array $row The record data array where the value(s) for the field can be found
2631 * @param array $PA An array with additional configuration options.
2632 * @return string The HTML code for the TCEform field
2633 * @todo Define visibility
2634 */
2635 public function getSingleField_typeGroup($table, $field, $row, &$PA) {
2636 // Init:
2637 $config = $PA['fieldConf']['config'];
2638 $show_thumbs = $config['show_thumbs'];
2639 $size = isset($config['size']) ? (int)$config['size'] : 5;
2640 $maxitems = MathUtility::forceIntegerInRange($config['maxitems'], 0);
2641 if (!$maxitems) {
2642 $maxitems = 100000;
2643 }
2644 $minitems = MathUtility::forceIntegerInRange($config['minitems'], 0);
2645 $allowed = trim($config['allowed']);
2646 $disallowed = trim($config['disallowed']);
2647 $item = '';
2648 $disabled = '';
2649 if ($this->renderReadonly || $config['readOnly']) {
2650 $disabled = ' disabled="disabled"';
2651 }
2652 $item .= '<input type="hidden" name="' . $PA['itemFormElName'] . '_mul" value="' . ($config['multiple'] ? 1 : 0) . '"' . $disabled . ' />';
2653 $this->registerRequiredProperty('range', $PA['itemFormElName'], array($minitems, $maxitems, 'imgName' => $table . '_' . $row['uid'] . '_' . $field));
2654 $info = '';
2655 // "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist.
2656 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
2657 $PA['itemFormElID_file'] = $PA['itemFormElID'] . '_files';
2658 // whether the list and delete controls should be disabled
2659 $noList = isset($config['disable_controls']) && GeneralUtility::inList($config['disable_controls'], 'list');
2660 $noDelete = isset($config['disable_controls']) && GeneralUtility::inList($config['disable_controls'], 'delete');
2661 // if maxitems==1 then automatically replace the current item (in list and file selector)
2662 if ($maxitems === 1) {
2663 $this->additionalJS_post[] = 'TBE_EDITOR.clearBeforeSettingFormValueFromBrowseWin[\'' . $PA['itemFormElName'] . '\'] = {
2664 itemFormElID_file: \'' . $PA['itemFormElID_file'] . '\'
2665 }';
2666 $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = 'setFormValueManipulate(\'' . $PA['itemFormElName']
2667 . '\', \'Remove\'); ' . $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'];
2668 } elseif ($noList) {
2669 // If the list controls have been removed and the maximum number is reached, remove the first entry to avoid "write once" field
2670 $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = 'setFormValueManipulate(\'' . $PA['itemFormElName']
2671 . '\', \'RemoveFirstIfFull\', \'' . $maxitems . '\'); ' . $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'];
2672 }
2673 // Acting according to either "file" or "db" type:
2674 switch ((string) $config['internal_type']) {
2675 case 'file_reference':
2676 $config['uploadfolder'] = '';
2677 // Fall through
2678 case 'file':
2679 // Creating string showing allowed types:
2680 $tempFT = GeneralUtility::trimExplode(',', $allowed, TRUE);
2681 if (!count($tempFT)) {
2682 $info .= '*';
2683 }
2684 foreach ($tempFT as $ext) {