Skip to content

Commit

Permalink
[FEATURE] Previews for Record Types
Browse files Browse the repository at this point in the history
Fixes: #127
  • Loading branch information
nhovratov committed Aug 10, 2024
1 parent 2004ad6 commit 4351148
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
27 changes: 15 additions & 12 deletions Classes/Backend/Preview/PreviewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem;
use TYPO3\CMS\ContentBlocks\DataProcessing\ContentBlockDataDecorator;
use TYPO3\CMS\ContentBlocks\DataProcessing\RelationResolver;
use TYPO3\CMS\ContentBlocks\Definition\ContentType\ContentType;
use TYPO3\CMS\ContentBlocks\Definition\TableDefinitionCollection;
use TYPO3\CMS\ContentBlocks\Registry\ContentBlockRegistry;
use TYPO3\CMS\ContentBlocks\Utility\ContentBlockPathUtility;
Expand All @@ -49,11 +48,16 @@ public function renderPageModulePreviewContent(GridColumnItem $item): string
/** @var ServerRequestInterface $request */
$request = $GLOBALS['TYPO3_REQUEST'];
$record = $item->getRecord();
$typeField = ContentType::CONTENT_ELEMENT->getTypeField();
$contentElementTable = ContentType::CONTENT_ELEMENT->getTable();
$typeName = $record[$typeField];
$contentElementDefinition = $this->tableDefinitionCollection->getContentElementDefinition($typeName);
$contentBlockExtPath = $this->contentBlockRegistry->getContentBlockExtPath($contentElementDefinition->getName());
$recordType = $item->getRecordType();
$table = $item->getTable();
$tableDefinition = $this->tableDefinitionCollection->getTable($table);
$contentTypeCollection = $tableDefinition->getContentTypeDefinitionCollection();
if ($contentTypeCollection->hasType($recordType)) {
$contentTypeDefinition = $contentTypeCollection->getType($recordType);
} else {
$contentTypeDefinition = $contentTypeCollection->getFirst();
}
$contentBlockExtPath = $this->contentBlockRegistry->getContentBlockExtPath($contentTypeDefinition->getName());
$contentBlockPrivatePath = $contentBlockExtPath . '/' . ContentBlockPathUtility::getPrivateFolder();

// Fall back to standard preview rendering if EditorPreview.html does not exist.
Expand All @@ -63,17 +67,16 @@ public function renderPageModulePreviewContent(GridColumnItem $item): string
$result = parent::renderPageModulePreviewContent($item);
return $result;
}
$contentElementTableDefinition = $this->tableDefinitionCollection->getTable($contentElementTable);
$this->relationResolver->setRequest($request);
$resolvedData = $this->relationResolver->resolve(
$contentElementDefinition,
$contentElementTableDefinition,
$contentTypeDefinition,
$tableDefinition,
$record,
$contentElementTable,
$table,
);
$data = $this->contentBlockDataDecorator->decorate(
$contentElementDefinition,
$contentElementTableDefinition,
$contentTypeDefinition,
$tableDefinition,
$resolvedData,
$item->getContext(),
);
Expand Down
1 change: 1 addition & 0 deletions Classes/Generator/TcaGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ protected function generateBaseTableTca(TableDefinition $tableDefinition): array
'label' => $this->resolveLabelField($tableDefinition),
'hideTable' => $tableDefinition->getParentReferences() !== null,
'enablecolumns' => $capability->buildRestrictionsTca(),
'previewRenderer' => PreviewRenderer::class,
];

$labelCapability = $tableDefinition->getCapability()->getLabelCapability();
Expand Down
11 changes: 7 additions & 4 deletions Documentation/Definition/Source/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ here.
EditorPreview.html
==================

This file is only available for :ref:`Content Elements <yaml_reference_content_element>`
and :ref:`Page Types <yaml_reference_page_types>`.

The **EditorPreview.html** can be added to customize the backend preview for
your editors. By default, TYPO3 comes with a standard preview renderer. However,
it is specialized in rendering the preview of Core Content Elements. This means
only Core fields like :sql:`header`, :sql:`subheader` or :sql:`bodytext` are
considered. Therefore, it is advised to provide an own preview for custom
Content Elements. Previews for **Page Types** are displayed at the top of the
content area and beneath the page title.
content area and beneath the page title. Previews for **Record Types** can only
be shown as nested child records of Content Elements in the Page Module like so:

.. code-block:: html

<f:comment>Provide the identifier of the child Collection to render a grid preview</f:comment>
<f:render partial="PageLayout/Grid" arguments="{data: data, identifier: 'tabs_item'}"/>

.. note::

Expand Down
7 changes: 7 additions & 0 deletions Tests/Unit/Generator/TcaGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ public static function checkTcaFieldTypesDataProvider(): iterable
'security' => [
'ignorePageTypeRestriction' => true,
],
'previewRenderer' => PreviewRenderer::class,
],
'types' => [
'1' => [
Expand Down Expand Up @@ -796,6 +797,7 @@ public static function checkTcaFieldTypesDataProvider(): iterable
'security' => [
'ignorePageTypeRestriction' => true,
],
'previewRenderer' => PreviewRenderer::class,
],
'types' => [
'1' => [
Expand Down Expand Up @@ -1091,6 +1093,7 @@ public static function checkTcaFieldTypesDataProvider(): iterable
'default' => 'foobar-1',
],
'searchFields' => '',
'previewRenderer' => PreviewRenderer::class,
],
'types' => [
'1' => [
Expand Down Expand Up @@ -1302,6 +1305,7 @@ public static function checkTcaFieldTypesDataProvider(): iterable
'default_sortby' => 't3ce_example_text',
'descriptionColumn' => 'internal_description',
'searchFields' => 't3ce_example_text,t3ce_example_text2',
'previewRenderer' => PreviewRenderer::class,
],
'types' => [
'1' => [
Expand Down Expand Up @@ -1454,6 +1458,7 @@ public static function checkTcaFieldTypesDataProvider(): iterable
'default' => 'foobar-1',
],
'searchFields' => 't3ce_example_text,t3ce_example_text2',
'previewRenderer' => PreviewRenderer::class,
],
'types' => [
'1' => [
Expand Down Expand Up @@ -1615,6 +1620,7 @@ public static function checkTcaFieldTypesDataProvider(): iterable
'default' => 'foobar-example',
],
'searchFields' => 'text,text2',
'previewRenderer' => PreviewRenderer::class,
],
'types' => [
'example' => [
Expand Down Expand Up @@ -1922,6 +1928,7 @@ public static function checkTcaFieldTypesDataProvider(): iterable
'default' => 'collection-1',
],
'searchFields' => 'text',
'previewRenderer' => PreviewRenderer::class,
'security' => [
'ignorePageTypeRestriction' => true,
],
Expand Down

0 comments on commit 4351148

Please sign in to comment.