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