‪TYPO3CMS  ‪main
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 
23 
32 {
33  public function ‪__construct(
34  private readonly ‪BackendLayoutView $backendLayoutView,
35  ) {}
36 
42  public function ‪render(): array
43  {
44  if ($this->data['tableName'] !== 'pages' || $this->data['fieldName'] !== 'backend_layout') {
45  throw new \RuntimeException(
46  'The backendLayoutFromParentPage field information can only be used for the backend_layout field of the pages table.',
47  1622109821
48  );
49  }
50 
51  $resultArray = $this->‪initializeResultArray();
52  $parameterArray = $this->data['parameterArray'];
53 
54  // In case the backend_layout field of the current page is not empty, no backend layout will be inherited.
55  if (!empty($parameterArray['itemFormElValue'])) {
56  return $resultArray;
57  }
58 
59  $backendLayoutInformation = '';
60  $languageService = $this->‪getLanguageService();
61 
62  if ($this->data['command'] === 'new') {
63  // In case we deal with a new record, we try to find a possible inherited backend layout in
64  // the rootline. Since there might be further actions, e.g. DataHandler hooks, the actually
65  // resolved backend layout can only be determined, once the record is saved. For now we just
66  // inform about the backend layout, which will most likely be used.
67  foreach ($this->data['rootline'] as $page) {
68  if (!empty($page['backend_layout_next_level']) && ($page['uid'] ?? false)) {
69  $backendLayoutInformation = sprintf(
70  $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:formEngine.pages.backendLayout.information.inheritFromParentPage'),
71  $this->getFieldValueLabel($parameterArray['fieldConf'], $page['backend_layout_next_level'])
72  );
73  break;
74  }
75  }
76  } else {
77  // Get the resolved backend layout for the current page.
78  $backendLayout = $this->backendLayoutView->getBackendLayoutForPage(
79  (int)($this->data['databaseRow']['uid'] ?? $this->data['effectivePid'] ?? 0)
80  );
81  if ($backendLayout !== null) {
82  $backendLayoutInformation = sprintf(
83  $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:formEngine.pages.backendLayout.information.inheritedFromParentPage'),
84  $languageService->sL($backendLayout->getTitle())
85  );
86  }
87  }
88 
89  if ($backendLayoutInformation !== '') {
90  $resultArray['html'] = '<p class="text-body-secondary">' . htmlspecialchars($backendLayoutInformation) . '</p>';
91  }
92 
93  return $resultArray;
94  }
95 
96  protected function ‪getFieldValueLabel(array $fieldConfiguration, string $fieldValue): string
97  {
98  foreach ($fieldConfiguration['config']['items'] as $item) {
99  if (($item['value'] ?? '') === $fieldValue && !empty($item['label'])) {
100  return $item['label'];
101  }
102  }
103 
104  $invalidValue = sprintf(
105  $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.noMatchingValue'),
106  $fieldValue
107  );
108 
109  return '[ ' . $invalidValue . ' ]';
110  }
111 
113  {
114  return ‪$GLOBALS['LANG'];
115  }
116 }
‪TYPO3\CMS\Backend\Form\FieldInformation\BackendLayoutFromParentPage\getLanguageService
‪getLanguageService()
Definition: BackendLayoutFromParentPage.php:112
‪TYPO3\CMS\Backend\Form\FieldInformation\BackendLayoutFromParentPage
Definition: BackendLayoutFromParentPage.php:32
‪TYPO3\CMS\Backend\Form\FieldInformation\BackendLayoutFromParentPage\getFieldValueLabel
‪getFieldValueLabel(array $fieldConfiguration, string $fieldValue)
Definition: BackendLayoutFromParentPage.php:96
‪TYPO3\CMS\Backend\Form\FieldInformation
Definition: AdminIsSystemMaintainer.php:18
‪TYPO3\CMS\Backend\Form\FieldInformation\BackendLayoutFromParentPage\__construct
‪__construct(private readonly BackendLayoutView $backendLayoutView,)
Definition: BackendLayoutFromParentPage.php:33
‪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:46
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:29
‪TYPO3\CMS\Backend\Form\FieldInformation\BackendLayoutFromParentPage\render
‪array render()
Definition: BackendLayoutFromParentPage.php:42
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪initializeResultArray()
Definition: AbstractNode.php:77