| Conditions | 28 |
| Paths | 5184 |
| Total Lines | 195 |
| Code Lines | 135 |
| 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 |
||
| 138 | public function getRowDetails($parameter) |
||
| 139 | { |
||
| 140 | $diffReturnArray = []; |
||
| 141 | $liveReturnArray = []; |
||
| 142 | $diffUtility = $this->getDifferenceHandler(); |
||
| 143 | $liveRecord = (array)BackendUtility::getRecord($parameter->table, $parameter->t3ver_oid); |
||
| 144 | $versionRecord = (array)BackendUtility::getRecord($parameter->table, $parameter->uid); |
||
| 145 | $versionState = VersionState::cast((int)($versionRecord['t3ver_state'] ?? 0)); |
||
| 146 | $iconFactory = GeneralUtility::makeInstance(IconFactory::class); |
||
| 147 | $icon_Live = $iconFactory->getIconForRecord($parameter->table, $liveRecord, Icon::SIZE_SMALL)->render(); |
||
| 148 | $icon_Workspace = $iconFactory->getIconForRecord($parameter->table, $versionRecord, Icon::SIZE_SMALL)->render(); |
||
| 149 | $stagePosition = $this->stagesService->getPositionOfCurrentStage($parameter->stage); |
||
| 150 | $fieldsOfRecords = array_keys($liveRecord); |
||
| 151 | $isNewOrDeletePlaceholder = $versionState->equals(VersionState::NEW_PLACEHOLDER) || $versionState->equals(VersionState::DELETE_PLACEHOLDER); |
||
| 152 | $suitableFields = ($isNewOrDeletePlaceholder && ($parameter->filterFields ?? false)) ? array_flip($this->getSuitableFields($parameter->table, $parameter->t3ver_oid)) : []; |
||
| 153 | foreach ($fieldsOfRecords as $fieldName) { |
||
| 154 | if ( |
||
| 155 | empty($GLOBALS['TCA'][$parameter->table]['columns'][$fieldName]['config']) |
||
| 156 | ) { |
||
| 157 | continue; |
||
| 158 | } |
||
| 159 | // Disable internal fields |
||
| 160 | if (($GLOBALS['TCA'][$parameter->table]['ctrl']['transOrigDiffSourceField'] ?? '') === $fieldName) { |
||
| 161 | continue; |
||
| 162 | } |
||
| 163 | if (($GLOBALS['TCA'][$parameter->table]['ctrl']['origUid'] ?? '') === $fieldName) { |
||
| 164 | continue; |
||
| 165 | } |
||
| 166 | // Get the field's label. If not available, use the field name |
||
| 167 | $fieldTitle = $this->getLanguageService()->sL(BackendUtility::getItemLabel($parameter->table, $fieldName)); |
||
| 168 | if (empty($fieldTitle)) { |
||
| 169 | $fieldTitle = $fieldName; |
||
| 170 | } |
||
| 171 | // Gets the TCA configuration for the current field |
||
| 172 | $configuration = $GLOBALS['TCA'][$parameter->table]['columns'][$fieldName]['config']; |
||
| 173 | // check for exclude fields |
||
| 174 | if ($this->getBackendUser()->isAdmin() || $GLOBALS['TCA'][$parameter->table]['columns'][$fieldName]['exclude'] == 0 || GeneralUtility::inList($this->getBackendUser()->groupData['non_exclude_fields'], $parameter->table . ':' . $fieldName)) { |
||
| 175 | // call diff class only if there is a difference |
||
| 176 | if ($configuration['type'] === 'inline' && $configuration['foreign_table'] === 'sys_file_reference') { |
||
| 177 | $useThumbnails = false; |
||
| 178 | if (!empty($configuration['overrideChildTca']['columns']['uid_local']['config']['appearance']['elementBrowserAllowed']) && !empty($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'])) { |
||
| 179 | $fileExtensions = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], true); |
||
| 180 | $allowedExtensions = GeneralUtility::trimExplode(',', $configuration['overrideChildTca']['columns']['uid_local']['config']['appearance']['elementBrowserAllowed'], true); |
||
| 181 | $differentExtensions = array_diff($allowedExtensions, $fileExtensions); |
||
| 182 | $useThumbnails = empty($differentExtensions); |
||
| 183 | } |
||
| 184 | |||
| 185 | $liveFileReferences = (array)BackendUtility::resolveFileReferences( |
||
| 186 | $parameter->table, |
||
| 187 | $fieldName, |
||
| 188 | $liveRecord, |
||
| 189 | 0 |
||
| 190 | ); |
||
| 191 | $versionFileReferences = (array)BackendUtility::resolveFileReferences( |
||
| 192 | $parameter->table, |
||
| 193 | $fieldName, |
||
| 194 | $versionRecord, |
||
| 195 | $this->getCurrentWorkspace() |
||
| 196 | ); |
||
| 197 | $fileReferenceDifferences = $this->prepareFileReferenceDifferences( |
||
| 198 | $liveFileReferences, |
||
| 199 | $versionFileReferences, |
||
| 200 | $useThumbnails |
||
| 201 | ); |
||
| 202 | |||
| 203 | if ($fileReferenceDifferences === null) { |
||
| 204 | continue; |
||
| 205 | } |
||
| 206 | |||
| 207 | $diffReturnArray[] = [ |
||
| 208 | 'field' => $fieldName, |
||
| 209 | 'label' => $fieldTitle, |
||
| 210 | 'content' => $fileReferenceDifferences['differences'] |
||
| 211 | ]; |
||
| 212 | $liveReturnArray[] = [ |
||
| 213 | 'field' => $fieldName, |
||
| 214 | 'label' => $fieldTitle, |
||
| 215 | 'content' => $fileReferenceDifferences['live'] |
||
| 216 | ]; |
||
| 217 | } elseif ($isNewOrDeletePlaceholder && isset($suitableFields[$fieldName])) { |
||
| 218 | // If this is a new or delete placeholder, add diff view for all appropriate fields |
||
| 219 | $newOrDeleteRecord[$fieldName] = BackendUtility::getProcessedValue( |
||
| 220 | $parameter->table, |
||
| 221 | $fieldName, |
||
| 222 | $liveRecord[$fieldName], // Both (live and version) values are the same |
||
| 223 | 0, |
||
| 224 | true, |
||
| 225 | false, |
||
| 226 | $liveRecord['uid'] // Relations of new/delete placeholder do always contain the live uid |
||
| 227 | ) ?? ''; |
||
| 228 | |||
| 229 | // Don't add empty fields |
||
| 230 | if ($newOrDeleteRecord[$fieldName] === '') { |
||
| 231 | continue; |
||
| 232 | } |
||
| 233 | |||
| 234 | $diffReturnArray[] = [ |
||
| 235 | 'field' => $fieldName, |
||
| 236 | 'label' => $fieldTitle, |
||
| 237 | 'content' => $versionState->equals(VersionState::NEW_PLACEHOLDER) |
||
| 238 | ? $diffUtility->makeDiffDisplay('', $newOrDeleteRecord[$fieldName]) |
||
| 239 | : $diffUtility->makeDiffDisplay($newOrDeleteRecord[$fieldName], '') |
||
| 240 | ]; |
||
| 241 | |||
| 242 | // Generally not needed by Core, but let's make it available for further processing in hooks |
||
| 243 | $liveReturnArray[] = [ |
||
| 244 | 'field' => $fieldName, |
||
| 245 | 'label' => $fieldTitle, |
||
| 246 | 'content' => $newOrDeleteRecord[$fieldName] |
||
| 247 | ]; |
||
| 248 | } elseif ((string)$liveRecord[$fieldName] !== (string)$versionRecord[$fieldName]) { |
||
| 249 | // Select the human readable values before diff |
||
| 250 | $liveRecord[$fieldName] = BackendUtility::getProcessedValue( |
||
| 251 | $parameter->table, |
||
| 252 | $fieldName, |
||
| 253 | $liveRecord[$fieldName], |
||
| 254 | 0, |
||
| 255 | true, |
||
| 256 | false, |
||
| 257 | $liveRecord['uid'] |
||
| 258 | ); |
||
| 259 | $versionRecord[$fieldName] = BackendUtility::getProcessedValue( |
||
| 260 | $parameter->table, |
||
| 261 | $fieldName, |
||
| 262 | $versionRecord[$fieldName], |
||
| 263 | 0, |
||
| 264 | true, |
||
| 265 | false, |
||
| 266 | $versionRecord['uid'] |
||
| 267 | ); |
||
| 268 | |||
| 269 | $diffReturnArray[] = [ |
||
| 270 | 'field' => $fieldName, |
||
| 271 | 'label' => $fieldTitle, |
||
| 272 | 'content' => $diffUtility->makeDiffDisplay($liveRecord[$fieldName], $versionRecord[$fieldName]) |
||
| 273 | ]; |
||
| 274 | $liveReturnArray[] = [ |
||
| 275 | 'field' => $fieldName, |
||
| 276 | 'label' => $fieldTitle, |
||
| 277 | 'content' => $liveRecord[$fieldName] |
||
| 278 | ]; |
||
| 279 | } |
||
| 280 | } |
||
| 281 | } |
||
| 282 | // Hook for modifying the difference and live arrays |
||
| 283 | // (this may be used by custom or dynamically-defined fields) |
||
| 284 | foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['workspaces']['modifyDifferenceArray'] ?? [] as $className) { |
||
| 285 | $hookObject = GeneralUtility::makeInstance($className); |
||
| 286 | if (method_exists($hookObject, 'modifyDifferenceArray')) { |
||
| 287 | $hookObject->modifyDifferenceArray($parameter, $diffReturnArray, $liveReturnArray, $diffUtility); |
||
| 288 | } |
||
| 289 | } |
||
| 290 | $commentsForRecord = $this->getCommentsForRecord($parameter->uid, $parameter->table); |
||
| 291 | |||
| 292 | $historyService = GeneralUtility::makeInstance(HistoryService::class); |
||
| 293 | $history = $historyService->getHistory($parameter->table, $parameter->t3ver_oid); |
||
| 294 | |||
| 295 | if ($this->stagesService->isPrevStageAllowedForUser($parameter->stage)) { |
||
| 296 | $prevStage = $this->stagesService->getPrevStage($parameter->stage); |
||
| 297 | if (isset($prevStage[0])) { |
||
| 298 | $prevStage = current($prevStage); |
||
|
|
|||
| 299 | } |
||
| 300 | } |
||
| 301 | if ($this->stagesService->isNextStageAllowedForUser($parameter->stage)) { |
||
| 302 | $nextStage = $this->stagesService->getNextStage($parameter->stage); |
||
| 303 | if (isset($nextStage[0])) { |
||
| 304 | $nextStage = current($nextStage); |
||
| 305 | } |
||
| 306 | } |
||
| 307 | |||
| 308 | return [ |
||
| 309 | 'total' => 1, |
||
| 310 | 'data' => [ |
||
| 311 | [ |
||
| 312 | // these parts contain HTML (don't escape) |
||
| 313 | 'diff' => $diffReturnArray, |
||
| 314 | 'live_record' => $liveReturnArray, |
||
| 315 | 'icon_Live' => $icon_Live, |
||
| 316 | 'icon_Workspace' => $icon_Workspace, |
||
| 317 | // this part is already escaped in getCommentsForRecord() |
||
| 318 | 'comments' => $commentsForRecord, |
||
| 319 | // escape/sanitize the others |
||
| 320 | 'path_Live' => htmlspecialchars(BackendUtility::getRecordPath($liveRecord['pid'], '', 999)), |
||
| 321 | 'label_Stage' => htmlspecialchars($this->stagesService->getStageTitle($parameter->stage)), |
||
| 322 | 'label_PrevStage' => $prevStage ?? false, |
||
| 323 | 'label_NextStage' => $nextStage ?? false, |
||
| 324 | 'stage_position' => (int)$stagePosition['position'], |
||
| 325 | 'stage_count' => (int)$stagePosition['count'], |
||
| 326 | 'parent' => [ |
||
| 327 | 'table' => htmlspecialchars($parameter->table), |
||
| 328 | 'uid' => (int)$parameter->uid |
||
| 329 | ], |
||
| 330 | 'history' => [ |
||
| 331 | 'data' => $history, |
||
| 332 | 'total' => count($history) |
||
| 333 | ] |
||
| 622 |