| Conditions | 9 |
| Paths | 54 |
| Total Lines | 146 |
| Code Lines | 99 |
| 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 |
||
| 61 | public function render(): array |
||
| 62 | { |
||
| 63 | $this->inlineData = $this->data['inlineData']; |
||
| 64 | |||
| 65 | $this->inlineStackProcessor->initializeByGivenStructure($this->data['inlineStructure']); |
||
| 66 | |||
| 67 | $row = $this->data['databaseRow']; |
||
| 68 | $parameterArray = $this->data['parameterArray']; |
||
| 69 | $config = $parameterArray['fieldConf']['config']; |
||
| 70 | $resultArray = $this->initializeResultArray(); |
||
| 71 | |||
| 72 | // Add the current inline job to the structure stack |
||
| 73 | $this->inlineStackProcessor->pushStableStructureItem([ |
||
| 74 | 'table' => $this->data['tableName'], |
||
| 75 | 'uid' => $row['uid'], |
||
| 76 | 'field' => $this->data['fieldName'], |
||
| 77 | 'config' => $config, |
||
| 78 | ]); |
||
| 79 | |||
| 80 | // Hand over original returnUrl to SiteInlineAjaxController. Needed if opening for instance a |
||
| 81 | // nested element in a new view to then go back to the original returnUrl and not the url of |
||
| 82 | // the site inline ajax controller. |
||
| 83 | $config['originalReturnUrl'] = $this->data['returnUrl']; |
||
| 84 | |||
| 85 | // e.g. data[site][1][languages] |
||
| 86 | $nameForm = $this->inlineStackProcessor->getCurrentStructureFormPrefix(); |
||
| 87 | // e.g. data-0-site-1-languages |
||
| 88 | $nameObject = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->data['inlineFirstPid']); |
||
| 89 | // e.g. array('table' => 'site', 'uid' => '1', 'field' => 'languages', 'config' => array()) |
||
| 90 | $top = $this->inlineStackProcessor->getStructureLevel(0); |
||
| 91 | |||
| 92 | $this->inlineData['config'][$nameObject] = [ |
||
| 93 | 'table' => self::FOREIGN_TABLE |
||
| 94 | ]; |
||
| 95 | |||
| 96 | $configJson = (string)json_encode($config); |
||
| 97 | $this->inlineData['config'][$nameObject . '-' . self::FOREIGN_TABLE] = [ |
||
| 98 | 'min' => $config['minitems'], |
||
| 99 | 'max' => $config['maxitems'], |
||
| 100 | 'sortable' => false, |
||
| 101 | 'top' => [ |
||
| 102 | 'table' => $top['table'], |
||
| 103 | 'uid' => $top['uid'] |
||
| 104 | ], |
||
| 105 | 'context' => [ |
||
| 106 | 'config' => $configJson, |
||
| 107 | 'hmac' => GeneralUtility::hmac($configJson, 'InlineContext'), |
||
| 108 | ], |
||
| 109 | ]; |
||
| 110 | $this->inlineData['nested'][$nameObject] = $this->data['tabAndInlineStack']; |
||
| 111 | |||
| 112 | $uniqueIds = []; |
||
| 113 | foreach ($parameterArray['fieldConf']['children'] as $children) { |
||
| 114 | $value = (int)($children['databaseRow'][self::FOREIGN_FIELD]['0'] ?? 0); |
||
| 115 | if (isset($children['databaseRow']['uid'])) { |
||
| 116 | $uniqueIds[$children['databaseRow']['uid']] = $value; |
||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 120 | $uniquePossibleRecords = $config['uniquePossibleRecords'] ?? []; |
||
| 121 | $possibleRecordsUidToTitle = []; |
||
| 122 | foreach ($uniquePossibleRecords as $possibleRecord) { |
||
| 123 | $possibleRecordsUidToTitle[$possibleRecord[1]] = $possibleRecord[0]; |
||
| 124 | } |
||
| 125 | $this->inlineData['unique'][$nameObject . '-' . self::FOREIGN_TABLE] = [ |
||
| 126 | // Usually "max" would the the number of possible records. However, since |
||
| 127 | // we also allow new languages to be created, we just use the maxitems value. |
||
| 128 | 'max' => $config['maxitems'], |
||
| 129 | // "used" must be a string array |
||
| 130 | 'used' => array_map('strval', $uniqueIds), |
||
| 131 | 'table' => self::FOREIGN_TABLE, |
||
| 132 | 'elTable' => self::FOREIGN_TABLE, |
||
| 133 | 'field' => self::FOREIGN_FIELD, |
||
| 134 | 'possible' => $possibleRecordsUidToTitle, |
||
| 135 | ]; |
||
| 136 | |||
| 137 | $resultArray['inlineData'] = $this->inlineData; |
||
| 138 | |||
| 139 | $fieldInformationResult = $this->renderFieldInformation(); |
||
| 140 | $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false); |
||
| 141 | $selectorOptions = $childRecordUids = $childHtml = []; |
||
| 142 | |||
| 143 | foreach ($config['uniquePossibleRecords'] ?? [] as $record) { |
||
| 144 | // Do not add the PHP_INT_MAX placeholder or already configured languages |
||
| 145 | if ($record[1] !== PHP_INT_MAX && !in_array($record[1], $uniqueIds, true)) { |
||
| 146 | $selectorOptions[] = ['value' => (string)$record[1], 'label' => (string)$record[0]]; |
||
| 147 | } |
||
| 148 | } |
||
| 149 | |||
| 150 | foreach ($this->data['parameterArray']['fieldConf']['children'] as $children) { |
||
| 151 | $children['inlineParentUid'] = $row['uid']; |
||
| 152 | $children['inlineFirstPid'] = $this->data['inlineFirstPid']; |
||
| 153 | $children['inlineParentConfig'] = $config; |
||
| 154 | $children['inlineData'] = $this->inlineData; |
||
| 155 | $children['inlineStructure'] = $this->inlineStackProcessor->getStructure(); |
||
| 156 | $children['inlineExpandCollapseStateArray'] = $this->data['inlineExpandCollapseStateArray']; |
||
| 157 | $children['renderType'] = 'inlineRecordContainer'; |
||
| 158 | $childResult = $this->nodeFactory->create($children)->render(); |
||
| 159 | $childHtml[] = $childResult['html']; |
||
| 160 | $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childResult, false); |
||
| 161 | if (isset($children['databaseRow']['uid'])) { |
||
| 162 | $childRecordUids[] = $children['databaseRow']['uid']; |
||
| 163 | } |
||
| 164 | } |
||
| 165 | |||
| 166 | $view = GeneralUtility::makeInstance(StandaloneView::class); |
||
| 167 | $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName( |
||
| 168 | 'EXT:backend/Resources/Private/Templates/SiteLanguageContainer.html' |
||
| 169 | )); |
||
| 170 | $view->assignMultiple([ |
||
| 171 | 'nameObject' => $nameObject, |
||
| 172 | 'nameForm' => $nameForm, |
||
| 173 | 'formGroupAttributes' => GeneralUtility::implodeAttributes([ |
||
| 174 | 'class' => 'form-group', |
||
| 175 | 'id' => $nameObject, |
||
| 176 | 'data-uid' => (string)$row['uid'], |
||
| 177 | 'data-local-table' => (string)$top['table'], |
||
| 178 | 'data-local-field' => (string)$top['field'], |
||
| 179 | 'data-foreign-table' => self::FOREIGN_TABLE, |
||
| 180 | 'data-object-group' => $nameObject . '-' . self::FOREIGN_TABLE, |
||
| 181 | 'data-form-field' => $nameForm, |
||
| 182 | 'data-appearance' => (string)json_encode($config['appearance'] ?? ''), |
||
| 183 | ], true), |
||
| 184 | 'fieldInformation' => $fieldInformationResult['html'], |
||
| 185 | 'selectorConfigutation' => [ |
||
| 186 | 'identifier' => $nameObject . '-' . self::FOREIGN_TABLE . '_selector', |
||
| 187 | 'size' => $config['size'] ?? 4, |
||
| 188 | 'options' => $selectorOptions |
||
| 189 | ], |
||
| 190 | 'inlineRecords' => [ |
||
| 191 | 'identifier' => $nameObject . '_records', |
||
| 192 | 'title' => trim($parameterArray['fieldConf']['label'] ?? ''), |
||
| 193 | 'records' => implode(PHP_EOL, $childHtml) |
||
| 194 | ], |
||
| 195 | 'childRecordUids' => implode(',', $childRecordUids), |
||
| 196 | 'validationRules' => $this->getValidationDataAsJsonString([ |
||
| 197 | 'type' => 'inline', |
||
| 198 | 'minitems' => $config['minitems'] ?? null, |
||
| 199 | 'maxitems' => $config['maxitems'] ?? null, |
||
| 200 | ]), |
||
| 201 | ]); |
||
| 202 | |||
| 203 | $resultArray['html'] = $view->render(); |
||
| 204 | $resultArray['requireJsModules'][] = 'TYPO3/CMS/Backend/FormEngine/Container/SiteLanguageContainer'; |
||
| 205 | |||
| 206 | return $resultArray; |
||
| 207 | } |
||
| 209 |