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