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