| Conditions | 10 |
| Paths | 12 |
| Total Lines | 53 |
| Code Lines | 28 |
| 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 |
||
| 39 | public function render(): array |
||
| 40 | { |
||
| 41 | if ($this->data['tableName'] !== 'pages' || $this->data['fieldName'] !== 'backend_layout') { |
||
| 42 | throw new \RuntimeException( |
||
| 43 | 'The backendLayoutFromParentPage field information can only be used for the backend_layout field of the pages table.', |
||
| 44 | 1622109821 |
||
| 45 | ); |
||
| 46 | } |
||
| 47 | |||
| 48 | $resultArray = $this->initializeResultArray(); |
||
| 49 | $parameterArray = $this->data['parameterArray']; |
||
| 50 | |||
| 51 | // In case the backend_layout field of the current page is not empty, no backend layout will be inherited. |
||
| 52 | if (!empty($parameterArray['itemFormElValue'])) { |
||
| 53 | return $resultArray; |
||
| 54 | } |
||
| 55 | |||
| 56 | $backendLayoutInformation = ''; |
||
| 57 | $languageService = $this->getLanguageService(); |
||
| 58 | |||
| 59 | if ($this->data['command'] === 'new') { |
||
| 60 | // In case we deal with a new record, we try to find a possible inherited backend layout in |
||
| 61 | // the rootline. Since there might be further actions, e.g. DataHandler hooks, the actually |
||
| 62 | // resolved backend layout can only be determined, once the record is saved. For now we just |
||
| 63 | // inform about the backend layout, which will most likely be used. |
||
| 64 | foreach ($this->data['rootline'] as $page) { |
||
| 65 | if (!empty($page['backend_layout_next_level']) && ($page['uid'] ?? false)) { |
||
| 66 | $backendLayoutInformation = sprintf( |
||
| 67 | $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:formEngine.pages.backendLayout.information.inheritFromParentPage'), |
||
| 68 | $this->getFieldValueLabel($parameterArray['fieldConf'], $page['backend_layout_next_level']) |
||
| 69 | ); |
||
| 70 | break; |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } else { |
||
| 74 | // Get the resolved backend layout for the current page. |
||
| 75 | $backendLayoutView = GeneralUtility::makeInstance(BackendLayoutView::class); |
||
| 76 | $backendLayout = $backendLayoutView->getBackendLayoutForPage( |
||
| 77 | $this->data['databaseRow']['uid'] ?? $this->data['effectivePid'] ?? 0 |
||
| 78 | ); |
||
| 79 | if ($backendLayout !== null) { |
||
| 80 | $backendLayoutInformation = sprintf( |
||
| 81 | $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:formEngine.pages.backendLayout.information.inheritedFromParentPage'), |
||
| 82 | $languageService->sL($backendLayout->getTitle()) |
||
| 83 | ); |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | if ($backendLayoutInformation !== '') { |
||
| 88 | $resultArray['html'] = '<p class="text-muted">' . htmlspecialchars($backendLayoutInformation) . '</p>'; |
||
| 89 | } |
||
| 90 | |||
| 91 | return $resultArray; |
||
| 92 | } |
||
| 115 |