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