Skip to content

Commit 64eda57

Browse files
bmackgeorgringer
authored andcommitted
[TASK] Make Page object implement RecordInterface
The Page object has been updated to implement the RecordInterface, aligning it with the Record API introduced in TYPO3 v13. This change adds: - Implementation of RecordInterface with all required methods - Internal use of RawRecord similar to the Record class - ComputedProperties support for translation source and localized UIDs - Backward compatibility with existing special properties and methods The Page object now provides a consistent interface with other record types while maintaining its page-specific functionality like getLanguageId(), getPageId(), and getTranslationSource(). In the next patch of this series, we'll connect the Page object to the RecordFactory, so it can handle subtypes as well. Since Page is still internal, this shouldn't be a big problem. Resolves: #107736 Releases: main Change-Id: I4cbf28c1a7be87031371e4a7a5ffb40914d9358d Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/91086 Reviewed-by: Georg Ringer <georg.ringer@gmail.com> Tested-by: Georg Ringer <georg.ringer@gmail.com>
1 parent f9b09f8 commit 64eda57

File tree

1 file changed

+117
-2
lines changed
  • typo3/sysext/core/Classes/Domain

1 file changed

+117
-2
lines changed

typo3/sysext/core/Classes/Domain/Page.php

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717

1818
namespace TYPO3\CMS\Core\Domain;
1919

20+
use TYPO3\CMS\Core\Domain\Exception\RecordPropertyNotFoundException;
21+
use TYPO3\CMS\Core\Domain\Record\ComputedProperties;
22+
2023
/**
2124
* @internal not part of public API, as this needs to be streamlined and proven
2225
*/
23-
class Page implements \ArrayAccess
26+
class Page implements RecordInterface, \ArrayAccess
2427
{
2528
use PropertyTrait;
2629

@@ -36,22 +39,134 @@ class Page implements \ArrayAccess
3639
];
3740

3841
protected array $specialProperties = [];
42+
protected RawRecord $rawRecord;
43+
protected ComputedProperties $computedProperties;
3944

4045
public function __construct(array $properties)
4146
{
47+
$translationSource = null;
48+
$localizedUid = null;
49+
$requestedOverlayLanguageId = null;
50+
4251
foreach ($properties as $propertyName => $propertyValue) {
4352
if (in_array($propertyName, $this->specialPropertyNames)) {
4453
if ($propertyName === '_TRANSLATION_SOURCE' && !$propertyValue instanceof Page) {
45-
$this->specialProperties[$propertyName] = new Page($propertyValue);
54+
$translationSource = new Page($propertyValue);
55+
$this->specialProperties[$propertyName] = $translationSource;
56+
} elseif ($propertyName === '_TRANSLATION_SOURCE') {
57+
$translationSource = $propertyValue;
58+
$this->specialProperties[$propertyName] = $propertyValue;
59+
} elseif ($propertyName === '_LOCALIZED_UID') {
60+
$localizedUid = $propertyValue;
61+
$this->specialProperties[$propertyName] = $propertyValue;
62+
} elseif ($propertyName === '_REQUESTED_OVERLAY_LANGUAGE') {
63+
$requestedOverlayLanguageId = $propertyValue;
64+
$this->specialProperties[$propertyName] = $propertyValue;
4665
} else {
4766
$this->specialProperties[$propertyName] = $propertyValue;
4867
}
4968
} else {
5069
$this->properties[$propertyName] = $propertyValue;
5170
}
5271
}
72+
73+
// Create computed properties from special properties
74+
$this->computedProperties = new ComputedProperties(
75+
versionedUid: null,
76+
localizedUid: $localizedUid,
77+
requestedOverlayLanguageId: $requestedOverlayLanguageId,
78+
translationSource: $translationSource
79+
);
80+
81+
// Determine record type for pages (based on doktype)
82+
$recordType = isset($this->properties['doktype']) ? (string)$this->properties['doktype'] : null;
83+
$fullType = $recordType !== null ? 'pages.' . $recordType : 'pages';
84+
85+
// Create RawRecord
86+
$this->rawRecord = new RawRecord(
87+
uid: (int)($this->properties['uid'] ?? 0),
88+
pid: (int)($this->properties['pid'] ?? 0),
89+
properties: $this->properties,
90+
computedProperties: $this->computedProperties,
91+
fullType: $fullType
92+
);
93+
}
94+
95+
// RecordInterface methods
96+
public function getUid(): int
97+
{
98+
return $this->rawRecord->getUid();
99+
}
100+
101+
public function getPid(): int
102+
{
103+
return $this->rawRecord->getPid();
104+
}
105+
106+
public function getFullType(): string
107+
{
108+
return $this->rawRecord->getFullType();
109+
}
110+
111+
public function getRecordType(): ?string
112+
{
113+
return $this->rawRecord->getRecordType();
114+
}
115+
116+
public function getMainType(): string
117+
{
118+
return $this->rawRecord->getMainType();
119+
}
120+
121+
public function getRawRecord(): RawRecord
122+
{
123+
return $this->rawRecord;
124+
}
125+
126+
public function getComputedProperties(): ComputedProperties
127+
{
128+
return $this->computedProperties;
129+
}
130+
131+
public function has(string $id): bool
132+
{
133+
if (array_key_exists($id, $this->properties)) {
134+
return true;
135+
}
136+
137+
if (in_array($id, ['uid', 'pid'], true)) {
138+
return true;
139+
}
140+
141+
if (array_key_exists($id, $this->specialProperties)) {
142+
return true;
143+
}
144+
145+
return false;
146+
}
147+
148+
public function get(string $id): mixed
149+
{
150+
if (array_key_exists($id, $this->properties)) {
151+
return $this->properties[$id];
152+
}
153+
154+
if ($id === 'uid') {
155+
return $this->rawRecord->getUid();
156+
}
157+
158+
if ($id === 'pid') {
159+
return $this->rawRecord->getPid();
160+
}
161+
162+
if (array_key_exists($id, $this->specialProperties)) {
163+
return $this->specialProperties[$id];
164+
}
165+
166+
throw new RecordPropertyNotFoundException('Record property "' . $id . '" is not available.', 1725892141);
53167
}
54168

169+
// Page-specific methods
55170
public function getLanguageId(): int
56171
{
57172
return $this->specialProperties['_language'] ?? $this->properties['sys_language_uid'];

0 commit comments

Comments
 (0)