| Conditions | 28 |
| Paths | > 20000 |
| Total Lines | 245 |
| Code Lines | 203 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 124 | public function render() |
||
| 125 | { |
||
| 126 | $filterTextfield = []; |
||
| 127 | $languageService = $this->getLanguageService(); |
||
| 128 | $resultArray = $this->initializeResultArray(); |
||
| 129 | |||
| 130 | $parameterArray = $this->data['parameterArray']; |
||
| 131 | $config = $parameterArray['fieldConf']['config']; |
||
| 132 | $elementName = $parameterArray['itemFormElName']; |
||
| 133 | |||
| 134 | if ($config['readOnly']) { |
||
| 135 | // Early return for the relatively simple read only case |
||
| 136 | return $this->renderReadOnly(); |
||
| 137 | } |
||
| 138 | |||
| 139 | $possibleItems = $config['items']; |
||
| 140 | $selectedItems = $parameterArray['itemFormElValue'] ?: []; |
||
| 141 | $selectedItemsCount = count($selectedItems); |
||
| 142 | |||
| 143 | $maxItems = $config['maxitems']; |
||
| 144 | $autoSizeMax = MathUtility::forceIntegerInRange($config['autoSizeMax'], 0); |
||
| 145 | $size = 2; |
||
| 146 | if (isset($config['size'])) { |
||
| 147 | $size = (int)$config['size']; |
||
| 148 | } |
||
| 149 | if ($autoSizeMax >= 1) { |
||
| 150 | $size = MathUtility::forceIntegerInRange($selectedItemsCount + 1, MathUtility::forceIntegerInRange($size, 1), $autoSizeMax); |
||
| 151 | } |
||
| 152 | $itemCanBeSelectedMoreThanOnce = !empty($config['multiple']); |
||
| 153 | |||
| 154 | $listOfSelectedValues = []; |
||
| 155 | $selectedItemsHtml = []; |
||
| 156 | foreach ($selectedItems as $itemValue) { |
||
| 157 | foreach ($possibleItems as $possibleItem) { |
||
| 158 | if ($possibleItem[1] == $itemValue) { |
||
| 159 | $title = $possibleItem[0]; |
||
| 160 | $listOfSelectedValues[] = $itemValue; |
||
| 161 | $selectedItemsHtml[] = '<option value="' . htmlspecialchars($itemValue) . '" title="' . htmlspecialchars($title) . '">' . htmlspecialchars($this->appendValueToLabelInDebugMode($title, $itemValue)) . '</option>'; |
||
| 162 | break; |
||
| 163 | } |
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 167 | $selectableItemsHtml = []; |
||
| 168 | foreach ($possibleItems as $possibleItem) { |
||
| 169 | $disabledAttr = ''; |
||
| 170 | $classAttr = ''; |
||
| 171 | if (!$itemCanBeSelectedMoreThanOnce && in_array((string)$possibleItem[1], $selectedItems, true)) { |
||
| 172 | $disabledAttr = ' disabled="disabled"'; |
||
| 173 | $classAttr = ' class="hidden"'; |
||
| 174 | } |
||
| 175 | $selectableItemsHtml[] = |
||
| 176 | '<option value="' |
||
| 177 | . htmlspecialchars($possibleItem[1]) |
||
| 178 | . '" title="' . htmlspecialchars($possibleItem[0]) . '"' |
||
| 179 | . $classAttr . $disabledAttr |
||
| 180 | . '>' |
||
| 181 | . htmlspecialchars($this->appendValueToLabelInDebugMode($possibleItem[0], $possibleItem[1])) . |
||
| 182 | '</option>'; |
||
| 183 | } |
||
| 184 | |||
| 185 | // Html stuff for filter and select filter on top of right side of multi select boxes |
||
| 186 | $filterTextfield[] = '<span class="input-group input-group-sm">'; |
||
| 187 | $filterTextfield[] = '<span class="input-group-addon">'; |
||
| 188 | $filterTextfield[] = '<span class="fa fa-filter"></span>'; |
||
| 189 | $filterTextfield[] = '</span>'; |
||
| 190 | $filterTextfield[] = '<input class="t3js-formengine-multiselect-filter-textfield form-control" value="">'; |
||
| 191 | $filterTextfield[] = '</span>'; |
||
| 192 | |||
| 193 | $filterDropDownOptions = []; |
||
| 194 | if (isset($config['multiSelectFilterItems']) && is_array($config['multiSelectFilterItems']) && count($config['multiSelectFilterItems']) > 1) { |
||
| 195 | foreach ($config['multiSelectFilterItems'] as $optionElement) { |
||
| 196 | $value = $languageService->sL($optionElement[0]); |
||
| 197 | $label = $value; |
||
| 198 | if (isset($optionElement[1]) && trim($optionElement[1]) !== '') { |
||
| 199 | $label = $languageService->sL($optionElement[1]); |
||
| 200 | } |
||
| 201 | $filterDropDownOptions[] = '<option value="' . htmlspecialchars($value) . '">' . htmlspecialchars($label) . '</option>'; |
||
| 202 | } |
||
| 203 | } |
||
| 204 | $filterHtml = []; |
||
| 205 | $filterHtml[] = '<div class="form-multigroup-item-wizard">'; |
||
| 206 | if (!empty($filterDropDownOptions)) { |
||
| 207 | $filterHtml[] = '<div class="t3js-formengine-multiselect-filter-container form-multigroup-wrap">'; |
||
| 208 | $filterHtml[] = '<div class="form-multigroup-item form-multigroup-element">'; |
||
| 209 | $filterHtml[] = '<select class="form-control input-sm t3js-formengine-multiselect-filter-dropdown">'; |
||
| 210 | $filterHtml[] = implode(LF, $filterDropDownOptions); |
||
| 211 | $filterHtml[] = '</select>'; |
||
| 212 | $filterHtml[] = '</div>'; |
||
| 213 | $filterHtml[] = '<div class="form-multigroup-item form-multigroup-element">'; |
||
| 214 | $filterHtml[] = implode(LF, $filterTextfield); |
||
| 215 | $filterHtml[] = '</div>'; |
||
| 216 | $filterHtml[] = '</div>'; |
||
| 217 | } else { |
||
| 218 | $filterHtml[] = implode(LF, $filterTextfield); |
||
| 219 | } |
||
| 220 | $filterHtml[] = '</div>'; |
||
| 221 | |||
| 222 | $classes = []; |
||
| 223 | $classes[] = 'form-control'; |
||
| 224 | $classes[] = 'tceforms-multiselect'; |
||
| 225 | if ($maxItems === 1) { |
||
| 226 | $classes[] = 'form-select-no-siblings'; |
||
| 227 | } |
||
| 228 | $multipleAttribute = ''; |
||
| 229 | if ($maxItems !== 1 && $size !== 1) { |
||
| 230 | $multipleAttribute = ' multiple="multiple"'; |
||
| 231 | } |
||
| 232 | |||
| 233 | $fieldInformationResult = $this->renderFieldInformation(); |
||
| 234 | $fieldInformationHtml = $fieldInformationResult['html']; |
||
| 235 | $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false); |
||
| 236 | |||
| 237 | [$fieldControlResult, $alternativeControlResult] = $this->renderFieldControl(); |
||
| 238 | $fieldControlHtml = $fieldControlResult['html']; |
||
| 239 | $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldControlResult, false); |
||
| 240 | $alternativeFieldControlHtml = $alternativeControlResult['html']; |
||
| 241 | $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $alternativeControlResult, false); |
||
| 242 | |||
| 243 | $fieldWizardResult = $this->renderFieldWizard(); |
||
| 244 | $fieldWizardHtml = $fieldWizardResult['html']; |
||
| 245 | $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false); |
||
| 246 | |||
| 247 | $selectedOptionsFieldId = StringUtility::getUniqueId('tceforms-multiselect-'); |
||
| 248 | $availableOptionsFieldId = StringUtility::getUniqueId('tceforms-multiselect-'); |
||
| 249 | |||
| 250 | $html = []; |
||
| 251 | $html[] = '<div class="formengine-field-item t3js-formengine-field-item">'; |
||
| 252 | $html[] = $fieldInformationHtml; |
||
| 253 | $html[] = '<div class="form-wizards-wrap">'; |
||
| 254 | $html[] = '<div class="form-wizards-element">'; |
||
| 255 | $html[] = '<input type="hidden" data-formengine-input-name="' . htmlspecialchars($elementName) . '" value="' . (int)$itemCanBeSelectedMoreThanOnce . '" />'; |
||
| 256 | $html[] = '<div class="form-multigroup-wrap t3js-formengine-field-group">'; |
||
| 257 | $html[] = '<div class="form-multigroup-item form-multigroup-element">'; |
||
| 258 | $html[] = '<label>'; |
||
| 259 | $html[] = htmlspecialchars($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.selected')); |
||
| 260 | $html[] = '</label>'; |
||
| 261 | $html[] = '<div class="form-wizards-wrap form-wizards-aside">'; |
||
| 262 | $html[] = '<div class="form-wizards-element">'; |
||
| 263 | $html[] = '<select'; |
||
| 264 | $html[] = ' id="' . $selectedOptionsFieldId . '"'; |
||
| 265 | $html[] = ' size="' . $size . '"'; |
||
| 266 | $html[] = ' class="' . implode(' ', $classes) . '"'; |
||
| 267 | $html[] = $multipleAttribute; |
||
| 268 | $html[] = ' data-formengine-input-name="' . htmlspecialchars($elementName) . '"'; |
||
| 269 | $html[] = '>'; |
||
| 270 | $html[] = implode(LF, $selectedItemsHtml); |
||
| 271 | $html[] = '</select>'; |
||
| 272 | $html[] = '</div>'; |
||
| 273 | $html[] = '<div class="form-wizards-items-aside">'; |
||
| 274 | $html[] = '<div class="btn-group-vertical">'; |
||
| 275 | if ($maxItems > 1 && $size >= 5) { |
||
| 276 | $html[] = '<a href="#"'; |
||
| 277 | $html[] = ' class="btn btn-default t3js-btn-option t3js-btn-moveoption-top"'; |
||
| 278 | $html[] = ' data-fieldname="' . htmlspecialchars($elementName) . '"'; |
||
| 279 | $html[] = ' title="' . htmlspecialchars($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.move_to_top')) . '"'; |
||
| 280 | $html[] = '>'; |
||
| 281 | $html[] = $this->iconFactory->getIcon('actions-move-to-top', Icon::SIZE_SMALL)->render(); |
||
| 282 | $html[] = '</a>'; |
||
| 283 | } |
||
| 284 | if ($maxItems > 1) { |
||
| 285 | $html[] = '<a href="#"'; |
||
| 286 | $html[] = ' class="btn btn-default t3js-btn-option t3js-btn-moveoption-up"'; |
||
| 287 | $html[] = ' data-fieldname="' . htmlspecialchars($elementName) . '"'; |
||
| 288 | $html[] = ' title="' . htmlspecialchars($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.move_up')) . '"'; |
||
| 289 | $html[] = '>'; |
||
| 290 | $html[] = $this->iconFactory->getIcon('actions-move-up', Icon::SIZE_SMALL)->render(); |
||
| 291 | $html[] = '</a>'; |
||
| 292 | $html[] = '<a href="#"'; |
||
| 293 | $html[] = ' class="btn btn-default t3js-btn-option t3js-btn-moveoption-down"'; |
||
| 294 | $html[] = ' data-fieldname="' . htmlspecialchars($elementName) . '"'; |
||
| 295 | $html[] = ' title="' . htmlspecialchars($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.move_down')) . '"'; |
||
| 296 | $html[] = '>'; |
||
| 297 | $html[] = $this->iconFactory->getIcon('actions-move-down', Icon::SIZE_SMALL)->render(); |
||
| 298 | $html[] = '</a>'; |
||
| 299 | } |
||
| 300 | if ($maxItems > 1 && $size >= 5) { |
||
| 301 | $html[] = '<a href="#"'; |
||
| 302 | $html[] = ' class="btn btn-default t3js-btn-option t3js-btn-moveoption-bottom"'; |
||
| 303 | $html[] = ' data-fieldname="' . htmlspecialchars($elementName) . '"'; |
||
| 304 | $html[] = ' title="' . htmlspecialchars($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.move_to_bottom')) . '"'; |
||
| 305 | $html[] = '>'; |
||
| 306 | $html[] = $this->iconFactory->getIcon('actions-move-to-bottom', Icon::SIZE_SMALL)->render(); |
||
| 307 | $html[] = '</a>'; |
||
| 308 | } |
||
| 309 | $html[] = $alternativeFieldControlHtml; |
||
| 310 | $html[] = '<a href="#"'; |
||
| 311 | $html[] = ' class="btn btn-default t3js-btn-option t3js-btn-removeoption"'; |
||
| 312 | $html[] = ' data-fieldname="' . htmlspecialchars($elementName) . '"'; |
||
| 313 | $html[] = ' title="' . htmlspecialchars($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.remove_selected')) . '"'; |
||
| 314 | $html[] = '>'; |
||
| 315 | $html[] = $this->iconFactory->getIcon('actions-selection-delete', Icon::SIZE_SMALL)->render(); |
||
| 316 | $html[] = '</a>'; |
||
| 317 | $html[] = '</div>'; |
||
| 318 | $html[] = '</div>'; |
||
| 319 | $html[] = '</div>'; |
||
| 320 | $html[] = '</div>'; |
||
| 321 | $html[] = '<div class="form-multigroup-item form-multigroup-element">'; |
||
| 322 | $html[] = '<label>'; |
||
| 323 | $html[] = htmlspecialchars($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.items')); |
||
| 324 | $html[] = '</label>'; |
||
| 325 | $html[] = '<div class="form-wizards-wrap form-wizards-aside">'; |
||
| 326 | $html[] = '<div class="form-wizards-element">'; |
||
| 327 | $html[] = implode(LF, $filterHtml); |
||
| 328 | $html[] = '<select'; |
||
| 329 | $html[] = ' data-relatedfieldname="' . htmlspecialchars($elementName) . '"'; |
||
| 330 | $html[] = ' data-exclusivevalues="' . htmlspecialchars($config['exclusiveKeys']) . '"'; |
||
| 331 | $html[] = ' id="' . $availableOptionsFieldId . '"'; |
||
| 332 | $html[] = ' data-formengine-input-name="' . htmlspecialchars($elementName) . '"'; |
||
| 333 | $html[] = ' class="form-control t3js-formengine-select-itemstoselect"'; |
||
| 334 | $html[] = ' size="' . $size . '"'; |
||
| 335 | $html[] = ' onchange="' . htmlspecialchars(implode('', $parameterArray['fieldChangeFunc'])) . '"'; |
||
| 336 | $html[] = ' data-formengine-validation-rules="' . htmlspecialchars($this->getValidationDataAsJsonString($config)) . '"'; |
||
| 337 | $html[] = '>'; |
||
| 338 | $html[] = implode(LF, $selectableItemsHtml); |
||
| 339 | $html[] = '</select>'; |
||
| 340 | $html[] = '</div>'; |
||
| 341 | if (!empty($fieldControlHtml)) { |
||
| 342 | $html[] = '<div class="form-wizards-items-aside">'; |
||
| 343 | $html[] = '<div class="btn-group-vertical">'; |
||
| 344 | $html[] = $fieldControlHtml; |
||
| 345 | $html[] = '</div>'; |
||
| 346 | $html[] = '</div>'; |
||
| 347 | } |
||
| 348 | $html[] = '</div>'; |
||
| 349 | $html[] = '</div>'; |
||
| 350 | $html[] = '</div>'; |
||
| 351 | $html[] = '<input type="hidden" name="' . htmlspecialchars($elementName) . '" value="' . htmlspecialchars(implode(',', $listOfSelectedValues)) . '" />'; |
||
| 352 | $html[] = '</div>'; |
||
| 353 | if (!empty($fieldWizardHtml)) { |
||
| 354 | $html[] = '<div class="form-wizards-items-bottom">'; |
||
| 355 | $html[] = $fieldWizardHtml; |
||
| 356 | $html[] = '</div>'; |
||
| 357 | } |
||
| 358 | $html[] = '</div>'; |
||
| 359 | $html[] = '</div>'; |
||
| 360 | |||
| 361 | $resultArray['requireJsModules'][] = ['TYPO3/CMS/Backend/FormEngine/Element/SelectMultipleSideBySideElement' => ' |
||
| 362 | function(SelectMultipleSideBySideElement) { |
||
| 363 | new SelectMultipleSideBySideElement(' . GeneralUtility::quoteJSvalue($selectedOptionsFieldId) . ', ' . GeneralUtility::quoteJSvalue($availableOptionsFieldId) . '); |
||
| 364 | }' |
||
| 365 | ]; |
||
| 366 | |||
| 367 | $resultArray['html'] = implode(LF, $html); |
||
| 368 | return $resultArray; |
||
| 369 | } |
||
| 470 |