| Conditions | 25 |
| Paths | 6049 |
| Total Lines | 224 |
| Code Lines | 176 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 91 | public function render() |
||
| 92 | { |
||
| 93 | $languageService = $this->getLanguageService(); |
||
| 94 | |||
| 95 | $table = $this->data['tableName']; |
||
| 96 | $fieldName = $this->data['fieldName']; |
||
| 97 | $row = $this->data['databaseRow']; |
||
| 98 | $parameterArray = $this->data['parameterArray']; |
||
| 99 | $resultArray = $this->initializeResultArray(); |
||
| 100 | $config = $parameterArray['fieldConf']['config']; |
||
| 101 | |||
| 102 | $itemValue = $parameterArray['itemFormElValue']; |
||
| 103 | $evalList = GeneralUtility::trimExplode(',', $config['eval'], true); |
||
| 104 | $size = MathUtility::forceIntegerInRange($config['size'] ?? $this->defaultInputWidth, $this->minimumInputWidth, $this->maxInputWidth); |
||
| 105 | $width = (int)$this->formMaxWidth($size); |
||
| 106 | $nullControlNameEscaped = htmlspecialchars('control[active][' . $table . '][' . $row['uid'] . '][' . $fieldName . ']'); |
||
| 107 | |||
| 108 | $fieldInformationResult = $this->renderFieldInformation(); |
||
| 109 | $fieldInformationHtml = $fieldInformationResult['html']; |
||
| 110 | $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false); |
||
| 111 | |||
| 112 | if ($config['readOnly']) { |
||
| 113 | // Early return for read only fields |
||
| 114 | $html = []; |
||
| 115 | $html[] = '<div class="formengine-field-item t3js-formengine-field-item">'; |
||
| 116 | $html[] = $fieldInformationHtml; |
||
| 117 | $html[] = '<div class="form-wizards-wrap">'; |
||
| 118 | $html[] = '<div class="form-wizards-element">'; |
||
| 119 | $html[] = '<div class="form-control-wrap" style="max-width: ' . $width . 'px">'; |
||
| 120 | $html[] = '<input class="form-control" value="' . htmlspecialchars($itemValue) . '" type="text" disabled>'; |
||
| 121 | $html[] = '</div>'; |
||
| 122 | $html[] = '</div>'; |
||
| 123 | $html[] = '</div>'; |
||
| 124 | $html[] = '</div>'; |
||
| 125 | $resultArray['html'] = implode(LF, $html); |
||
| 126 | return $resultArray; |
||
| 127 | } |
||
| 128 | |||
| 129 | // @todo: The whole eval handling is a mess and needs refactoring |
||
| 130 | foreach ($evalList as $func) { |
||
| 131 | // @todo: This is ugly: The code should find out on it's own whether an eval definition is a |
||
| 132 | // @todo: keyword like "date", or a class reference. The global registration could be dropped then |
||
| 133 | // Pair hook to the one in \TYPO3\CMS\Core\DataHandling\DataHandler::checkValue_input_Eval() |
||
| 134 | if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func])) { |
||
| 135 | if (class_exists($func)) { |
||
| 136 | $evalObj = GeneralUtility::makeInstance($func); |
||
| 137 | if (method_exists($evalObj, 'deevaluateFieldValue')) { |
||
| 138 | $_params = [ |
||
| 139 | 'value' => $itemValue |
||
| 140 | ]; |
||
| 141 | $itemValue = $evalObj->deevaluateFieldValue($_params); |
||
| 142 | } |
||
| 143 | if (method_exists($evalObj, 'returnFieldJS')) { |
||
| 144 | $resultArray['additionalJavaScriptPost'][] = 'TBE_EDITOR.customEvalFunctions[' . GeneralUtility::quoteJSvalue($func) . ']' |
||
| 145 | . ' = function(value) {' . $evalObj->returnFieldJS() . '};'; |
||
| 146 | } |
||
| 147 | } |
||
| 148 | } |
||
| 149 | } |
||
| 150 | |||
| 151 | $fieldId = StringUtility::getUniqueId('formengine-input-'); |
||
| 152 | |||
| 153 | $attributes = [ |
||
| 154 | 'value' => '', |
||
| 155 | 'id' => $fieldId, |
||
| 156 | 'class' => implode(' ', [ |
||
| 157 | 'form-control', |
||
| 158 | 't3js-clearable', |
||
| 159 | 't3js-form-field-inputlink-input', |
||
| 160 | 'hidden', |
||
| 161 | 'hasDefaultValue', |
||
| 162 | ]), |
||
| 163 | 'data-formengine-validation-rules' => $this->getValidationDataAsJsonString($config), |
||
| 164 | 'data-formengine-input-params' => (string)json_encode([ |
||
| 165 | 'field' => $parameterArray['itemFormElName'], |
||
| 166 | 'evalList' => implode(',', $evalList) |
||
| 167 | ]), |
||
| 168 | 'data-formengine-input-name' => (string)($parameterArray['itemFormElName'] ?? ''), |
||
| 169 | ]; |
||
| 170 | |||
| 171 | $maxLength = $config['max'] ?? 0; |
||
| 172 | if ((int)$maxLength > 0) { |
||
| 173 | $attributes['maxlength'] = (string)(int)$maxLength; |
||
| 174 | } |
||
| 175 | if (!empty($config['placeholder'])) { |
||
| 176 | $attributes['placeholder'] = trim($config['placeholder']); |
||
| 177 | } |
||
| 178 | if (isset($config['autocomplete'])) { |
||
| 179 | $attributes['autocomplete'] = empty($config['autocomplete']) ? 'new-' . $fieldName : 'on'; |
||
| 180 | } |
||
| 181 | |||
| 182 | $valuePickerHtml = []; |
||
| 183 | if (isset($config['valuePicker']['items']) && is_array($config['valuePicker']['items'])) { |
||
| 184 | $mode = $config['valuePicker']['mode'] ?? ''; |
||
| 185 | $itemName = $parameterArray['itemFormElName']; |
||
| 186 | $fieldChangeFunc = $parameterArray['fieldChangeFunc']; |
||
| 187 | if ($mode === 'append') { |
||
| 188 | $assignValue = 'document.querySelectorAll(' . GeneralUtility::quoteJSvalue('[data-formengine-input-name="' . $itemName . '"]') . ')[0]' |
||
| 189 | . '.value=\'\'+this.options[this.selectedIndex].value+document.editform[' . GeneralUtility::quoteJSvalue($itemName) . '].value'; |
||
| 190 | } elseif ($mode === 'prepend') { |
||
| 191 | $assignValue = 'document.querySelectorAll(' . GeneralUtility::quoteJSvalue('[data-formengine-input-name="' . $itemName . '"]') . ')[0]' |
||
| 192 | . '.value+=\'\'+this.options[this.selectedIndex].value'; |
||
| 193 | } else { |
||
| 194 | $assignValue = 'document.querySelectorAll(' . GeneralUtility::quoteJSvalue('[data-formengine-input-name="' . $itemName . '"]') . ')[0]' |
||
| 195 | . '.value=this.options[this.selectedIndex].value'; |
||
| 196 | } |
||
| 197 | $valuePickerHtml[] = '<select'; |
||
| 198 | $valuePickerHtml[] = ' class="form-select"'; |
||
| 199 | $valuePickerHtml[] = ' onchange="' . htmlspecialchars($assignValue . ';this.blur();this.selectedIndex=0;' . implode('', $fieldChangeFunc)) . '"'; |
||
| 200 | $valuePickerHtml[] = '>'; |
||
| 201 | $valuePickerHtml[] = '<option></option>'; |
||
| 202 | foreach ($config['valuePicker']['items'] as $item) { |
||
| 203 | $valuePickerHtml[] = '<option value="' . htmlspecialchars($item[1]) . '">' . htmlspecialchars($languageService->sL($item[0])) . '</option>'; |
||
| 204 | } |
||
| 205 | $valuePickerHtml[] = '</select>'; |
||
| 206 | } |
||
| 207 | |||
| 208 | $fieldWizardResult = $this->renderFieldWizard(); |
||
| 209 | $fieldWizardHtml = $fieldWizardResult['html']; |
||
| 210 | $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false); |
||
| 211 | |||
| 212 | $fieldControlResult = $this->renderFieldControl(); |
||
| 213 | $fieldControlHtml = $fieldControlResult['html']; |
||
| 214 | $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldControlResult, false); |
||
| 215 | |||
| 216 | $linkExplanation = $this->getLinkExplanation($itemValue ?: ''); |
||
| 217 | $explanation = htmlspecialchars($linkExplanation['text']); |
||
| 218 | $toggleButtonTitle = $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:buttons.toggleLinkExplanation'); |
||
| 219 | |||
| 220 | $expansionHtml = []; |
||
| 221 | $expansionHtml[] = '<div class="form-control-wrap" style="max-width: ' . $width . 'px">'; |
||
| 222 | $expansionHtml[] = '<div class="form-wizards-wrap">'; |
||
| 223 | $expansionHtml[] = '<div class="form-wizards-element">'; |
||
| 224 | $expansionHtml[] = '<div class="input-group t3js-form-field-inputlink">'; |
||
| 225 | $expansionHtml[] = '<span class="t3js-form-field-inputlink-icon input-group-addon">' . $linkExplanation['icon'] . '</span>'; |
||
| 226 | $expansionHtml[] = '<input class="form-control t3js-form-field-inputlink-explanation" data-bs-toggle="tooltip" data-title="' . $explanation . '" value="' . $explanation . '" readonly>'; |
||
| 227 | $expansionHtml[] = '<input type="text" ' . GeneralUtility::implodeAttributes($attributes, true) . ' />'; |
||
| 228 | $expansionHtml[] = '<span class="input-group-btn">'; |
||
| 229 | $expansionHtml[] = '<button class="btn btn-default t3js-form-field-inputlink-explanation-toggle" type="button" title="' . htmlspecialchars($toggleButtonTitle) . '">'; |
||
| 230 | $expansionHtml[] = $this->iconFactory->getIcon('actions-version-workspaces-preview-link', Icon::SIZE_SMALL)->render(); |
||
| 231 | $expansionHtml[] = '</button>'; |
||
| 232 | $expansionHtml[] = '</span>'; |
||
| 233 | $expansionHtml[] = '<input type="hidden" name="' . $parameterArray['itemFormElName'] . '" value="' . htmlspecialchars($itemValue) . '" />'; |
||
| 234 | $expansionHtml[] = '</div>'; |
||
| 235 | $expansionHtml[] = '</div>'; |
||
| 236 | if (!empty($valuePickerHtml) || !empty($fieldControlHtml)) { |
||
| 237 | $expansionHtml[] = '<div class="form-wizards-items-aside">'; |
||
| 238 | $expansionHtml[] = '<div class="btn-group">'; |
||
| 239 | $expansionHtml[] = implode(LF, $valuePickerHtml); |
||
| 240 | $expansionHtml[] = $fieldControlHtml; |
||
| 241 | $expansionHtml[] = '</div>'; |
||
| 242 | $expansionHtml[] = '</div>'; |
||
| 243 | } |
||
| 244 | $expansionHtml[] = '<div class="form-wizards-items-bottom">'; |
||
| 245 | $expansionHtml[] = $linkExplanation['additionalAttributes']; |
||
| 246 | $expansionHtml[] = $fieldWizardHtml; |
||
| 247 | $expansionHtml[] = '</div>'; |
||
| 248 | $expansionHtml[] = '</div>'; |
||
| 249 | $expansionHtml[] = '</div>'; |
||
| 250 | $expansionHtml = implode(LF, $expansionHtml); |
||
| 251 | |||
| 252 | $fullElement = $expansionHtml; |
||
| 253 | if ($this->hasNullCheckboxButNoPlaceholder()) { |
||
| 254 | $checked = $itemValue !== null ? ' checked="checked"' : ''; |
||
| 255 | $fullElement = []; |
||
| 256 | $fullElement[] = '<div class="t3-form-field-disable"></div>'; |
||
| 257 | $fullElement[] = '<div class="form-check t3-form-field-eval-null-checkbox">'; |
||
| 258 | $fullElement[] = '<input type="hidden" name="' . $nullControlNameEscaped . '" value="0" />'; |
||
| 259 | $fullElement[] = '<input type="checkbox" class="form-check-input" name="' . $nullControlNameEscaped . '" id="' . $nullControlNameEscaped . '" value="1"' . $checked . ' />'; |
||
| 260 | $fullElement[] = '<label class="form-check-label" for="' . $nullControlNameEscaped . '">'; |
||
| 261 | $fullElement[] = $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.nullCheckbox'); |
||
| 262 | $fullElement[] = '</label>'; |
||
| 263 | $fullElement[] = '</div>'; |
||
| 264 | $fullElement[] = $expansionHtml; |
||
| 265 | $fullElement = implode(LF, $fullElement); |
||
| 266 | } elseif ($this->hasNullCheckboxWithPlaceholder()) { |
||
| 267 | $checked = $itemValue !== null ? ' checked="checked"' : ''; |
||
| 268 | $placeholder = $shortenedPlaceholder = $config['placeholder'] ?? ''; |
||
| 269 | $disabled = ''; |
||
| 270 | $fallbackValue = 0; |
||
| 271 | if (strlen($placeholder) > 0) { |
||
| 272 | $shortenedPlaceholder = GeneralUtility::fixed_lgd_cs($placeholder, 20); |
||
| 273 | if ($placeholder !== $shortenedPlaceholder) { |
||
| 274 | $overrideLabel = sprintf( |
||
| 275 | $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.placeholder.override'), |
||
| 276 | '<span title="' . htmlspecialchars($placeholder) . '">' . htmlspecialchars($shortenedPlaceholder) . '</span>' |
||
| 277 | ); |
||
| 278 | } else { |
||
| 279 | $overrideLabel = sprintf( |
||
| 280 | $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.placeholder.override'), |
||
| 281 | htmlspecialchars($placeholder) |
||
| 282 | ); |
||
| 283 | } |
||
| 284 | } else { |
||
| 285 | $overrideLabel = $languageService->sL( |
||
| 286 | 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.placeholder.override_not_available' |
||
| 287 | ); |
||
| 288 | } |
||
| 289 | $fullElement = []; |
||
| 290 | $fullElement[] = '<div class="form-check t3js-form-field-eval-null-placeholder-checkbox">'; |
||
| 291 | $fullElement[] = '<input type="hidden" name="' . $nullControlNameEscaped . '" value="' . $fallbackValue . '" />'; |
||
| 292 | $fullElement[] = '<input type="checkbox" class="form-check-input" name="' . $nullControlNameEscaped . '" id="' . $nullControlNameEscaped . '" value="1"' . $checked . $disabled . ' />'; |
||
| 293 | $fullElement[] = '<label class="form-check-label" for="' . $nullControlNameEscaped . '">'; |
||
| 294 | $fullElement[] = $overrideLabel; |
||
| 295 | $fullElement[] = '</label>'; |
||
| 296 | $fullElement[] = '</div>'; |
||
| 297 | $fullElement[] = '<div class="t3js-formengine-placeholder-placeholder">'; |
||
| 298 | $fullElement[] = '<div class="form-control-wrap" style="max-width:' . $width . 'px">'; |
||
| 299 | $fullElement[] = '<input type="text" class="form-control" disabled="disabled" value="' . htmlspecialchars($shortenedPlaceholder) . '" />'; |
||
| 300 | $fullElement[] = '</div>'; |
||
| 301 | $fullElement[] = '</div>'; |
||
| 302 | $fullElement[] = '<div class="t3js-formengine-placeholder-formfield">'; |
||
| 303 | $fullElement[] = $expansionHtml; |
||
| 304 | $fullElement[] = '</div>'; |
||
| 305 | $fullElement = implode(LF, $fullElement); |
||
| 306 | } |
||
| 307 | |||
| 308 | $resultArray['requireJsModules'][] = ['TYPO3/CMS/Backend/FormEngine/Element/InputLinkElement' => ' |
||
| 309 | function(InputLinkElement) { |
||
| 310 | new InputLinkElement(' . GeneralUtility::quoteJSvalue($fieldId) . '); |
||
| 311 | }' |
||
| 312 | ]; |
||
| 313 | $resultArray['html'] = '<div class="formengine-field-item t3js-formengine-field-item">' . $fieldInformationHtml . $fullElement . '</div>'; |
||
| 314 | return $resultArray; |
||
| 315 | } |
||
| 469 |