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