‪TYPO3CMS  11.5
BackendLayoutFromParentPage.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
24 
33 {
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  (int)($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  }
93 
94  protected function ‪getFieldValueLabel(array $fieldConfiguration, string $fieldValue): string
95  {
96  foreach ($fieldConfiguration['config']['items'] as $item) {
97  if (($item[1] ?? '') === $fieldValue && !empty($item[0])) {
98  return $item[0];
99  }
100  }
101 
102  $invalidValue = sprintf(
103  $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.noMatchingValue'),
104  $fieldValue
105  );
106 
107  return '[ ' . $invalidValue . ' ]';
108  }
109 
111  {
112  return ‪$GLOBALS['LANG'];
113  }
114 }
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:91
‪TYPO3\CMS\Backend\Form\FieldInformation\BackendLayoutFromParentPage\getLanguageService
‪getLanguageService()
Definition: BackendLayoutFromParentPage.php:110
‪TYPO3\CMS\Backend\Form\FieldInformation\BackendLayoutFromParentPage
Definition: BackendLayoutFromParentPage.php:33
‪TYPO3\CMS\Backend\Form\FieldInformation\BackendLayoutFromParentPage\getFieldValueLabel
‪getFieldValueLabel(array $fieldConfiguration, string $fieldValue)
Definition: BackendLayoutFromParentPage.php:94
‪TYPO3\CMS\Backend\Form\FieldInformation
Definition: AdminIsSystemMaintainer.php:18
‪TYPO3\CMS\Backend\View\BackendLayoutView
Definition: BackendLayoutView.php:37
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\Form\FieldInformation\BackendLayoutFromParentPage\render
‪array render()
Definition: BackendLayoutFromParentPage.php:39