Skip to content

Commit 8bf0304

Browse files
committed
[BUGFIX] custom backend layout for v14
1 parent a50aaff commit 8bf0304

File tree

13 files changed

+191
-22
lines changed

13 files changed

+191
-22
lines changed

Build/phpstan-baseline-14.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,3 @@ parameters:
8383
message: "#^Parameter \\#1 \\$record of method B13\\\\Container\\\\Backend\\\\Preview\\\\GridRenderer\\:\\:renderGrid\\(\\) expects array, TYPO3\\\\CMS\\\\Core\\\\Domain\\\\RecordInterface given\\.$#"
8484
count: 1
8585
path: ../Classes/Backend/Preview/ContainerPreviewRenderer.php
86-
87-
-
88-
message: "#^Parameter \\#1 \\$record of method B13\\\\Container\\\\Backend\\\\Preview\\\\GridRenderer\\:\\:renderGrid\\(\\) expects array, TYPO3\\\\CMS\\\\Core\\\\Domain\\\\RecordInterface given\\.$#"
89-
count: 1
90-
path: ../Classes/Listener/PageContentPreviewRendering.php

Build/phpstan11-7.4.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ parameters:
1616
- %currentWorkingDirectory%/Classes/Listener/RecordSummaryForLocalization.php
1717
- %currentWorkingDirectory%/Classes/Listener/PageTsConfig.php
1818
- %currentWorkingDirectory%/Classes/Listener/PageContentPreviewRendering.php
19+
- %currentWorkingDirectory%/Classes/Domain/Core/RecordWithRenderedGrid.php
1920

Build/phpstan11.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ parameters:
1616
- %currentWorkingDirectory%/Classes/Listener/RecordSummaryForLocalization.php
1717
- %currentWorkingDirectory%/Classes/Listener/PageTsConfig.php
1818
- %currentWorkingDirectory%/Classes/Listener/PageContentPreviewRendering.php
19+
- %currentWorkingDirectory%/Classes/Domain/Core/RecordWithRenderedGrid.php
1920

Build/phpstan12.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ parameters:
1212
- %currentWorkingDirectory%/Classes/Hooks/UsedRecords.php
1313
- %currentWorkingDirectory%/Tests/Functional/Hooks/UsedRecordsTest.php
1414
- %currentWorkingDirectory%/Tests/Unit/Hooks/UsedRecordsTest.php
15+
- %currentWorkingDirectory%/Classes/Domain/Core/RecordWithRenderedGrid.php
16+
- %currentWorkingDirectory%/Classes/Listener/PageContentPreviewRendering.php
1517

1618

Build/phpstan13.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ parameters:
1414
- %currentWorkingDirectory%/Tests/Unit/Hooks/UsedRecordsTest.php
1515
- %currentWorkingDirectory%/Classes/Hooks/WizardItems.php
1616
- %currentWorkingDirectory%/Classes/Listener/LegacyPageTsConfig.php
17+
- %currentWorkingDirectory%/Classes/Listener/PageContentPreviewRendering.php
1718

Build/phpstan14.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ parameters:
1414
- %currentWorkingDirectory%/Tests/Unit/Hooks/UsedRecordsTest.php
1515
- %currentWorkingDirectory%/Classes/Hooks/WizardItems.php
1616
- %currentWorkingDirectory%/Classes/Listener/LegacyPageTsConfig.php
17+
- %currentWorkingDirectory%/Classes/Listener/LegacyPageContentPreviewRendering.php
1718
- %currentWorkingDirectory%/Classes/ContentDefender
1819
- %currentWorkingDirectory%/Classes/Events/BeforeContainerPreviewIsRenderedEvent.php
1920
- %currentWorkingDirectory%/Tests/Functional/Integrity/IntegrityTest.php
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace B13\Container\Domain\Core;
6+
7+
/*
8+
* This file is part of TYPO3 CMS-based extension "container" by b13.
9+
*
10+
* It is free software; you can redistribute it and/or modify it under
11+
* the terms of the GNU General Public License, either version 2
12+
* of the License, or any later version.
13+
*/
14+
15+
use TYPO3\CMS\Core\Domain\RawRecord;
16+
use TYPO3\CMS\Core\Domain\Record;
17+
use TYPO3\CMS\Core\Domain\Record\ComputedProperties;
18+
use TYPO3\CMS\Core\Domain\Record\LanguageInfo;
19+
use TYPO3\CMS\Core\Domain\Record\SystemProperties;
20+
use TYPO3\CMS\Core\Domain\Record\VersionInfo;
21+
use TYPO3\CMS\Core\Domain\RecordInterface;
22+
23+
class RecordWithRenderedGrid implements RecordInterface
24+
{
25+
public function __construct(
26+
protected readonly Record $coreRecord,
27+
protected readonly ?string $renderedGrid
28+
) {
29+
}
30+
31+
public function getUid(): int
32+
{
33+
return $this->coreRecord->getRawRecord()->getUid();
34+
}
35+
36+
public function getPid(): int
37+
{
38+
return $this->coreRecord->getRawRecord()->getPid();
39+
}
40+
41+
public function getFullType(): string
42+
{
43+
return $this->coreRecord->getRawRecord()->getFullType();
44+
}
45+
46+
public function getRecordType(): ?string
47+
{
48+
return $this->coreRecord->getRawRecord()->getRecordType();
49+
}
50+
51+
public function getMainType(): string
52+
{
53+
return $this->coreRecord->getRawRecord()->getMainType();
54+
}
55+
56+
public function toArray(bool $includeSystemProperties = false): array
57+
{
58+
$properties = $this->coreRecord->toArray();
59+
$properties['tx_container_grid'] = $this->renderedGrid;
60+
return $properties;
61+
}
62+
63+
public function has(string $id): bool
64+
{
65+
if ($id === 'tx_container_grid') {
66+
return true;
67+
}
68+
return $this->coreRecord->has($id);
69+
}
70+
71+
public function get(string $id): mixed
72+
{
73+
if ($id === 'tx_container_grid') {
74+
return $this->renderedGrid;
75+
}
76+
return $this->coreRecord->get($id);
77+
}
78+
79+
public function getVersionInfo(): ?VersionInfo
80+
{
81+
return $this->coreRecord->getVersionInfo();
82+
}
83+
84+
public function getLanguageInfo(): ?LanguageInfo
85+
{
86+
return $this->coreRecord->getLanguageInfo();
87+
}
88+
89+
public function getLanguageId(): ?int
90+
{
91+
return $this->coreRecord->getLanguageId();
92+
}
93+
94+
public function getSystemProperties(): ?SystemProperties
95+
{
96+
return $this->coreRecord->getSystemProperties();
97+
}
98+
99+
public function getComputedProperties(): ComputedProperties
100+
{
101+
return $this->coreRecord->getComputedProperties();
102+
}
103+
104+
public function getRawRecord(): RawRecord
105+
{
106+
return $this->coreRecord->getRawRecord();
107+
}
108+
109+
public function getOverlaidUid(): int
110+
{
111+
return $this->coreRecord->getOverlaidUid();
112+
}
113+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace B13\Container\Listener;
6+
7+
/*
8+
* This file is part of TYPO3 CMS-based extension "container" by b13.
9+
*
10+
* It is free software; you can redistribute it and/or modify it under
11+
* the terms of the GNU General Public License, either version 2
12+
* of the License, or any later version.
13+
*/
14+
15+
use B13\Container\Backend\Preview\GridRenderer;
16+
use B13\Container\Tca\Registry;
17+
use TYPO3\CMS\Backend\View\Event\PageContentPreviewRenderingEvent;
18+
use TYPO3\CMS\Core\Information\Typo3Version;
19+
20+
class LegacyPageContentPreviewRendering
21+
{
22+
protected GridRenderer $gridRenderer;
23+
protected Registry $tcaRegistry;
24+
25+
public function __construct(GridRenderer $gridRenderer, Registry $tcaRegistry)
26+
{
27+
$this->gridRenderer = $gridRenderer;
28+
$this->tcaRegistry = $tcaRegistry;
29+
}
30+
31+
public function __invoke(PageContentPreviewRenderingEvent $event): void
32+
{
33+
if ($event->getTable() !== 'tt_content') {
34+
return;
35+
}
36+
if ((new Typo3Version())->getMajorVersion() > 13) {
37+
return;
38+
}
39+
40+
$record = $event->getRecord();
41+
$recordType = $record['CType'];
42+
if (!$this->tcaRegistry->isContainerElement($recordType)) {
43+
return;
44+
}
45+
$record['tx_container_grid'] = $this->gridRenderer->renderGrid($record, $event->getPageLayoutContext());
46+
$event->setRecord($record);
47+
}
48+
}

Classes/Listener/PageContentPreviewRendering.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
*/
1414

1515
use B13\Container\Backend\Preview\GridRenderer;
16+
use B13\Container\Domain\Core\RecordWithRenderedGrid;
1617
use B13\Container\Tca\Registry;
1718
use TYPO3\CMS\Backend\View\Event\PageContentPreviewRenderingEvent;
19+
use TYPO3\CMS\Core\Domain\Record;
1820
use TYPO3\CMS\Core\Information\Typo3Version;
19-
use TYPO3\CMS\Core\Utility\GeneralUtility;
2021

2122
class PageContentPreviewRendering
2223
{
@@ -34,23 +35,19 @@ public function __invoke(PageContentPreviewRenderingEvent $event): void
3435
if ($event->getTable() !== 'tt_content') {
3536
return;
3637
}
38+
if ((new Typo3Version())->getMajorVersion() < 14) {
39+
return;
40+
}
3741

3842
$record = $event->getRecord();
39-
40-
if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() > 13) {
41-
$recordType = $record->getRecordType();
42-
} else {
43-
$recordType = $record['CType'];
44-
}
43+
$recordType = $record->getRecordType();
4544
if (!$this->tcaRegistry->isContainerElement($recordType)) {
4645
return;
4746
}
48-
if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() > 13) {
47+
if ($record instanceof Record) {
4948
$previewContent = $this->gridRenderer->renderGrid($record->toArray(), $event->getPageLayoutContext());
50-
$event->setPreviewContent($previewContent);
51-
} else {
52-
$record['tx_container_grid'] = $this->gridRenderer->renderGrid($record, $event->getPageLayoutContext());
53-
$event->setRecord($record);
49+
$recordWithRenderedGrid = new RecordWithRenderedGrid($record, $previewContent);
50+
$event->setRecord($recordWithRenderedGrid);
5451
}
5552
}
5653
}

Configuration/Services.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ services:
7373
tags:
7474
- name: event.listener
7575
identifier: 'tx-container-boot-completed'
76+
B13\Container\Listener\LegacyPageContentPreviewRendering:
77+
tags:
78+
- name: event.listener
79+
identifier: 'tx-container-legacy-page-content-preview-rendering'
80+
before: 'typo3-backend/fluid-preview/content'
7681
B13\Container\Listener\PageContentPreviewRendering:
7782
tags:
7883
- name: event.listener

0 commit comments

Comments
 (0)