|
12 | 12 | * of the License, or any later version. |
13 | 13 | */ |
14 | 14 |
|
15 | | -use B13\Container\Backend\Grid\ContainerGridColumn; |
16 | | -use B13\Container\Backend\Grid\ContainerGridColumnItem; |
17 | | -use B13\Container\Backend\Service\NewContentUrlBuilder; |
18 | | -use B13\Container\Domain\Factory\Exception; |
19 | | -use B13\Container\Domain\Factory\PageView\Backend\ContainerFactory; |
20 | | -use B13\Container\Events\BeforeContainerPreviewIsRenderedEvent; |
21 | | -use B13\Container\Tca\Registry; |
22 | | -use Psr\EventDispatcher\EventDispatcherInterface; |
| 15 | + |
23 | 16 | use TYPO3\CMS\Backend\Preview\StandardContentPreviewRenderer; |
24 | | -use TYPO3\CMS\Backend\Utility\BackendUtility; |
25 | | -use TYPO3\CMS\Backend\View\BackendLayout\Grid\Grid; |
26 | 17 | use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem; |
27 | | -use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridRow; |
28 | | -use TYPO3\CMS\Core\Utility\GeneralUtility; |
29 | | -use TYPO3\CMS\Fluid\View\StandaloneView; |
30 | 18 |
|
31 | 19 | class ContainerPreviewRenderer extends StandardContentPreviewRenderer |
32 | 20 | { |
33 | | - /** |
34 | | - * @var Registry |
35 | | - */ |
36 | | - protected $tcaRegistry; |
37 | | - |
38 | | - /** |
39 | | - * @var ContainerFactory |
40 | | - */ |
41 | | - protected $containerFactory; |
42 | | - |
43 | | - protected NewContentUrlBuilder $newContentUrlBuilder; |
| 21 | + protected GridRenderer $gridRenderer; |
44 | 22 |
|
45 | | - /** |
46 | | - * @var EventDispatcherInterface |
47 | | - */ |
48 | | - protected $eventDispatcher; |
49 | | - |
50 | | - public function __construct( |
51 | | - Registry $tcaRegistry, |
52 | | - ContainerFactory $containerFactory, |
53 | | - NewContentUrlBuilder $newContentUrlBuilder, |
54 | | - EventDispatcherInterface $eventDispatcher |
55 | | - ) { |
56 | | - $this->eventDispatcher = $eventDispatcher; |
57 | | - $this->tcaRegistry = $tcaRegistry; |
58 | | - $this->containerFactory = $containerFactory; |
59 | | - $this->newContentUrlBuilder = $newContentUrlBuilder; |
| 23 | + public function __construct(GridRenderer $gridRenderer) { |
| 24 | + $this->gridRenderer = $gridRenderer; |
60 | 25 | } |
61 | 26 |
|
62 | 27 | public function renderPageModulePreviewContent(GridColumnItem $item): string |
63 | 28 | { |
64 | | - $content = parent::renderPageModulePreviewContent($item); |
65 | | - $context = $item->getContext(); |
66 | 29 | $record = $item->getRecord(); |
67 | | - $grid = GeneralUtility::makeInstance(Grid::class, $context); |
68 | | - try { |
69 | | - $container = $this->containerFactory->buildContainer((int)$record['uid']); |
70 | | - } catch (Exception $e) { |
71 | | - // not a container |
72 | | - return $content; |
73 | | - } |
74 | | - $containerGrid = $this->tcaRegistry->getGrid($record['CType']); |
75 | | - foreach ($containerGrid as $cols) { |
76 | | - $rowObject = GeneralUtility::makeInstance(GridRow::class, $context); |
77 | | - foreach ($cols as $col) { |
78 | | - $defVals = $this->getDefValsForContentDefenderAllowsOnlyOneSpecificContentType($record['CType'], (int)$col['colPos']); |
79 | | - $url = $this->newContentUrlBuilder->getNewContentUrlAtTopOfColumn($context, $container, (int)$col['colPos'], $defVals); |
80 | | - $columnObject = GeneralUtility::makeInstance(ContainerGridColumn::class, $context, $col, $container, $url, $defVals !== null); |
81 | | - $rowObject->addColumn($columnObject); |
82 | | - if (isset($col['colPos'])) { |
83 | | - $records = $container->getChildrenByColPos($col['colPos']); |
84 | | - foreach ($records as $contentRecord) { |
85 | | - $url = $this->newContentUrlBuilder->getNewContentUrlAfterChild($context, $container, (int)$col['colPos'], (int)$contentRecord['uid'], $defVals); |
86 | | - $columnItem = GeneralUtility::makeInstance(ContainerGridColumnItem::class, $context, $columnObject, $contentRecord, $container, $url); |
87 | | - $columnObject->addItem($columnItem); |
88 | | - } |
89 | | - } |
90 | | - } |
91 | | - $grid->addRow($rowObject); |
92 | | - } |
93 | | - |
94 | | - $gridTemplate = $this->tcaRegistry->getGridTemplate($record['CType']); |
95 | | - $partialRootPaths = $this->tcaRegistry->getGridPartialPaths($record['CType']); |
96 | | - $layoutRootPaths = $this->tcaRegistry->getGridLayoutPaths($record['CType']); |
97 | | - $view = GeneralUtility::makeInstance(StandaloneView::class); |
98 | | - $view->setPartialRootPaths($partialRootPaths); |
99 | | - $view->setLayoutRootPaths($layoutRootPaths); |
100 | | - $view->setTemplatePathAndFilename($gridTemplate); |
101 | | - |
102 | | - $view->assign('hideRestrictedColumns', (bool)(BackendUtility::getPagesTSconfig($context->getPageId())['mod.']['web_layout.']['hideRestrictedCols'] ?? false)); |
103 | | - $view->assign('newContentTitle', $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newContentElement')); |
104 | | - $view->assign('newContentTitleShort', $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:content')); |
105 | | - $view->assign('allowEditContent', $this->getBackendUser()->check('tables_modify', 'tt_content')); |
106 | | - // keep compatibility |
107 | | - $view->assign('containerGrid', $grid); |
108 | | - $view->assign('grid', $grid); |
109 | | - $view->assign('containerRecord', $record); |
110 | | - $view->assign('context', $context); |
111 | | - $beforeContainerPreviewIsRendered = new BeforeContainerPreviewIsRenderedEvent($container, $view, $grid, $item); |
112 | | - $this->eventDispatcher->dispatch($beforeContainerPreviewIsRendered); |
113 | | - $rendered = $view->render(); |
114 | | - |
115 | | - return $content . $rendered; |
116 | | - } |
117 | | - |
118 | | - protected function getDefValsForContentDefenderAllowsOnlyOneSpecificContentType(string $cType, int $colPos): ?array |
119 | | - { |
120 | | - $contentDefefenderConfiguration = $this->tcaRegistry->getContentDefenderConfiguration($cType, $colPos); |
121 | | - $allowedCTypes = GeneralUtility::trimExplode(',', $contentDefefenderConfiguration['allowed.']['CType'] ?? '', true); |
122 | | - $allowedListTypes = GeneralUtility::trimExplode(',', $contentDefefenderConfiguration['allowed.']['list_type'] ?? '', true); |
123 | | - if (count($allowedCTypes) === 1) { |
124 | | - if ($allowedCTypes[0] !== 'list') { |
125 | | - return ['CType' => $allowedCTypes[0]]; |
126 | | - } |
127 | | - if (count($allowedListTypes) === 1) { |
128 | | - return ['CType' => 'list', 'list_type' => $allowedListTypes[0]]; |
129 | | - } |
130 | | - } |
131 | | - return null; |
| 30 | + $record['tx_container_grid'] = $this->gridRenderer->renderGrid($record, $item->getContext(), $item); |
| 31 | + $item->setRecord($record); |
| 32 | + return parent::renderPageModulePreviewContent($item); |
132 | 33 | } |
133 | 34 | } |
0 commit comments