Skip to content

Commit 2ef903f

Browse files
authored
[!!!][TASK] Use Record API in Page Module Preview Rendering #1409 (#6162)
Resolves: TYPO3-Documentation/Changelog-To-Doc#1409 Releases: main
1 parent 8345cf9 commit 2ef903f

File tree

5 files changed

+71
-18
lines changed

5 files changed

+71
-18
lines changed

Documentation/ApiOverview/ContentElements/CustomBackendPreview.rst

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class is responsible for generating the preview and the wrapping.
1717
The default preview renderer is :php:`\TYPO3\CMS\Backend\Preview\StandardContentPreviewRenderer`
1818
and handles the Core's built-in content types (field :sql:`CType` in table :sql:`tt_content`).
1919

20+
.. _ContentPreviewRenderer:
21+
2022
Extend the default preview renderer
2123
===================================
2224

@@ -25,31 +27,43 @@ via page :ref:`TSconfig <ConfigureCE-Preview-PageTSconfig>` or :ref:`event liste
2527

2628
.. _ConfigureCE-Preview-PageTSconfig:
2729

28-
Page TSconfig
29-
-------------
30+
Preview rendering with a Fluid template and page TSconfig
31+
---------------------------------------------------------
32+
33+
.. versionchanged:: 14.0
34+
A :php:`\TYPO3\CMS\Core\Domain\RecordInterface` is passed as variable
35+
`{record}` to the Fluid Template. The fields are not passed as direct
36+
variables anymore. `{pi_flexform_transformed}` has been replaced by
37+
`{record.pi_flexform}`. See also `Breaking: #92434 - Use Record API
38+
in Page Module Preview Rendering <https://docs.typo3.org/permalink/changelog:breaking-92434-1761644184>`_.
39+
3040

3141
This is the "integrator" way, no PHP coding is required. Just some page TSconfig
3242
and a Fluid template.
3343

34-
.. code-block:: typoscript
44+
.. literalinclude:: _codesnippets/_preview.typoscript
3545
:caption: EXT:my_extension/Configuration/page.tsconfig
3646

37-
mod.web_layout {
38-
tt_content {
39-
preview {
40-
# Your CType
41-
example_ctype = EXT:my_extension/Resources/Private/Templates/Preview/ExampleCType.html
42-
}
43-
}
44-
}
47+
For more details see the :ref:`TSconfig Reference <t3tsref:pageweblayoutpreview>`.
4548

4649
In the Fluid template, the following variables are available:
4750

48-
* All properties of the :php:`tt_content` row (for example `{uid}`, `{title}`, and `{header}`)
49-
* The current record as object (:php:`\TYPO3\CMS\Core\Domain\Record`) in `{record}`
50-
* FlexForm settings as array in `{pi_flexform_transformed}`
51+
* The current record as object (:php-short:`\TYPO3\CMS\Core\Domain\Record`)
52+
in variable `{record}`
5153

52-
For more details see the :ref:`TSconfig Reference <t3tsref:pageweblayoutpreview>`.
54+
.. literalinclude:: _codesnippets/_Preview.html
55+
:caption: EXT:my_extension/Resources/Private/Templates/Preview/MyCType.html
56+
57+
.. rubric:: Migration
58+
59+
.. code-block:: diff
60+
61+
-<h2>{header}</h2>
62+
+<h2>{record.header}</h2>
63+
-<p>{bodytext}</p>
64+
+<p>{record.bodytext}</p>
65+
-<small>{pi_flexform_transformed.settings.welcome_header}</small>
66+
+<small>{record.pi_flexform.sheets.s_messages.settings.welcome_header}</small>
5367
5468
.. _ConfigureCE-Preview-EventListener:
5569

@@ -67,9 +81,16 @@ Have a look at this :ref:`showcase implementation <PageContentPreviewRenderingEv
6781

6882
For general information see the chapter on :ref:`implementing an event listener <EventDispatcherImplementation>`.
6983

84+
.. _ConfigureCE-Preview-preview-renderer:
85+
7086
Writing a preview renderer
7187
==========================
7288

89+
.. versionchanged:: 14.0
90+
The `@internal` class
91+
:php-short:`\TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem` has been
92+
updated to work with Record objects.
93+
7394
A custom preview renderer must implement the interface
7495
:php:`\TYPO3\CMS\Backend\Preview\PreviewRendererInterface` which contains
7596
the following API methods:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<h2>{record.header}</h2>
2+
<p>{record.bodytext}</p>
3+
<f:if condition="{record.image}">
4+
<p>Image UID: {record.image.uid}</p>
5+
</f:if>
6+
7+
<f:variable name="path" value="s_messages/settings" />
8+
<small>{record.pi_flexform.{path}.welcome_header}</small>
9+
10+
Or, the following (same result):
11+
12+
<small>{record.pi_flexform.sheets.s_messages.settings.welcome_header}</small>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
mod.web_layout {
2+
tt_content {
3+
preview {
4+
# Your CType
5+
example_ctype = EXT:my_extension/Resources/Private/Templates/Preview/MyCType.html
6+
}
7+
}
8+
}

Documentation/ApiOverview/Events/Events/Backend/PageContentPreviewRenderingEvent.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ Use the PSR-14 event
1111
to ship an alternative rendering for a specific content type or
1212
to manipulate the record data of a content element.
1313

14+
.. versionchanged:: 14.0
15+
`PageContentPreviewRenderingEvent->getRecord()` now returns a
16+
:php:`RecordInterface` object instead of an array,
17+
:php:`PageContentPreviewRenderingEvent->setRecord()` has been adjusted
18+
accordingly.
19+
20+
.. _PageContentPreviewRenderingEvent-example:
21+
1422
Example
1523
=======
1624

@@ -20,6 +28,7 @@ Example
2028

2129
.. include:: /_includes/EventsAttributeAdded.rst.txt
2230

31+
.. _PageContentPreviewRenderingEvent-api:
2332

2433
API
2534
===

Documentation/ApiOverview/Events/Events/Backend/_PageContentPreviewRenderingEvent/_MyEventListener.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@
1414
{
1515
public function __invoke(PageContentPreviewRenderingEvent $event): void
1616
{
17-
if ($event->getTable() !== 'tt_content') {
17+
if ($event->getRecord()->getFullType() !== 'tt_content.example_ctype') {
1818
return;
1919
}
2020

21-
if ($event->getRecordType() === 'example_ctype') {
22-
$event->setPreviewContent('<div>...</div>');
21+
if ($event->getRecord()->has('header')) {
22+
$header = $event->getRecord()->get('header');
23+
$event->setPreviewContent(
24+
sprintf('<h1>%s</h1></h1><div>...</div>', $header),
25+
);
2326
}
2427
}
2528
}

0 commit comments

Comments
 (0)