TYPO3  7.6
SelectMultipleSideBySideElement.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Form\Element;
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 
21 
28 {
34  public function render()
35  {
36  $table = $this->data['tableName'];
37  $field = $this->data['fieldName'];
38  $parameterArray = $this->data['parameterArray'];
39  // Field configuration from TCA:
40  $config = $parameterArray['fieldConf']['config'];
41 
42  // Creating the label for the "No Matching Value" entry.
43  $noMatchingLabel = isset($parameterArray['fieldTSConfig']['noMatchingValue_label'])
44  ? $this->getLanguageService()->sL(trim($parameterArray['fieldTSConfig']['noMatchingValue_label']))
45  : '[ ' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.noMatchingValue') . ' ]';
46 
47  $selItems = $config['items'];
48  $html = '';
49  $disabled = '';
50  if ($config['readOnly']) {
51  $disabled = ' disabled="disabled"';
52  }
53  // Setting this hidden field (as a flag that JavaScript can read out)
54  if (!$disabled) {
55  $html .= '<input type="hidden" data-formengine-input-name="' . htmlspecialchars($parameterArray['itemFormElName']) . '" value="' . ($config['multiple'] ? 1 : 0) . '" />';
56  }
57  // Set max and min items:
58  $maxitems = MathUtility::forceIntegerInRange($config['maxitems'], 0);
59  if (!$maxitems) {
60  $maxitems = 100000;
61  }
62  // Get the array with selected items:
63  $itemsArray = $parameterArray['itemFormElValue'] ?: [];
64 
65  // Perform modification of the selected items array:
66  foreach ($itemsArray as $itemNumber => $itemValue) {
67  $itemArray = array(
68  0 => $itemValue,
69  1 => '',
70  );
71 
72  if (isset($parameterArray['fieldTSConfig']['altIcons.'][$itemValue])) {
73  $itemArray[2] = $parameterArray['fieldTSConfig']['altIcons.'][$itemValue];
74  }
75 
76  foreach ($selItems as $selItem) {
77  if ($selItem[1] == $itemValue) {
78  $itemArray[1] = $selItem[0];
79  break;
80  }
81  }
82  $itemsArray[$itemNumber] = implode('|', $itemArray);
83  }
84 
85  // size must be at least two, as there are always maxitems > 1 (see parent function)
86  if (isset($config['size'])) {
87  $size = (int)$config['size'];
88  } else {
89  $size = 2;
90  }
91  $size = $config['autoSizeMax'] ? MathUtility::forceIntegerInRange(count($itemsArray) + 1, MathUtility::forceIntegerInRange($size, 1), $config['autoSizeMax']) : $size;
92 
93  $itemsToSelect = [];
94  $filterTextfield = [];
95  $filterSelectbox = '';
96  if (!$disabled) {
97  // Create option tags:
98  $opt = array();
99  foreach ($selItems as $p) {
100  $opt[] = '<option value="' . htmlspecialchars($p[1]) . '" title="' . $p[0] . '">' . $p[0] . '</option>';
101  }
102  // Put together the selector box:
103  $selector_itemListStyle = isset($config['itemListStyle'])
104  ? ' style="' . htmlspecialchars($config['itemListStyle']) . '"'
105  : '';
106  $sOnChange = implode('', $parameterArray['fieldChangeFunc']);
107 
108  $multiSelectId = StringUtility::getUniqueId('tceforms-multiselect-');
109  $itemsToSelect[] = '<select data-relatedfieldname="' . htmlspecialchars($parameterArray['itemFormElName']) . '" '
110  . 'data-exclusivevalues="' . htmlspecialchars($config['exclusiveKeys']) . '" '
111  . 'id="' . $multiSelectId . '" '
112  . 'data-formengine-input-name="' . htmlspecialchars($parameterArray['itemFormElName']) . '" '
113  . 'class="form-control t3js-formengine-select-itemstoselect" '
114  . ($size ? ' size="' . $size . '" ' : '')
115  . 'onchange="' . htmlspecialchars($sOnChange) . '" '
116  . $parameterArray['onFocus']
117  . $this->getValidationDataAsDataAttribute($config)
118  . $selector_itemListStyle
119  . '>';
120  $itemsToSelect[] = implode(LF, $opt);
121  $itemsToSelect[] = '</select>';
122 
123  // enable filter functionality via a text field
124  if ($config['enableMultiSelectFilterTextfield']) {
125  $filterTextfield[] = '<span class="input-group input-group-sm">';
126  $filterTextfield[] = '<span class="input-group-addon">';
127  $filterTextfield[] = '<span class="fa fa-filter"></span>';
128  $filterTextfield[] = '</span>';
129  $filterTextfield[] = '<input class="t3js-formengine-multiselect-filter-textfield form-control" value="">';
130  $filterTextfield[] = '</span>';
131  }
132 
133  // enable filter functionality via a select
134  if (isset($config['multiSelectFilterItems']) && is_array($config['multiSelectFilterItems']) && count($config['multiSelectFilterItems']) > 1) {
135  $filterDropDownOptions = array();
136  foreach ($config['multiSelectFilterItems'] as $optionElement) {
137  $optionValue = $this->getLanguageService()->sL(isset($optionElement[1]) && trim($optionElement[1]) !== '' ? trim($optionElement[1])
138  : trim($optionElement[0]));
139  $filterDropDownOptions[] = '<option value="' . htmlspecialchars($this->getLanguageService()->sL(trim($optionElement[0]))) . '">'
140  . htmlspecialchars($optionValue) . '</option>';
141  }
142  $filterSelectbox = '<select class="form-control input-sm t3js-formengine-multiselect-filter-dropdown">'
143  . implode(LF, $filterDropDownOptions) . '</select>';
144  }
145  }
146 
147  if (!empty(trim($filterSelectbox)) && !empty($filterTextfield)) {
148  $filterSelectbox = '<div class="form-multigroup-item form-multigroup-element">' . $filterSelectbox . '</div>';
149  $filterTextfield = '<div class="form-multigroup-item form-multigroup-element">' . implode(LF, $filterTextfield) . '</div>';
150  $selectBoxFilterContents = '<div class="t3js-formengine-multiselect-filter-container form-multigroup-wrap">' . $filterSelectbox . $filterTextfield . '</div>';
151  } else {
152  $selectBoxFilterContents = trim($filterSelectbox . ' ' . implode(LF, $filterTextfield));
153  }
154 
155  // Pass to "dbFileIcons" function:
156  $params = array(
157  'size' => $size,
158  'autoSizeMax' => MathUtility::forceIntegerInRange($config['autoSizeMax'], 0),
159  'style' => isset($config['selectedListStyle'])
160  ? ' style="' . htmlspecialchars($config['selectedListStyle']) . '"'
161  : '',
162  'dontShowMoveIcons' => $maxitems <= 1,
163  'maxitems' => $maxitems,
164  'info' => '',
165  'headers' => array(
166  'selector' => $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.selected'),
167  'items' => $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.items'),
168  'selectorbox' => $selectBoxFilterContents,
169  ),
170  'noBrowser' => 1,
171  'rightbox' => implode(LF, $itemsToSelect),
172  'readOnly' => $disabled
173  );
174  $html .= $this->dbFileIcons($parameterArray['itemFormElName'], '', '', $itemsArray, '', $params, $parameterArray['onFocus']);
175 
176  // Wizards:
177  if (!$disabled) {
178  $html = $this->renderWizards(
179  array($html),
180  $config['wizards'],
181  $table,
182  $this->data['databaseRow'],
183  $field,
184  $parameterArray,
185  $parameterArray['itemFormElName'],
186  BackendUtility::getSpecConfParts($parameterArray['fieldConf']['defaultExtras'])
187  );
188  }
189 
190  $resultArray = $this->initializeResultArray();
191  $resultArray['html'] = $html;
192  return $resultArray;
193  }
194 
198  protected function getBackendUserAuthentication()
199  {
200  return $GLOBALS['BE_USER'];
201  }
202 }