Skip to content

Commit 4b99fde

Browse files
committed
[TASK] cleanup code for TYPO3 > 12
1 parent 326b90d commit 4b99fde

File tree

5 files changed

+69
-253
lines changed

5 files changed

+69
-253
lines changed

Classes/Backend/Preview/ContainerPreviewRenderer.php

Lines changed: 0 additions & 48 deletions
This file was deleted.

Classes/Backend/Preview/GridRenderer.php

Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,23 @@
3131
use TYPO3\CMS\Core\Utility\GeneralUtility;
3232
use TYPO3\CMS\Core\View\ViewFactoryData;
3333
use TYPO3\CMS\Core\View\ViewFactoryInterface;
34+
use TYPO3\CMS\Core\View\ViewInterface;
3435
use TYPO3\CMS\Fluid\View\StandaloneView;
3536

3637
class GridRenderer
3738
{
38-
protected Registry $tcaRegistry;
39-
protected ContainerFactory $containerFactory;
40-
protected NewContentUrlBuilder $newContentUrlBuilder;
41-
protected EventDispatcherInterface $eventDispatcher;
42-
protected FrontendInterface $runtimeCache;
43-
4439
public function __construct(
45-
Registry $tcaRegistry,
46-
ContainerFactory $containerFactory,
47-
NewContentUrlBuilder $newContentUrlBuilder,
48-
EventDispatcherInterface $eventDispatcher,
49-
FrontendInterface $runtimeCache
40+
protected Registry $tcaRegistry,
41+
protected ContainerFactory $containerFactory,
42+
protected NewContentUrlBuilder $newContentUrlBuilder,
43+
protected EventDispatcherInterface $eventDispatcher,
44+
protected ViewFactoryInterface $viewFactory
5045
) {
51-
$this->eventDispatcher = $eventDispatcher;
52-
$this->tcaRegistry = $tcaRegistry;
53-
$this->containerFactory = $containerFactory;
54-
$this->newContentUrlBuilder = $newContentUrlBuilder;
55-
$this->runtimeCache = $runtimeCache;
5646
}
5747

5848
public function renderGrid(array $record, PageLayoutContext $context): string
5949
{
60-
$grid = GeneralUtility::makeInstance(Grid::class, $context);
50+
$grid = new Grid($context);
6151
try {
6252
$container = $this->containerFactory->buildContainer((int)$record['uid']);
6353
} catch (Exception $e) {
@@ -66,17 +56,17 @@ public function renderGrid(array $record, PageLayoutContext $context): string
6656
}
6757
$containerGrid = $this->tcaRegistry->getGrid($record['CType']);
6858
foreach ($containerGrid as $cols) {
69-
$rowObject = GeneralUtility::makeInstance(GridRow::class, $context);
59+
$rowObject = new GridRow($context);
7060
foreach ($cols as $col) {
7161
$defVals = $this->getDefValsForContentDefenderAllowsOnlyOneSpecificContentType($record['CType'], (int)$col['colPos']);
7262
$url = $this->newContentUrlBuilder->getNewContentUrlAtTopOfColumn($context, $container, (int)$col['colPos'], $defVals);
73-
$columnObject = GeneralUtility::makeInstance(ContainerGridColumn::class, $context, $col, $container, $url, $defVals !== null);
63+
$columnObject = new ContainerGridColumn($context, $col, $container, $url, $defVals !== null);
7464
$rowObject->addColumn($columnObject);
7565
if (isset($col['colPos'])) {
7666
$records = $container->getChildrenByColPos($col['colPos']);
7767
foreach ($records as $contentRecord) {
7868
$url = $this->newContentUrlBuilder->getNewContentUrlAfterChild($context, $container, (int)$col['colPos'], (int)$contentRecord['uid'], $defVals);
79-
$columnItem = GeneralUtility::makeInstance(ContainerGridColumnItem::class, $context, $columnObject, $contentRecord, $container, $url);
69+
$columnItem = new ContainerGridColumnItem($context, $columnObject, $contentRecord, $container, $url);
8070
$columnObject->addItem($columnItem);
8171
}
8272
}
@@ -87,20 +77,12 @@ public function renderGrid(array $record, PageLayoutContext $context): string
8777
$gridTemplate = $this->tcaRegistry->getGridTemplate($record['CType']);
8878
$partialRootPaths = $this->tcaRegistry->getGridPartialPaths($record['CType']);
8979
$layoutRootPaths = $this->tcaRegistry->getGridLayoutPaths($record['CType']);
90-
if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() <= 13) {
91-
$view = GeneralUtility::makeInstance(StandaloneView::class);
92-
$view->setPartialRootPaths($partialRootPaths);
93-
$view->setLayoutRootPaths($layoutRootPaths);
94-
$view->setTemplatePathAndFilename($gridTemplate);
95-
} else {
96-
$viewFactory = GeneralUtility::makeInstance(ViewFactoryInterface::class);
97-
$view = $viewFactory->create(new ViewFactoryData(
98-
null,
99-
$partialRootPaths,
100-
$layoutRootPaths,
101-
$gridTemplate
102-
));
103-
}
80+
$view = $this->viewFactory->create(new ViewFactoryData(
81+
null,
82+
$partialRootPaths,
83+
$layoutRootPaths,
84+
$gridTemplate
85+
));
10486

10587
$view->assign('hideRestrictedColumns', (bool)(BackendUtility::getPagesTSconfig($context->getPageId())['mod.']['web_layout.']['hideRestrictedCols'] ?? false));
10688
$view->assign('newContentTitle', $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newContentElement'));
@@ -112,29 +94,17 @@ public function renderGrid(array $record, PageLayoutContext $context): string
11294
$view->assign('gridColumns', array_fill(1, $grid->getSpan(), null));
11395
$view->assign('containerRecord', $record);
11496
$view->assign('context', $context);
115-
$parentGridColumnItem = $this->runtimeCache->get('tx_container_current_gridColumItem');
116-
if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() <= 13) {
117-
// cannot be used for v14 / dev-main branch
118-
// needs adaption in next major version
119-
$beforeContainerPreviewIsRendered = new BeforeContainerPreviewIsRenderedEvent($container, $view, $grid, $parentGridColumnItem);
120-
$this->eventDispatcher->dispatch($beforeContainerPreviewIsRendered);
121-
}
97+
$beforeContainerPreviewIsRendered = new BeforeContainerPreviewIsRenderedEvent($container, $view, $grid);
98+
$this->eventDispatcher->dispatch($beforeContainerPreviewIsRendered);
12299
$rendered = $view->render();
123100
return $rendered;
124101
}
125102

126103
protected function getDefValsForContentDefenderAllowsOnlyOneSpecificContentType(string $cType, int $colPos): ?array
127104
{
128-
$contentDefefenderConfiguration = $this->tcaRegistry->getContentDefenderConfiguration($cType, $colPos);
129-
$allowedCTypes = GeneralUtility::trimExplode(',', $contentDefefenderConfiguration['allowed.']['CType'] ?? '', true);
130-
$allowedListTypes = GeneralUtility::trimExplode(',', $contentDefefenderConfiguration['allowed.']['list_type'] ?? '', true);
105+
$allowedCTypes = (array)$this->tcaRegistry->getAllowedCTypesInColumn($cType, $colPos);
131106
if (count($allowedCTypes) === 1) {
132-
if ($allowedCTypes[0] !== 'list') {
133-
return ['CType' => $allowedCTypes[0]];
134-
}
135-
if (count($allowedListTypes) === 1) {
136-
return ['CType' => 'list', 'list_type' => $allowedListTypes[0]];
137-
}
107+
return ['CType' => $allowedCTypes[0]];
138108
}
139109
return null;
140110
}

Classes/Backend/Service/NewContentUrlBuilder.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,12 @@
2222

2323
class NewContentUrlBuilder
2424
{
25-
protected Registry $tcaRegistry;
26-
protected ContainerColumnConfigurationService $containerColumnConfigurationService;
27-
protected ContainerService $containerService;
28-
protected UriBuilder $uriBuilder;
29-
3025
public function __construct(
31-
Registry $tcaRegistry,
32-
ContainerColumnConfigurationService $containerColumnConfigurationService,
33-
ContainerService $containerService,
34-
UriBuilder $uriBuilder
26+
protected Registry $tcaRegistry,
27+
protected ContainerColumnConfigurationService $containerColumnConfigurationService,
28+
protected ContainerService $containerService,
29+
protected UriBuilder $uriBuilder
3530
) {
36-
$this->tcaRegistry = $tcaRegistry;
37-
$this->containerColumnConfigurationService = $containerColumnConfigurationService;
38-
$this->containerService = $containerService;
39-
$this->uriBuilder = $uriBuilder;
4031
}
4132

4233
public function getNewContentUrlAfterChild(PageLayoutContext $context, Container $container, int $columnNumber, int $recordUid, ?array $defVals): string

Classes/Events/BeforeContainerPreviewIsRenderedEvent.php

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,20 @@
1414

1515
use B13\Container\Domain\Model\Container;
1616
use TYPO3\CMS\Backend\View\BackendLayout\Grid\Grid;
17-
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem;
18-
use TYPO3\CMS\Fluid\View\StandaloneView;
17+
use TYPO3\CMS\Core\View\ViewInterface;
1918

2019
final class BeforeContainerPreviewIsRenderedEvent
2120
{
22-
protected Container $container;
23-
24-
protected StandaloneView $view;
25-
26-
protected Grid $grid;
27-
28-
protected GridColumnItem $item;
29-
30-
public function __construct(Container $container, StandaloneView $view, Grid $grid, GridColumnItem $item)
21+
public function __construct(protected Container $container, protected ViewInterface $view, protected Grid $grid)
3122
{
32-
$this->container = $container;
33-
$this->view = $view;
34-
$this->grid = $grid;
35-
$this->item = $item;
3623
}
3724

3825
public function getContainer(): Container
3926
{
4027
return $this->container;
4128
}
4229

43-
public function getView(): StandaloneView
30+
public function getView(): ViewInterface
4431
{
4532
return $this->view;
4633
}
@@ -49,10 +36,4 @@ public function getGrid(): Grid
4936
{
5037
return $this->grid;
5138
}
52-
53-
public function getItem(): GridColumnItem
54-
{
55-
trigger_error('gridColumItem property will be removed on next major release', E_USER_DEPRECATED);
56-
return $this->item;
57-
}
5839
}

0 commit comments

Comments
 (0)