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