‪TYPO3CMS  ‪main
BackendLayoutRenderer.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 
20 use Psr\Http\Message\ServerRequestInterface;
36 
47 {
48  public function ‪__construct(
49  protected readonly ‪BackendViewFactory $backendViewFactory,
50  protected readonly ‪RecordRememberer $recordRememberer
51  ) {}
52 
54  {
55  $contentFetcher = GeneralUtility::makeInstance(ContentFetcher::class, $context);
56  $grid = GeneralUtility::makeInstance(Grid::class, $context);
57  if ($context->‪getDrawingConfiguration()->isLanguageComparisonMode()) {
58  $languageId = $context->‪getSiteLanguage()->getLanguageId();
59  } else {
60  $languageId = $context->‪getDrawingConfiguration()->getSelectedLanguageId();
61  }
62  $rows = $context->‪getBackendLayout()->getStructure()['__config']['backend_layout.']['rows.'] ?? [];
63  ksort($rows);
64  foreach ($rows as $row) {
65  $rowObject = GeneralUtility::makeInstance(GridRow::class, $context);
66  foreach ($row['columns.'] as $column) {
67  $columnObject = GeneralUtility::makeInstance(GridColumn::class, $context, $column);
68  $rowObject->addColumn($columnObject);
69  if (isset($column['colPos'])) {
70  $records = $contentFetcher->getContentRecordsPerColumn((int)$column['colPos'], $languageId);
71  $this->recordRememberer->rememberRecords($records);
72  foreach ($records as $contentRecord) {
73  $columnItem = GeneralUtility::makeInstance(GridColumnItem::class, $context, $columnObject, $contentRecord);
74  $columnObject->addItem($columnItem);
75  }
76  }
77  }
78  $grid->addRow($rowObject);
79  }
80  return $grid;
81  }
82 
86  public function ‪drawContent(ServerRequestInterface $request, ‪PageLayoutContext $pageLayoutContext, bool $renderUnused = true): string
87  {
88  $backendUser = $this->‪getBackendUser();
89  $contentFetcher = GeneralUtility::makeInstance(ContentFetcher::class, $pageLayoutContext);
90 
91  $view = $this->backendViewFactory->create($request);
92  $view->assignMultiple([
93  'context' => $pageLayoutContext,
94  'hideRestrictedColumns' => $pageLayoutContext->‪getDrawingConfiguration()->shouldHideRestrictedColumns(),
95  'allowEditContent' => $backendUser->check('tables_modify', 'tt_content'),
96  'maxTitleLength' => $backendUser->uc['titleLen'] ?? 20,
97  ]);
98 
99  if ($pageLayoutContext->‪getDrawingConfiguration()->isLanguageComparisonMode()) {
100  if ($pageLayoutContext->‪getDrawingConfiguration()->getDefaultLanguageBinding()) {
101  $view->assign('languageColumns', $this->‪getLanguageColumnsWithDefLangBindingForPageLayoutContext($pageLayoutContext));
102  } else {
103  $view->assign('languageColumns', $this->‪getLanguageColumnsForPageLayoutContext($pageLayoutContext));
104  }
105  } else {
106  $context = $pageLayoutContext;
107  // Check if we have to use a localized context for grid creation
108  if ($pageLayoutContext->‪getDrawingConfiguration()->getSelectedLanguageId() > 0) {
109  // In case a localization is selected, clone the context with this language
110  $localizedContext = $pageLayoutContext->‪cloneForLanguage(
111  $pageLayoutContext->‪getSiteLanguage($pageLayoutContext->‪getDrawingConfiguration()->getSelectedLanguageId())
112  );
113  if ($localizedContext->getLocalizedPageRecord()) {
114  // In case the localized context contains the corresponding
115  // localized page record use this context for grid creation.
116  $context = $localizedContext;
117  }
118  }
119  $grid = $this->‪getGridForPageLayoutContext($context);
120  $view->assign('grid', $grid);
121  $view->assign('gridColumns', array_fill(1, $grid->getContext()->getBackendLayout()->getColCount(), null));
122  }
123 
124  $rendered = $view->render('PageLayout/PageLayout');
125  if ($renderUnused) {
126  $unusedRecords = $contentFetcher->getUnusedRecords();
127 
128  if (!empty($unusedRecords)) {
129  $unusedElementsMessage = GeneralUtility::makeInstance(
130  FlashMessage::class,
131  $this->‪getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:staleUnusedElementsWarning'),
132  $this->‪getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:staleUnusedElementsWarningTitle'),
133  ContextualFeedbackSeverity::WARNING
134  );
135  $service = GeneralUtility::makeInstance(FlashMessageService::class);
136  $queue = $service->getMessageQueueByIdentifier();
137  $queue->addMessage($unusedElementsMessage);
138 
139  $unusedGrid = GeneralUtility::makeInstance(Grid::class, $pageLayoutContext);
140  $unusedRow = GeneralUtility::makeInstance(GridRow::class, $pageLayoutContext);
141  $unusedColumn = GeneralUtility::makeInstance(GridColumn::class, $pageLayoutContext, ['name' => 'unused']);
142 
143  $unusedGrid->addRow($unusedRow);
144  $unusedRow->addColumn($unusedColumn);
145 
146  foreach ($unusedRecords as $unusedRecord) {
147  $item = GeneralUtility::makeInstance(GridColumnItem::class, $pageLayoutContext, $unusedColumn, $unusedRecord);
148  $unusedColumn->addItem($item);
149  }
150 
151  $view->assign('grid', $unusedGrid);
152  $view->assign('gridColumns', null);
153  $rendered .= $view->render('PageLayout/UnusedRecords');
154  }
155  }
156  return $rendered;
157  }
158 
163  {
164  $contentFetcher = GeneralUtility::makeInstance(ContentFetcher::class, $context);
165  $languageColumns = [];
166  foreach ($context->‪getLanguagesToShow() as $siteLanguage) {
167  $localizedLanguageId = $siteLanguage->getLanguageId();
168  if ($localizedLanguageId === -1) {
169  continue;
170  }
171  if ($localizedLanguageId > 0) {
172  $localizedContext = $context->‪cloneForLanguage($siteLanguage);
173  if (!$localizedContext->getLocalizedPageRecord()) {
174  continue;
175  }
176  } else {
177  $localizedContext = $context;
178  }
179  $translationInfo = $contentFetcher->getTranslationData(
180  $contentFetcher->getFlatContentRecords($localizedLanguageId),
181  $localizedContext->getSiteLanguage()->getLanguageId()
182  );
183  $languageColumnObject = GeneralUtility::makeInstance(
184  LanguageColumn::class,
185  $localizedContext,
186  $this->‪getGridForPageLayoutContext($localizedContext),
187  $translationInfo
188  );
189  $languageColumns[] = $languageColumnObject;
190  }
191  return $languageColumns;
192  }
193 
195  {
196  $contentFetcher = GeneralUtility::makeInstance(ContentFetcher::class, $context);
197  $languageColumns = [];
198 
199  // default language
200  $translationInfo = $contentFetcher->getTranslationData(
201  $contentFetcher->getFlatContentRecords(0),
202  0
203  );
204 
205  $defaultLanguageColumnObject = GeneralUtility::makeInstance(
206  LanguageColumn::class,
207  $context,
208  $this->‪getGridForPageLayoutContext($context),
209  $translationInfo
210  );
211  foreach ($context->‪getLanguagesToShow() as $siteLanguage) {
212  $localizedLanguageId = $siteLanguage->getLanguageId();
213  if ($localizedLanguageId <= 0) {
214  continue;
215  }
216 
217  $localizedContext = $context->‪cloneForLanguage($siteLanguage);
218  if (!$localizedContext->getLocalizedPageRecord()) {
219  continue;
220  }
221 
222  $translationInfo = $contentFetcher->getTranslationData(
223  $contentFetcher->getFlatContentRecords($localizedLanguageId),
224  $localizedContext->getSiteLanguage()->getLanguageId()
225  );
226 
227  $translatedRows = $contentFetcher->getFlatContentRecords($localizedLanguageId);
228 
229  foreach ($defaultLanguageColumnObject->getGrid()->getRows() as $rows) {
230  foreach ($rows->getColumns() as $column) {
231  if (($translationInfo['mode'] ?? '') === 'connected') {
232  foreach ($column->getItems() as $item) {
233  // check if translation exists
234  foreach ($translatedRows as $translation) {
235  if ($translation['l18n_parent'] === $item->getRecord()['uid']) {
236  $translatedItem = GeneralUtility::makeInstance(GridColumnItem::class, $localizedContext, $column, $translation);
237  $item->addTranslation($localizedLanguageId, $translatedItem);
238  }
239  }
240  }
241  }
242  }
243  }
244 
245  $languageColumnObject = GeneralUtility::makeInstance(
246  LanguageColumn::class,
247  $localizedContext,
248  $this->‪getGridForPageLayoutContext($localizedContext),
249  $translationInfo
250  );
251  $languageColumns[$localizedLanguageId] = $languageColumnObject;
252  }
253  return [$defaultLanguageColumnObject] + $languageColumns;
254  }
255 
257  {
258  return ‪$GLOBALS['BE_USER'];
259  }
260 
262  {
263  return ‪$GLOBALS['LANG'];
264  }
265 }
‪TYPO3\CMS\Backend\View\Drawing\BackendLayoutRenderer\drawContent
‪drawContent(ServerRequestInterface $request, PageLayoutContext $pageLayoutContext, bool $renderUnused=true)
Definition: BackendLayoutRenderer.php:86
‪TYPO3\CMS\Backend\View\PageLayoutContext\getLanguagesToShow
‪SiteLanguage[] getLanguagesToShow()
Definition: PageLayoutContext.php:144
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\Grid
Definition: Grid.php:39
‪TYPO3\CMS\Backend\View\Drawing\BackendLayoutRenderer\getLanguageColumnsWithDefLangBindingForPageLayoutContext
‪getLanguageColumnsWithDefLangBindingForPageLayoutContext(PageLayoutContext $context)
Definition: BackendLayoutRenderer.php:194
‪TYPO3\CMS\Backend\View\BackendViewFactory
Definition: BackendViewFactory.php:35
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridRow
Definition: GridRow.php:31
‪TYPO3\CMS\Backend\View\PageLayoutContext\getBackendLayout
‪getBackendLayout()
Definition: PageLayoutContext.php:108
‪TYPO3\CMS\Backend\View\BackendLayout\ContentFetcher
Definition: ContentFetcher.php:53
‪TYPO3\CMS\Core\Type\ContextualFeedbackSeverity
‪ContextualFeedbackSeverity
Definition: ContextualFeedbackSeverity.php:25
‪TYPO3\CMS\Backend\View\Drawing\BackendLayoutRenderer\getGridForPageLayoutContext
‪getGridForPageLayoutContext(PageLayoutContext $context)
Definition: BackendLayoutRenderer.php:53
‪TYPO3\CMS\Backend\View\Drawing\BackendLayoutRenderer\getLanguageColumnsForPageLayoutContext
‪LanguageColumn[] getLanguageColumnsForPageLayoutContext(PageLayoutContext $context)
Definition: BackendLayoutRenderer.php:162
‪TYPO3\CMS\Backend\View\PageLayoutContext\getSiteLanguage
‪getSiteLanguage(?int $languageId=null)
Definition: PageLayoutContext.php:169
‪TYPO3\CMS\Backend\View\Drawing\BackendLayoutRenderer
Definition: BackendLayoutRenderer.php:47
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\View\PageLayoutContext\cloneForLanguage
‪cloneForLanguage(SiteLanguage $language)
Definition: PageLayoutContext.php:83
‪TYPO3\CMS\Backend\View\Drawing\BackendLayoutRenderer\__construct
‪__construct(protected readonly BackendViewFactory $backendViewFactory, protected readonly RecordRememberer $recordRememberer)
Definition: BackendLayoutRenderer.php:48
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn
Definition: GridColumn.php:44
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:27
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\View\PageLayoutContext
Definition: PageLayoutContext.php:42
‪TYPO3\CMS\Backend\View\BackendLayout\RecordRememberer
Definition: RecordRememberer.php:26
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\LanguageColumn
Definition: LanguageColumn.php:46
‪TYPO3\CMS\Backend\View\Drawing\BackendLayoutRenderer\getLanguageService
‪getLanguageService()
Definition: BackendLayoutRenderer.php:261
‪TYPO3\CMS\Backend\View\Drawing\BackendLayoutRenderer\getBackendUser
‪getBackendUser()
Definition: BackendLayoutRenderer.php:256
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Backend\View\PageLayoutContext\getDrawingConfiguration
‪getDrawingConfiguration()
Definition: PageLayoutContext.php:113
‪TYPO3\CMS\Backend\View\Drawing
Definition: BackendLayoutRenderer.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem
Definition: GridColumnItem.php:45
‪TYPO3\CMS\Core\Messaging\FlashMessageService
Definition: FlashMessageService.php:27