TYPO3 CMS  TYPO3_7-6
SelectMultipleSideBySideElement.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
22 
29 {
35  public function render()
36  {
37  $table = $this->data['tableName'];
38  $field = $this->data['fieldName'];
39  $parameterArray = $this->data['parameterArray'];
40  // Field configuration from TCA:
41  $config = $parameterArray['fieldConf']['config'];
42 
43  // Creating the label for the "No Matching Value" entry.
44  $noMatchingLabel = isset($parameterArray['fieldTSConfig']['noMatchingValue_label'])
45  ? $this->getLanguageService()->sL(trim($parameterArray['fieldTSConfig']['noMatchingValue_label']))
46  : '[ ' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.noMatchingValue') . ' ]';
47 
48  $selItems = $config['items'];
49  $html = '';
50  $disabled = '';
51  if ($config['readOnly']) {
52  $disabled = ' disabled="disabled"';
53  }
54  // Setting this hidden field (as a flag that JavaScript can read out)
55  if (!$disabled) {
56  $html .= '<input type="hidden" data-formengine-input-name="' . htmlspecialchars($parameterArray['itemFormElName']) . '" value="' . ($config['multiple'] ? 1 : 0) . '" />';
57  }
58  // Set max and min items:
59  $maxitems = MathUtility::forceIntegerInRange($config['maxitems'], 0);
60  if (!$maxitems) {
61  $maxitems = 100000;
62  }
63  // Get the array with selected items:
64  $itemsArray = $parameterArray['itemFormElValue'] ?: [];
65  if (!is_array($itemsArray)) {
66  $itemsArray = GeneralUtility::trimExplode(',', $itemsArray, true);
67  }
68 
69  // Perform modification of the selected items array:
70  foreach ($itemsArray as $itemNumber => $itemValue) {
71  $itemArray = [
72  0 => $itemValue,
73  1 => '',
74  ];
75 
76  if (isset($parameterArray['fieldTSConfig']['altIcons.'][$itemValue])) {
77  $itemArray[2] = $parameterArray['fieldTSConfig']['altIcons.'][$itemValue];
78  }
79 
80  foreach ($selItems as $selItem) {
81  if ($selItem[1] == $itemValue) {
82  $itemArray[1] = $selItem[0];
83  break;
84  }
85  }
86  $itemsArray[$itemNumber] = implode('|', $itemArray);
87  }
88 
89  // size must be at least two, as there are always maxitems > 1 (see parent function)
90  if (isset($config['size'])) {
91  $size = (int)$config['size'];
92  } else {
93  $size = 2;
94  }
95  $size = $config['autoSizeMax'] ? MathUtility::forceIntegerInRange(count($itemsArray) + 1, MathUtility::forceIntegerInRange($size, 1), $config['autoSizeMax']) : $size;
96  $allowMultiple = !empty($config['multiple']);
97 
98  $itemsToSelect = [];
99  $filterTextfield = [];
100  $filterSelectbox = '';
101  if (!$disabled) {
102  // Create option tags:
103  $opt = [];
104  foreach ($selItems as $p) {
105  $disabledAttr = '';
106  $classAttr = '';
107  if (!$allowMultiple && in_array((string)$p[1], $parameterArray['itemFormElValue'], true)) {
108  $disabledAttr = ' disabled="disabled"';
109  $classAttr = ' class="hidden"';
110  }
111  $opt[] = '<option value="' . htmlspecialchars($p[1]) . '" title="' . htmlspecialchars($p[0]) . '"' . $classAttr . $disabledAttr . '>' . htmlspecialchars($p[0]) . '</option>';
112  }
113  // Put together the selector box:
114  $selector_itemListStyle = isset($config['itemListStyle'])
115  ? ' style="' . htmlspecialchars($config['itemListStyle']) . '"'
116  : '';
117  $sOnChange = implode('', $parameterArray['fieldChangeFunc']);
118 
119  $multiSelectId = StringUtility::getUniqueId('tceforms-multiselect-');
120  $itemsToSelect[] = '<select data-relatedfieldname="' . htmlspecialchars($parameterArray['itemFormElName']) . '" '
121  . 'data-exclusivevalues="' . htmlspecialchars($config['exclusiveKeys']) . '" '
122  . 'id="' . $multiSelectId . '" '
123  . 'data-formengine-input-name="' . htmlspecialchars($parameterArray['itemFormElName']) . '" '
124  . 'class="form-control t3js-formengine-select-itemstoselect" '
125  . ($size ? ' size="' . $size . '" ' : '')
126  . 'onchange="' . htmlspecialchars($sOnChange) . '" '
127  . $parameterArray['onFocus']
128  . $this->getValidationDataAsDataAttribute($config)
129  . $selector_itemListStyle
130  . '>';
131  $itemsToSelect[] = implode(LF, $opt);
132  $itemsToSelect[] = '</select>';
133 
134  // enable filter functionality via a text field
135  if ($config['enableMultiSelectFilterTextfield']) {
136  $filterTextfield[] = '<span class="input-group input-group-sm">';
137  $filterTextfield[] = '<span class="input-group-addon">';
138  $filterTextfield[] = '<span class="fa fa-filter"></span>';
139  $filterTextfield[] = '</span>';
140  $filterTextfield[] = '<input class="t3js-formengine-multiselect-filter-textfield form-control" value="">';
141  $filterTextfield[] = '</span>';
142  }
143 
144  // enable filter functionality via a select
145  if (isset($config['multiSelectFilterItems']) && is_array($config['multiSelectFilterItems']) && count($config['multiSelectFilterItems']) > 1) {
146  $filterDropDownOptions = [];
147  foreach ($config['multiSelectFilterItems'] as $optionElement) {
148  $optionValue = $this->getLanguageService()->sL(isset($optionElement[1]) && trim($optionElement[1]) !== '' ? trim($optionElement[1])
149  : trim($optionElement[0]));
150  $filterDropDownOptions[] = '<option value="' . htmlspecialchars($this->getLanguageService()->sL(trim($optionElement[0]))) . '">'
151  . htmlspecialchars($optionValue) . '</option>';
152  }
153  $filterSelectbox = '<select class="form-control input-sm t3js-formengine-multiselect-filter-dropdown">'
154  . implode(LF, $filterDropDownOptions) . '</select>';
155  }
156  }
157 
158  if (!empty(trim($filterSelectbox)) && !empty($filterTextfield)) {
159  $filterSelectbox = '<div class="form-multigroup-item form-multigroup-element">' . $filterSelectbox . '</div>';
160  $filterTextfield = '<div class="form-multigroup-item form-multigroup-element">' . implode(LF, $filterTextfield) . '</div>';
161  $selectBoxFilterContents = '<div class="t3js-formengine-multiselect-filter-container form-multigroup-wrap">' . $filterSelectbox . $filterTextfield . '</div>';
162  } else {
163  $selectBoxFilterContents = trim($filterSelectbox . ' ' . implode(LF, $filterTextfield));
164  }
165 
166  // Pass to "dbFileIcons" function:
167  $params = [
168  'size' => $size,
169  'autoSizeMax' => MathUtility::forceIntegerInRange($config['autoSizeMax'], 0),
170  'style' => isset($config['selectedListStyle'])
171  ? ' style="' . htmlspecialchars($config['selectedListStyle']) . '"'
172  : '',
173  'dontShowMoveIcons' => $maxitems <= 1,
174  'maxitems' => $maxitems,
175  'info' => '',
176  'headers' => [
177  'selector' => $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.selected'),
178  'items' => $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.items'),
179  'selectorbox' => $selectBoxFilterContents,
180  ],
181  'noBrowser' => 1,
182  'rightbox' => implode(LF, $itemsToSelect),
183  'readOnly' => $disabled
184  ];
185  $html .= $this->dbFileIcons($parameterArray['itemFormElName'], '', '', $itemsArray, '', $params, $parameterArray['onFocus']);
186 
187  // Wizards:
188  if (!$disabled) {
189  $html = $this->renderWizards(
190  [$html],
191  $config['wizards'],
192  $table,
193  $this->data['databaseRow'],
194  $field,
195  $parameterArray,
196  $parameterArray['itemFormElName'],
197  BackendUtility::getSpecConfParts($parameterArray['fieldConf']['defaultExtras'])
198  );
199  }
200 
201  $resultArray = $this->initializeResultArray();
202  $resultArray['html'] = $html;
203  return $resultArray;
204  }
205 
209  protected function getBackendUserAuthentication()
210  {
211  return $GLOBALS['BE_USER'];
212  }
213 }
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
getValidationDataAsDataAttribute(array $config)
static getSpecConfParts($defaultExtrasString, $_='')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']