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