| Conditions | 48 |
| Paths | > 20000 |
| Total Lines | 287 |
| Code Lines | 176 |
| 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 |
||
| 103 | public function render() |
||
| 104 | { |
||
| 105 | $languageService = $this->getLanguageService(); |
||
| 106 | |||
| 107 | $this->inlineData = $this->data['inlineData']; |
||
| 108 | |||
| 109 | /** @var InlineStackProcessor $inlineStackProcessor */ |
||
| 110 | $inlineStackProcessor = GeneralUtility::makeInstance(InlineStackProcessor::class); |
||
| 111 | $this->inlineStackProcessor = $inlineStackProcessor; |
||
| 112 | $inlineStackProcessor->initializeByGivenStructure($this->data['inlineStructure']); |
||
| 113 | |||
| 114 | $table = $this->data['tableName']; |
||
| 115 | $row = $this->data['databaseRow']; |
||
| 116 | $field = $this->data['fieldName']; |
||
| 117 | $parameterArray = $this->data['parameterArray']; |
||
| 118 | |||
| 119 | $resultArray = $this->initializeResultArray(); |
||
| 120 | |||
| 121 | $config = $parameterArray['fieldConf']['config']; |
||
| 122 | $foreign_table = $config['foreign_table']; |
||
| 123 | $isReadOnly = isset($config['readOnly']) && $config['readOnly']; |
||
| 124 | $language = 0; |
||
| 125 | $languageFieldName = $GLOBALS['TCA'][$table]['ctrl']['languageField']; |
||
| 126 | if (BackendUtility::isTableLocalizable($table)) { |
||
| 127 | $language = isset($row[$languageFieldName][0]) ? (int)$row[$languageFieldName][0] : (int)$row[$languageFieldName]; |
||
| 128 | } |
||
| 129 | |||
| 130 | // Add the current inline job to the structure stack |
||
| 131 | $newStructureItem = [ |
||
| 132 | 'table' => $table, |
||
| 133 | 'uid' => $row['uid'], |
||
| 134 | 'field' => $field, |
||
| 135 | 'config' => $config, |
||
| 136 | ]; |
||
| 137 | // Extract FlexForm parts (if any) from element name, e.g. array('vDEF', 'lDEF', 'FlexField', 'vDEF') |
||
| 138 | if (!empty($parameterArray['itemFormElName'])) { |
||
| 139 | $flexFormParts = $this->extractFlexFormParts($parameterArray['itemFormElName']); |
||
| 140 | if ($flexFormParts !== null) { |
||
| 141 | $newStructureItem['flexform'] = $flexFormParts; |
||
| 142 | } |
||
| 143 | } |
||
| 144 | $inlineStackProcessor->pushStableStructureItem($newStructureItem); |
||
| 145 | |||
| 146 | // Transport the flexform DS identifier fields to the FormInlineAjaxController |
||
| 147 | if (!empty($newStructureItem['flexform']) |
||
| 148 | && isset($this->data['processedTca']['columns'][$field]['config']['dataStructureIdentifier']) |
||
| 149 | ) { |
||
| 150 | $config['dataStructureIdentifier'] = $this->data['processedTca']['columns'][$field]['config']['dataStructureIdentifier']; |
||
| 151 | } |
||
| 152 | |||
| 153 | // Hand over original returnUrl to FormInlineAjaxController. Needed if opening for instance a |
||
| 154 | // nested element in a new view to then go back to the original returnUrl and not the url of |
||
| 155 | // the inline ajax controller |
||
| 156 | $config['originalReturnUrl'] = $this->data['returnUrl']; |
||
| 157 | |||
| 158 | // e.g. data[<table>][<uid>][<field>] |
||
| 159 | $nameForm = $inlineStackProcessor->getCurrentStructureFormPrefix(); |
||
| 160 | // e.g. data-<pid>-<table1>-<uid1>-<field1>-<table2>-<uid2>-<field2> |
||
| 161 | $nameObject = $inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->data['inlineFirstPid']); |
||
| 162 | |||
| 163 | $config['inline']['first'] = false; |
||
| 164 | $firstChild = reset($this->data['parameterArray']['fieldConf']['children']); |
||
| 165 | if (isset($firstChild['databaseRow']['uid'])) { |
||
| 166 | $config['inline']['first'] = $firstChild['databaseRow']['uid']; |
||
| 167 | } |
||
| 168 | $config['inline']['last'] = false; |
||
| 169 | $lastChild = end($this->data['parameterArray']['fieldConf']['children']); |
||
| 170 | if (isset($lastChild['databaseRow']['uid'])) { |
||
| 171 | $config['inline']['last'] = $lastChild['databaseRow']['uid']; |
||
| 172 | } |
||
| 173 | |||
| 174 | $top = $inlineStackProcessor->getStructureLevel(0); |
||
| 175 | |||
| 176 | $this->inlineData['config'][$nameObject] = [ |
||
| 177 | 'table' => $foreign_table, |
||
| 178 | ]; |
||
| 179 | $configJson = (string)json_encode($config); |
||
| 180 | $this->inlineData['config'][$nameObject . '-' . $foreign_table] = [ |
||
| 181 | 'min' => $config['minitems'], |
||
| 182 | 'max' => $config['maxitems'], |
||
| 183 | 'sortable' => $config['appearance']['useSortable'], |
||
| 184 | 'top' => [ |
||
| 185 | 'table' => $top['table'], |
||
| 186 | 'uid' => $top['uid'] |
||
| 187 | ], |
||
| 188 | 'context' => [ |
||
| 189 | 'config' => $configJson, |
||
| 190 | 'hmac' => GeneralUtility::hmac($configJson, 'InlineContext'), |
||
| 191 | ], |
||
| 192 | ]; |
||
| 193 | $this->inlineData['nested'][$nameObject] = $this->data['tabAndInlineStack']; |
||
| 194 | |||
| 195 | $uniqueMax = 0; |
||
| 196 | $uniqueIds = []; |
||
| 197 | |||
| 198 | if ($config['foreign_unique']) { |
||
| 199 | // Add inlineData['unique'] with JS unique configuration |
||
| 200 | // @todo: Improve validation and throw an exception if type is neither select nor group here |
||
| 201 | $type = $config['selectorOrUniqueConfiguration']['config']['type'] === 'select' ? 'select' : 'groupdb'; |
||
| 202 | foreach ($parameterArray['fieldConf']['children'] as $child) { |
||
| 203 | // Determine used unique ids, skip not localized records |
||
| 204 | if (!$child['isInlineDefaultLanguageRecordInLocalizedParentContext']) { |
||
| 205 | $value = $child['databaseRow'][$config['foreign_unique']]; |
||
| 206 | // We're assuming there is only one connected value here for both select and group |
||
| 207 | if ($type === 'select') { |
||
| 208 | // A select field is an array of uids. See TcaSelectItems data provider for details. |
||
| 209 | // Pick first entry, ends up as eg. $value = 42. |
||
| 210 | $value = $value['0']; |
||
| 211 | } else { |
||
| 212 | // A group field is an array of arrays containing uid + table + title + row. |
||
| 213 | // See TcaGroup data provider for details. |
||
| 214 | // Pick the first one (always on 0), and use uid + table only. Exclude title + row |
||
| 215 | // since the entire inlineData['unique'] array ends up in JavaScript in the end |
||
| 216 | // and we don't need and want the title and the entire row data in the frontend. |
||
| 217 | // Ends up as $value = [ 'uid' => '42', 'table' => 'tx_my_table' ] |
||
| 218 | $value = [ |
||
| 219 | 'uid' => $value[0]['uid'], |
||
| 220 | 'table' => $value[0]['table'], |
||
| 221 | ]; |
||
| 222 | } |
||
| 223 | // Note structure of $value is different in select vs. group: It's a uid for select, but an |
||
| 224 | // array with uid + table for group. |
||
| 225 | $uniqueIds[$child['databaseRow']['uid']] = $value; |
||
| 226 | } |
||
| 227 | } |
||
| 228 | $possibleRecords = $config['selectorOrUniquePossibleRecords']; |
||
| 229 | $possibleRecordsUidToTitle = []; |
||
| 230 | foreach ($possibleRecords as $possibleRecord) { |
||
| 231 | $possibleRecordsUidToTitle[$possibleRecord[1]] = $possibleRecord[0]; |
||
| 232 | } |
||
| 233 | $uniqueMax = $config['appearance']['useCombination'] || empty($possibleRecords) ? -1 : count($possibleRecords); |
||
| 234 | $this->inlineData['unique'][$nameObject . '-' . $foreign_table] = [ |
||
| 235 | 'max' => $uniqueMax, |
||
| 236 | 'used' => $uniqueIds, |
||
| 237 | 'type' => $type, |
||
| 238 | 'table' => $foreign_table, |
||
| 239 | 'elTable' => $config['selectorOrUniqueConfiguration']['foreignTable'], |
||
| 240 | 'field' => $config['foreign_unique'], |
||
| 241 | 'selector' => $config['selectorOrUniqueConfiguration']['isSelector'] ? $type : false, |
||
| 242 | 'possible' => $possibleRecordsUidToTitle, |
||
| 243 | ]; |
||
| 244 | } |
||
| 245 | |||
| 246 | $resultArray['inlineData'] = $this->inlineData; |
||
| 247 | |||
| 248 | // @todo: It might be a good idea to have something like "isLocalizedRecord" or similar set by a data provider |
||
| 249 | $uidOfDefaultRecord = $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']]; |
||
| 250 | $isLocalizedParent = $language > 0 |
||
| 251 | && ($uidOfDefaultRecord[0] ?? $uidOfDefaultRecord) > 0 |
||
| 252 | && MathUtility::canBeInterpretedAsInteger($row['uid']); |
||
| 253 | $numberOfFullLocalizedChildren = 0; |
||
| 254 | $numberOfNotYetLocalizedChildren = 0; |
||
| 255 | foreach ($this->data['parameterArray']['fieldConf']['children'] as $child) { |
||
| 256 | if (!$child['isInlineDefaultLanguageRecordInLocalizedParentContext']) { |
||
| 257 | $numberOfFullLocalizedChildren++; |
||
| 258 | } |
||
| 259 | if ($isLocalizedParent && $child['isInlineDefaultLanguageRecordInLocalizedParentContext']) { |
||
| 260 | $numberOfNotYetLocalizedChildren++; |
||
| 261 | } |
||
| 262 | } |
||
| 263 | |||
| 264 | // Render the localization buttons if needed |
||
| 265 | $localizationButtons = ''; |
||
| 266 | if ($numberOfNotYetLocalizedChildren) { |
||
| 267 | // Add the "Localize all records" button before all child records: |
||
| 268 | if (isset($config['appearance']['showAllLocalizationLink']) && $config['appearance']['showAllLocalizationLink']) { |
||
| 269 | $localizationButtons = ' ' . $this->getLevelInteractionButton('localize', $config); |
||
| 270 | } |
||
| 271 | // Add the "Synchronize with default language" button before all child records: |
||
| 272 | if (isset($config['appearance']['showSynchronizationLink']) && $config['appearance']['showSynchronizationLink']) { |
||
| 273 | $localizationButtons .= ' ' . $this->getLevelInteractionButton('synchronize', $config); |
||
| 274 | } |
||
| 275 | } |
||
| 276 | |||
| 277 | // Define how to show the "Create new record" button - if there are more than maxitems, hide it |
||
| 278 | if ($isReadOnly || $numberOfFullLocalizedChildren >= $config['maxitems'] || ($uniqueMax > 0 && $numberOfFullLocalizedChildren >= $uniqueMax)) { |
||
| 279 | $config['inline']['inlineNewButtonStyle'] = 'display: none;'; |
||
| 280 | $config['inline']['inlineNewRelationButtonStyle'] = 'display: none;'; |
||
| 281 | $config['inline']['inlineOnlineMediaAddButtonStyle'] = 'display: none;'; |
||
| 282 | } |
||
| 283 | |||
| 284 | // Render the level buttons (create new record): |
||
| 285 | $levelButtons = $this->getLevelInteractionButton('newRecord', $config); |
||
| 286 | |||
| 287 | $formGroupAttributes = [ |
||
| 288 | 'class' => 'form-group', |
||
| 289 | 'id' => $nameObject, |
||
| 290 | 'data-uid' => (string)$row['uid'], |
||
| 291 | 'data-local-table' => (string)$top['table'], |
||
| 292 | 'data-local-field' => (string)$top['field'], |
||
| 293 | 'data-foreign-table' => (string)$foreign_table, |
||
| 294 | 'data-object-group' => $nameObject . '-' . $foreign_table, |
||
| 295 | 'data-form-field' => $nameForm, |
||
| 296 | 'data-appearance' => (string)json_encode($config['appearance']), |
||
| 297 | ]; |
||
| 298 | |||
| 299 | // Wrap all inline fields of a record with a <div> (like a container) |
||
| 300 | $html = '<div ' . GeneralUtility::implodeAttributes($formGroupAttributes, true) . '>'; |
||
| 301 | |||
| 302 | $fieldInformationResult = $this->renderFieldInformation(); |
||
| 303 | $html .= $fieldInformationResult['html']; |
||
| 304 | $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false); |
||
| 305 | |||
| 306 | // Add the level buttons before all child records: |
||
| 307 | if ($config['appearance']['levelLinksPosition'] === 'both' || $config['appearance']['levelLinksPosition'] === 'top') { |
||
| 308 | $html .= '<div class="form-group t3js-formengine-validation-marker">' . $levelButtons . $localizationButtons . '</div>'; |
||
| 309 | } |
||
| 310 | |||
| 311 | // If it's required to select from possible child records (reusable children), add a selector box |
||
| 312 | if (!$isReadOnly && $config['foreign_selector'] && $config['appearance']['showPossibleRecordsSelector'] !== false) { |
||
| 313 | if ($config['selectorOrUniqueConfiguration']['config']['type'] === 'select') { |
||
| 314 | $selectorBox = $this->renderPossibleRecordsSelectorTypeSelect($config, $uniqueIds); |
||
| 315 | } else { |
||
| 316 | $selectorBox = $this->renderPossibleRecordsSelectorTypeGroupDB($config); |
||
| 317 | } |
||
| 318 | $html .= $selectorBox . $localizationButtons; |
||
| 319 | } |
||
| 320 | |||
| 321 | $title = $languageService->sL(trim($parameterArray['fieldConf']['label'])); |
||
| 322 | $html .= '<div class="panel-group panel-hover" data-title="' . htmlspecialchars($title) . '" id="' . $nameObject . '_records">'; |
||
| 323 | |||
| 324 | $sortableRecordUids = []; |
||
| 325 | foreach ($this->data['parameterArray']['fieldConf']['children'] as $options) { |
||
| 326 | $options['inlineParentUid'] = $row['uid']; |
||
| 327 | $options['inlineFirstPid'] = $this->data['inlineFirstPid']; |
||
| 328 | // @todo: this can be removed if this container no longer sets additional info to $config |
||
| 329 | $options['inlineParentConfig'] = $config; |
||
| 330 | $options['inlineData'] = $this->inlineData; |
||
| 331 | $options['inlineStructure'] = $inlineStackProcessor->getStructure(); |
||
| 332 | $options['inlineExpandCollapseStateArray'] = $this->data['inlineExpandCollapseStateArray']; |
||
| 333 | $options['renderType'] = 'inlineRecordContainer'; |
||
| 334 | $childResult = $this->nodeFactory->create($options)->render(); |
||
| 335 | $html .= $childResult['html']; |
||
| 336 | $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childResult, false); |
||
| 337 | if (!$options['isInlineDefaultLanguageRecordInLocalizedParentContext']) { |
||
| 338 | // Don't add record to list of "valid" uids if it is only the default |
||
| 339 | // language record of a not yet localized child |
||
| 340 | $sortableRecordUids[] = $options['databaseRow']['uid']; |
||
| 341 | } |
||
| 342 | } |
||
| 343 | |||
| 344 | $html .= '</div>'; |
||
| 345 | |||
| 346 | $fieldWizardResult = $this->renderFieldWizard(); |
||
| 347 | $fieldWizardHtml = $fieldWizardResult['html']; |
||
| 348 | $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false); |
||
| 349 | $html .= $fieldWizardHtml; |
||
| 350 | |||
| 351 | // Add the level buttons after all child records: |
||
| 352 | if (!$isReadOnly && ($config['appearance']['levelLinksPosition'] === 'both' || $config['appearance']['levelLinksPosition'] === 'bottom')) { |
||
| 353 | $html .= $levelButtons . $localizationButtons; |
||
| 354 | } |
||
| 355 | if (is_array($config['customControls'])) { |
||
| 356 | $html .= '<div id="' . $nameObject . '_customControls">'; |
||
| 357 | foreach ($config['customControls'] as $customControlConfig) { |
||
| 358 | if (!isset($customControlConfig['userFunc'])) { |
||
| 359 | throw new \RuntimeException('Support for customControl without a userFunc key in TCA type inline is not supported.', 1548052629); |
||
| 360 | } |
||
| 361 | $parameters = [ |
||
| 362 | 'table' => $table, |
||
| 363 | 'field' => $field, |
||
| 364 | 'row' => $row, |
||
| 365 | 'nameObject' => $nameObject, |
||
| 366 | 'nameForm' => $nameForm, |
||
| 367 | 'config' => $config, |
||
| 368 | 'customControlConfig' => $customControlConfig, |
||
| 369 | ]; |
||
| 370 | $html .= GeneralUtility::callUserFunction($customControlConfig['userFunc'], $parameters, $this); |
||
| 371 | } |
||
| 372 | $html .= '</div>'; |
||
| 373 | } |
||
| 374 | $resultArray['requireJsModules'] = array_merge($resultArray['requireJsModules'], $this->requireJsModules); |
||
| 375 | $resultArray['requireJsModules'][] = ['TYPO3/CMS/Backend/FormEngine/Container/InlineControlContainer' => ' |
||
| 376 | function(InlineControlContainer) { |
||
| 377 | new InlineControlContainer(' . GeneralUtility::quoteJSvalue($nameObject) . '); |
||
| 378 | }' |
||
| 379 | ]; |
||
| 380 | |||
| 381 | // Publish the uids of the child records in the given order to the browser |
||
| 382 | $html .= '<input type="hidden" name="' . $nameForm . '" value="' . implode(',', $sortableRecordUids) . '" ' |
||
| 383 | . ' data-formengine-validation-rules="' . htmlspecialchars($this->getValidationDataAsJsonString(['type' => 'inline', 'minitems' => $config['minitems'], 'maxitems' => $config['maxitems']])) . '"' |
||
|
|
|||
| 384 | . ' class="inlineRecord" />'; |
||
| 385 | // Close the wrap for all inline fields (container) |
||
| 386 | $html .= '</div>'; |
||
| 387 | |||
| 388 | $resultArray['html'] = $html; |
||
| 389 | return $resultArray; |
||
| 390 | } |
||
| 688 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.