diff --git a/typo3/sysext/backend/Classes/View/BackendLayout/Grid/GridColumnItem.php b/typo3/sysext/backend/Classes/View/BackendLayout/Grid/GridColumnItem.php index d52b474caf4e36d4c534eaf9a98719895e42fb1a..44e12cbde6df46dda79c4fad008d6c2e4a2dda00 100644 --- a/typo3/sysext/backend/Classes/View/BackendLayout/Grid/GridColumnItem.php +++ b/typo3/sysext/backend/Classes/View/BackendLayout/Grid/GridColumnItem.php @@ -72,18 +72,25 @@ class GridColumnItem extends AbstractGridObject public function getPreview(): string { - $record = $this->getRecord(); $previewRenderer = GeneralUtility::makeInstance(StandardPreviewRendererResolver::class) ->resolveRendererFor( 'tt_content', - $record, + $this->record, $this->context->getPageId() ); $previewHeader = $previewRenderer->renderPageModulePreviewHeader($this); - $event = new PageContentPreviewRenderingEvent('tt_content', $this->record, $this->context); - GeneralUtility::makeInstance(EventDispatcherInterface::class)->dispatch($event); + // Dispatch event to allow listeners adding an alternative content type + // specific preview or to manipulate the content elements' record data. + $event = GeneralUtility::makeInstance(EventDispatcherInterface::class)->dispatch( + new PageContentPreviewRenderingEvent('tt_content', $this->record, $this->context) + ); + + // Update the modified record data + $this->record = $event->getRecord(); + // Get specific preview from listeners. In case non was added, + // fall back to the standard preview rendering workflow. $previewContent = $event->getPreviewContent(); if ($previewContent === null) { $previewContent = $previewRenderer->renderPageModulePreviewContent($this); diff --git a/typo3/sysext/backend/Classes/View/Event/PageContentPreviewRenderingEvent.php b/typo3/sysext/backend/Classes/View/Event/PageContentPreviewRenderingEvent.php index 2588f266219ed3be489809f725c6d4a89979e0b8..705a786a613dbe6b0695d4bfd082b55a43a61ead 100644 --- a/typo3/sysext/backend/Classes/View/Event/PageContentPreviewRenderingEvent.php +++ b/typo3/sysext/backend/Classes/View/Event/PageContentPreviewRenderingEvent.php @@ -28,9 +28,9 @@ final class PageContentPreviewRenderingEvent implements StoppableEventInterface private ?string $content = null; public function __construct( - private string $table, + private readonly string $table, private array $record, - private PageLayoutContext $context + private readonly PageLayoutContext $context ) { } @@ -44,6 +44,11 @@ final class PageContentPreviewRenderingEvent implements StoppableEventInterface return $this->record; } + public function setRecord(array $record): void + { + $this->record = $record; + } + public function getPageLayoutContext(): PageLayoutContext { return $this->context; diff --git a/typo3/sysext/core/Documentation/Changelog/12.0/Feature-98375-PSR-14EventsInPageModule.rst b/typo3/sysext/core/Documentation/Changelog/12.0/Feature-98375-PSR-14EventsInPageModule.rst index 597b61eaddfca91c7c2294c3921fbffc2ac28534..796e087ed7be3734d7b7a4ed345ffe80e239e5a0 100644 --- a/typo3/sysext/core/Documentation/Changelog/12.0/Feature-98375-PSR-14EventsInPageModule.rst +++ b/typo3/sysext/core/Documentation/Changelog/12.0/Feature-98375-PSR-14EventsInPageModule.rst @@ -33,7 +33,7 @@ in a column that isn't on a Backend Layout. Use :php:`ModifyDatabaseQueryForContentEvent` to filter out certain content elements from being shown in the Page Module. -Use :php:`PageContentPreviewRenderingEvent` to ship an alternative rendering for a -specific content type. +Use :php:`PageContentPreviewRenderingEvent` to ship an alternative rendering for +a specific content type or to manipulate the content elements' record data. .. index:: Backend, PHP-API, ext:backend