data['tableName'] !== 'pages' || $this->data['fieldName'] !== 'backend_layout') { throw new \RuntimeException( 'The backendLayoutFromParentPage field information can only be used for the backend_layout field of the pages table.', 1622109821 ); } $resultArray = $this->initializeResultArray(); $parameterArray = $this->data['parameterArray']; // In case the backend_layout field of the current page is not empty, no backend layout will be inherited. if (!empty($parameterArray['itemFormElValue'])) { return $resultArray; } $backendLayoutInformation = ''; $languageService = $this->getLanguageService(); if ($this->data['command'] === 'new') { // In case we deal with a new record, we try to find a possible inherited backend layout in // the rootline. Since there might be further actions, e.g. DataHandler hooks, the actually // resolved backend layout can only be determined, once the record is saved. For now we just // inform about the backend layout, which will most likely be used. foreach ($this->data['rootline'] as $page) { if (!empty($page['backend_layout_next_level']) && ($page['uid'] ?? false)) { $backendLayoutInformation = sprintf( $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:formEngine.pages.backendLayout.information.inheritFromParentPage'), $this->getFieldValueLabel($parameterArray['fieldConf'], $page['backend_layout_next_level']) ); break; } } } else { // Get the resolved backend layout for the current page. $backendLayout = $this->backendLayoutView->getBackendLayoutForPage((int)($this->data['databaseRow']['uid'] ?? $this->data['effectivePid'] ?? 0)); $backendLayoutInformation = sprintf( $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:formEngine.pages.backendLayout.information.inheritedFromParentPage'), $languageService->sL($backendLayout->getTitle()) ); } if ($backendLayoutInformation !== '') { $resultArray['html'] = '
' . htmlspecialchars($backendLayoutInformation) . '
'; } return $resultArray; } protected function getFieldValueLabel(array $fieldConfiguration, string $fieldValue): string { foreach ($fieldConfiguration['config']['items'] as $item) { if (($item['value'] ?? '') === $fieldValue && !empty($item['label'])) { return $item['label']; } } $invalidValue = sprintf( $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.noMatchingValue'), $fieldValue ); return '[ ' . $invalidValue . ' ]'; } protected function getLanguageService(): LanguageService { return $GLOBALS['LANG']; } }