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