Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] readd backendTemplate #514

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Classes/Listener/PageTsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 13 additions & 0 deletions Classes/Tca/ContainerConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class ContainerConfiguration
*/
protected $icon = 'EXT:container/Resources/Public/Icons/Extension.svg';

protected ?string $backendTemplate = null;

/**
* @var string
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 11 additions & 6 deletions Classes/Tca/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
}
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` | `[]` |
Expand Down
23 changes: 16 additions & 7 deletions Tests/Functional/Tca/RegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
4 changes: 0 additions & 4 deletions Tests/Unit/Tca/RegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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');
Expand Down
Loading