From b513c131e2e4c1109f24455c225f5151c11dd023 Mon Sep 17 00:00:00 2001 From: Achim Fritz Date: Wed, 3 Jul 2024 23:17:09 +0200 Subject: [PATCH] [BUGFIX] readd backendTemplate PageTS mod.web_layout.tt_content.preview still exists https://docs.typo3.org/m/typo3/reference-tsconfig/main/en-us/PageTsconfig/Mod/WebLayout.html#pageweblayoutpreview This reverts commit e187b1a5287e0eeeb4f26d42a11dbc8972d3ec99. Relates to: #495 --- Classes/Listener/PageTsConfig.php | 4 +--- Classes/Tca/ContainerConfiguration.php | 13 +++++++++++++ Classes/Tca/Registry.php | 17 +++++++++++------ README.md | 1 + Tests/Functional/Tca/RegistryTest.php | 23 ++++++++++++++++------- Tests/Unit/Tca/RegistryTest.php | 4 ---- 6 files changed, 42 insertions(+), 20 deletions(-) diff --git a/Classes/Listener/PageTsConfig.php b/Classes/Listener/PageTsConfig.php index 8e420345..8c328d64 100644 --- a/Classes/Listener/PageTsConfig.php +++ b/Classes/Listener/PageTsConfig.php @@ -31,9 +31,7 @@ public function __construct(Registry $tcaRegistry) public function __invoke(ModifyLoadedPageTsConfigEvent $event): void { - // s. https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/ContentElements/CustomBackendPreview.html#ConfigureCE-Preview-EventListener - // s. https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/13.0/Breaking-102834-RemoveItemsFromNewContentElementWizard.html - if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() !== 12) { + if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() < 12) { return; } $tsConfig = $event->getTsConfig(); diff --git a/Classes/Tca/ContainerConfiguration.php b/Classes/Tca/ContainerConfiguration.php index b90db375..90319f04 100644 --- a/Classes/Tca/ContainerConfiguration.php +++ b/Classes/Tca/ContainerConfiguration.php @@ -42,6 +42,8 @@ class ContainerConfiguration */ protected $icon = 'EXT:container/Resources/Public/Icons/Extension.svg'; + protected ?string $backendTemplate = null; + /** * @var string */ @@ -105,6 +107,16 @@ public function setIcon(string $icon): ContainerConfiguration return $this; } + /** + * @param string $backendTemplate + * @return ContainerConfiguration + */ + public function setBackendTemplate(string $backendTemplate): ContainerConfiguration + { + $this->backendTemplate = $backendTemplate; + return $this; + } + /** * @param string $gridTemplate * @return ContainerConfiguration @@ -247,6 +259,7 @@ public function toArray(): array 'icon' => $this->icon, 'label' => $this->label, 'description' => $this->description, + 'backendTemplate' => $this->backendTemplate, 'grid' => $this->grid, 'gridTemplate' => $this->gridTemplate, 'gridPartialPaths' => $this->gridPartialPaths, diff --git a/Classes/Tca/Registry.php b/Classes/Tca/Registry.php index 68cf8d12..c28fc634 100644 --- a/Classes/Tca/Registry.php +++ b/Classes/Tca/Registry.php @@ -238,12 +238,6 @@ public function getAllAvailableColumns(): array public function getPageTsString(): string { - // s. https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/ContentElements/CustomBackendPreview.html#ConfigureCE-Preview-EventListener - // s. https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/13.0/Breaking-102834-RemoveItemsFromNewContentElementWizard.html - $typo3Version = GeneralUtility::makeInstance(Typo3Version::class); - if ($typo3Version->getMajorVersion() > 12) { - throw new \BadMethodCallException('removed with TYPO3 13'); - } if (empty($GLOBALS['TCA']['tt_content']['containerConfiguration'])) { return ''; } @@ -259,6 +253,17 @@ public function getPageTsString(): string } $groupedByGroup[$group][$cType] = $containerConfiguration; } + if ($containerConfiguration['backendTemplate'] !== null) { + $pageTs .= LF . 'mod.web_layout.tt_content.preview { +' . $cType . ' = ' . $containerConfiguration['backendTemplate'] . ' +} +'; + } + } + $typo3Version = GeneralUtility::makeInstance(Typo3Version::class); + if ($typo3Version->getMajorVersion() > 12) { + // s. https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/13.0/Breaking-102834-RemoveItemsFromNewContentElementWizard.html + return $pageTs; } foreach ($groupedByGroup as $group => $containerConfigurations) { diff --git a/README.md b/README.md index 0015d898..e3b97b5e 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ This is an example to create a 2 column container. The code snippet goes into a | Method name | Description | Parameters | Default | | ----------- | ----------- | ---------- | ---------- | | `setIcon` | icon file, or existing icon identifier | `string $icon` | `'EXT:container/Resources/Public/Icons/Extension.svg'` | +| `setBackendTemplate` | Template for backend view| `string $backendTemplate` | `null'` | | `setGridTemplate` | Template for grid | `string $gridTemplate` | `'EXT:container/Resources/Private/Templates/Container.html'` | | `setGridPartialPaths` / `addGridPartialPath` | Partial root paths for grid | `array $gridPartialPaths` / `string $gridPartialPath` | `['EXT:backend/Resources/Private/Partials/', 'EXT:container/Resources/Private/Partials/']` | | `setGridLayoutPaths` | Layout root paths for grid | `array $gridLayoutPaths` | `[]` | diff --git a/Tests/Functional/Tca/RegistryTest.php b/Tests/Functional/Tca/RegistryTest.php index a721aca0..d4f81f13 100644 --- a/Tests/Functional/Tca/RegistryTest.php +++ b/Tests/Functional/Tca/RegistryTest.php @@ -33,13 +33,22 @@ class RegistryTest extends FunctionalTestCase */ public function getPageTsAddsPreviewConfigEvenIfRegisterInNewContentElementWizardIsSetToFalse(): void { - if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() > 12) { - // s. https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/ContentElements/CustomBackendPreview.html#ConfigureCE-Preview-EventListener - self::markTestSkipped('event listener is used'); - } else { - // https://github.com/b13/container/pull/153 - self::markTestSkipped('todo check this, TS removed, mod.web_layout.tt_content.preview'); - } + // https://github.com/b13/container/pull/153 + \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(Registry::class)->configureContainer( + (new ContainerConfiguration( + 'b13-container', // CType + 'foo', // label + 'bar', // description + [] // grid configuration + ))->setRegisterInNewContentElementWizard(false) + ->setBackendTemplate('EXT:container/Resources/Private/Templates/Container.html') + ); + $registry = GeneralUtility::makeInstance(Registry::class); + $pageTs = $registry->getPageTsString(); + $expected = 'mod.web_layout.tt_content.preview { +b13-container = EXT:container/Resources/Private/Templates/Container.html +}'; + self::assertStringContainsString($expected, $pageTs); } /** diff --git a/Tests/Unit/Tca/RegistryTest.php b/Tests/Unit/Tca/RegistryTest.php index fee41def..2121c54f 100644 --- a/Tests/Unit/Tca/RegistryTest.php +++ b/Tests/Unit/Tca/RegistryTest.php @@ -13,7 +13,6 @@ */ use B13\Container\Tca\Registry; -use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; @@ -36,9 +35,6 @@ public function getAllAvailableColumnsReturnsEmptyArrayIfNoContainerConfigured() */ public function getPageTsStringReturnsEmptyStringIfNoContainerConfigured(): void { - if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() === 13) { - self::markTestSkipped('not used in v13'); - } $registry = GeneralUtility::makeInstance(Registry::class); $res = $registry->getPageTsString(); self::assertSame('', $res, 'empty string should be returned');