Skip to content

Commit b63c575

Browse files
committed
[FEATURE] Add support for PAGEVIEW data processing
1 parent 91ea27a commit b63c575

14 files changed

Lines changed: 92 additions & 21 deletions

File tree

Build/content-blocks-examples/Configuration/Sets/Example/setup.typoscript

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ page.10 {
44
paths.10 = EXT:content_blocks_examples/Resources/Private/Templates
55
dataProcessing {
66
10 = page-content
7+
20 = content-blocks
78
}
89
}

Classes/DataProcessing/ContentBlockDataDecorator.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,16 @@ public function setRequest(ServerRequestInterface $request): void
5151

5252
public function decorate(RecordInterface $resolvedRecord, ?PageLayoutContext $context = null): ContentBlockData
5353
{
54-
$tableDefinition = $this->tableDefinitionCollection->getTable($resolvedRecord->getMainType());
5554
$contentTypeDefinition = $this->contentTypeResolver->resolve($resolvedRecord);
56-
$identifier = $this->getRecordIdentifier($resolvedRecord);
57-
$this->contentBlockDataDecoratorSession->addContentBlockData($identifier, new ContentBlockData());
5855
$resolvedContentBlockDataRelation = new ResolvedContentBlockDataRelation();
5956
$resolvedContentBlockDataRelation->record = $resolvedRecord;
6057
$resolvedContentBlockDataRelation->resolved = $resolvedRecord->toArray();
58+
if ($contentTypeDefinition === null) {
59+
return $this->buildFakeContentBlockDataObject($resolvedContentBlockDataRelation);
60+
}
61+
$identifier = $this->getRecordIdentifier($resolvedRecord);
62+
$this->contentBlockDataDecoratorSession->addContentBlockData($identifier, new ContentBlockData());
63+
$tableDefinition = $this->tableDefinitionCollection->getTable($resolvedRecord->getMainType());
6164
$contentBlockData = $this->buildContentBlockDataObjectRecursive(
6265
$contentTypeDefinition,
6366
$tableDefinition,
@@ -299,11 +302,9 @@ private function buildFakeContentBlockDataObject(ResolvedContentBlockDataRelatio
299302
private function getRecordIdentifier(RecordInterface $record): string
300303
{
301304
$identifier = $record->getMainType();
302-
303305
if ($record instanceof Record) {
304306
$identifier .= '-' . $record->getOverlaidUid();
305307
}
306-
307308
return $identifier;
308309
}
309310
}

Classes/DataProcessing/ContentBlocksDataProcessor.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,14 @@ public function process(
4545
$request = $cObj->getRequest();
4646
$this->contentBlockDataDecorator->setRequest($request);
4747
$table = $cObj->getCurrentTable();
48-
if (!$this->tableDefinitionCollection->hasTable($table)) {
48+
// Fall back to ContentObjectRenderer->data if the key "data" is not populated.
49+
// This is the case, for example, for PAGEVIEW.
50+
$data = $processedData['data'] ?? $cObj->data;
51+
if ($data === []) {
4952
return $processedData;
5053
}
51-
$resolveRecord = $this->recordFactory->createResolvedRecordFromDatabaseRow(
52-
$table,
53-
$processedData['data'],
54-
);
55-
$contentTypeDefinition = $this->contentTypeResolver->resolve($resolveRecord);
56-
if ($contentTypeDefinition === null) {
57-
$processedData['data'] = $resolveRecord;
58-
return $processedData;
59-
}
60-
$processedData['data'] = $this->contentBlockDataDecorator->decorate($resolveRecord);
54+
$resolvedRecord = $this->recordFactory->createResolvedRecordFromDatabaseRow($table, $data);
55+
$processedData['data'] = $this->contentBlockDataDecorator->decorate($resolvedRecord);
6156
return $processedData;
6257
}
6358
}

Classes/DataProcessing/ContentTypeResolver.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ public function __construct(
3232

3333
public function resolve(RecordInterface $record): ?ContentTypeInterface
3434
{
35-
$tableDefinition = $this->tableDefinitionCollection->getTable($record->getMainType());
35+
$table = $record->getMainType();
36+
if (!$this->tableDefinitionCollection->hasTable($table)) {
37+
return null;
38+
}
39+
$tableDefinition = $this->tableDefinitionCollection->getTable($table);
3640
$typeName = $tableDefinition->hasTypeField()
3741
? $record->getRecordType()
3842
: '1';

Tests/Fixtures/Extensions/test_content_blocks_b/ContentBlocks/ContentElements/content-element-b/templates/frontend.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<html
22
xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
3-
xmlns:cb="http://typo3.org/ns/TYPO3/CMS/ContentBlocks/ViewHelpers"
43
data-namespace-typo3-fluid="true"
54
>
65

Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: example/example-page-type
2+
typeName: 942
3+
prefixFields: false
4+
fields:
5+
- identifier: additional_field
6+
type: Text
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0"?>
2+
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
3+
<file datatype="plaintext" original="labels.xlf" source-language="en" date="2024-09-20T23:35:32+00:00" product-name="example/example-page-type">
4+
<header/>
5+
<body>
6+
<trans-unit id="title">
7+
<source>My custom page type</source>
8+
</trans-unit>
9+
<trans-unit id="description">
10+
<source>This is your page type description</source>
11+
</trans-unit>
12+
<trans-unit id="additional_field.label">
13+
<source>Additional field</source>
14+
</trans-unit>
15+
</body>
16+
</file>
17+
</xliff>

0 commit comments

Comments
 (0)