Skip to content

Commit fa1bb98

Browse files
committed
[TASK] use ContentObjectRenderer
to get container child records for FE cleanup pageview layer unused method in database
1 parent 9d29e35 commit fa1bb98

File tree

15 files changed

+183
-429
lines changed

15 files changed

+183
-429
lines changed

Build/phpstan-baseline-11-7.4.neon

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Domain\\\\Repository\\\\PageRepository\\:\\:getLanguageOverlay\\(\\) invoked with 3 parameters, 2 required\\.$#"
5-
count: 1
6-
path: ../Classes/Domain/Factory/PageView/Frontend/ContainerFactory.php
73

84
-
95
message: "#^Constant LF not found\\.$#"

Build/phpstan-baseline-11.neon

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Domain\\\\Repository\\\\PageRepository\\:\\:getLanguageOverlay\\(\\) invoked with 3 parameters, 2 required\\.$#"
5-
count: 1
6-
path: ../Classes/Domain/Factory/PageView/Frontend/ContainerFactory.php
73

84
-
95
message: "#^Constant LF not found\\.$#"

Build/phpstan-baseline-12.neon

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Call to protected method getRecordOverlay\\(\\) of class TYPO3\\\\CMS\\\\Core\\\\Domain\\\\Repository\\\\PageRepository\\.$#"
5-
count: 1
6-
path: ../Classes/Domain/Factory/PageView/Frontend/ContainerFactory.php
73

84
-
95
message: "#^Constant LF not found\\.$#"

Build/phpstan-baseline-13.neon

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Database\\\\Query\\\\Restriction\\\\FrontendWorkspaceRestriction not found\\.$#"
5-
count: 1
6-
path: ../Classes/Domain/Factory/Database.php
7-
8-
-
9-
message: "#^Call to protected method getRecordOverlay\\(\\) of class TYPO3\\\\CMS\\\\Core\\\\Domain\\\\Repository\\\\PageRepository\\.$#"
10-
count: 1
11-
path: ../Classes/Domain/Factory/PageView/Frontend/ContainerFactory.php
12-
13-
-
14-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Domain\\\\Repository\\\\PageRepository\\:\\:getRecordOverlay\\(\\) invoked with 4 parameters, 3 required\\.$#"
15-
count: 1
16-
path: ../Classes/Domain/Factory/PageView/Frontend/ContainerFactory.php
17-
18-
-
19-
message: "#^Parameter \\#3 \\$languageAspect of method TYPO3\\\\CMS\\\\Core\\\\Domain\\\\Repository\\\\PageRepository\\:\\:getRecordOverlay\\(\\) expects TYPO3\\\\CMS\\\\Core\\\\Context\\\\LanguageAspect, int given\\.$#"
20-
count: 1
21-
path: ../Classes/Domain/Factory/PageView/Frontend/ContainerFactory.php
223

234
-
245
message: "#^Constant LF not found\\.$#"

Classes/DataProcessing/ContainerProcessor.php

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,31 @@
1313
*/
1414

1515
use B13\Container\Domain\Factory\Exception;
16-
use B13\Container\Domain\Factory\PageView\Frontend\ContainerFactory;
16+
use B13\Container\Domain\Factory\FrontendContainerFactory;
1717
use B13\Container\Domain\Model\Container;
1818
use Psr\Http\Message\ServerRequestInterface;
1919
use TYPO3\CMS\Core\Context\Context;
20-
use TYPO3\CMS\Core\Context\LanguageAspect;
2120
use TYPO3\CMS\Core\Utility\GeneralUtility;
2221
use TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor;
2322
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
2423
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
2524

2625
class ContainerProcessor implements DataProcessorInterface
2726
{
28-
/**
29-
* @var ContainerFactory
30-
*/
31-
protected $containerFactory;
3227

3328
/**
3429
* @var ContentDataProcessor
3530
*/
3631
protected $contentDataProcessor;
3732

3833
protected Context $context;
34+
protected FrontendContainerFactory $frontendContainerFactory;
3935

40-
public function __construct(ContainerFactory $containerFactory, ContentDataProcessor $contentDataProcessor, Context $context)
36+
public function __construct(ContentDataProcessor $contentDataProcessor, Context $context, FrontendContainerFactory $frontendContainerFactory)
4137
{
42-
$this->containerFactory = $containerFactory;
4338
$this->contentDataProcessor = $contentDataProcessor;
4439
$this->context = $context;
40+
$this->frontendContainerFactory = $frontendContainerFactory;
4541
}
4642

4743
public function process(
@@ -53,16 +49,15 @@ public function process(
5349
if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) {
5450
return $processedData;
5551
}
52+
$contentId = null;
5653
if ($processorConfiguration['contentId.'] ?? false) {
5754
$contentId = (int)$cObj->stdWrap($processorConfiguration['contentId'], $processorConfiguration['contentId.']);
5855
} elseif ($processorConfiguration['contentId'] ?? false) {
5956
$contentId = (int)$processorConfiguration['contentId'];
60-
} else {
61-
$contentId = (int)$cObj->data['uid'];
6257
}
6358

6459
try {
65-
$container = $this->containerFactory->buildContainer($contentId);
60+
$container = $this->frontendContainerFactory->buildContainer($cObj, $this->context, $contentId);
6661
} catch (Exception $e) {
6762
// do nothing
6863
return $processedData;
@@ -109,22 +104,12 @@ protected function processColPos(
109104
if ($contentRecordRenderer === null) {
110105
throw new ContainerDataProcessingFailedException('RECORDS content object not available.', 1691483526);
111106
}
112-
113107
$conf = [
114108
'tables' => 'tt_content',
115109
];
116-
/** @var LanguageAspect $languageAspect */
117-
$languageAspect = $this->context->getAspect('language');
118110
foreach ($children as &$child) {
119111
if (!isset($processorConfiguration['skipRenderingChildContent']) || (int)$processorConfiguration['skipRenderingChildContent'] === 0) {
120-
if ($child['l18n_parent'] > 0 && $languageAspect->doOverlays()) {
121-
$conf['source'] = $child['l18n_parent'];
122-
} else {
123-
$conf['source'] = $child['uid'];
124-
}
125-
if ($child['t3ver_oid'] > 0) {
126-
$conf['source'] = $child['t3ver_oid'];
127-
}
112+
$conf['source'] = $child['uid'];
128113
$child['renderedContent'] = $cObj->render($contentRecordRenderer, $conf);
129114
}
130115
/** @var ContentObjectRenderer $recordContentObjectRenderer */

Classes/Domain/Factory/Database.php

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,12 @@
1212
* of the License, or any later version.
1313
*/
1414

15-
use Psr\Http\Message\ServerRequestInterface;
1615
use TYPO3\CMS\Core\Context\Context;
1716
use TYPO3\CMS\Core\Database\Connection;
1817
use TYPO3\CMS\Core\Database\ConnectionPool;
1918
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
2019
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
21-
use TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer;
22-
use TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction;
23-
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
2420
use TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction;
25-
use TYPO3\CMS\Core\Http\ApplicationType;
26-
use TYPO3\CMS\Core\Information\Typo3Version;
2721
use TYPO3\CMS\Core\SingletonInterface;
2822
use TYPO3\CMS\Core\Utility\GeneralUtility;
2923

@@ -48,33 +42,13 @@ public function __construct(Context $context)
4842
protected function getQueryBuilder(): QueryBuilder
4943
{
5044
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
51-
if ($this->getServerRequest() instanceof ServerRequestInterface
52-
&& ApplicationType::fromRequest($this->getServerRequest())->isFrontend()
53-
) {
54-
$queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));
55-
if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() < 12) {
56-
// do not use FrontendWorkspaceRestriction
57-
$queryBuilder->getRestrictions()
58-
->removeByType(FrontendWorkspaceRestriction::class)
59-
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->workspaceId));
60-
}
61-
if ($this->workspaceId > 0) {
62-
$queryBuilder->getRestrictions()->removeByType(HiddenRestriction::class);
63-
}
64-
} else {
65-
$queryBuilder->getRestrictions()
66-
->removeAll()
67-
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
68-
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->workspaceId));
69-
}
45+
$queryBuilder->getRestrictions()
46+
->removeAll()
47+
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
48+
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->workspaceId));
7049
return $queryBuilder;
7150
}
7251

73-
protected function getServerRequest(): ?ServerRequestInterface
74-
{
75-
return $GLOBALS['TYPO3_REQUEST'] ?? null;
76-
}
77-
7852
public function fetchRecordsByPidAndLanguage(int $pid, int $language): array
7953
{
8054
$queryBuilder = $this->getQueryBuilder();
@@ -187,27 +161,4 @@ public function fetchOverlayRecords(array $records, int $language): array
187161
->fetchAllAssociative();
188162
return $rows;
189163
}
190-
191-
public function fetchOneOverlayRecord(int $uid, int $language): ?array
192-
{
193-
$queryBuilder = $this->getQueryBuilder();
194-
$record = $queryBuilder->select('*')
195-
->from('tt_content')
196-
->where(
197-
$queryBuilder->expr()->eq(
198-
'l18n_parent',
199-
$queryBuilder->createNamedParameter($uid, Connection::PARAM_INT)
200-
),
201-
$queryBuilder->expr()->eq(
202-
'sys_language_uid',
203-
$queryBuilder->createNamedParameter($language, Connection::PARAM_INT)
204-
)
205-
)
206-
->executeQuery()
207-
->fetchAssociative();
208-
if ($record === false) {
209-
return null;
210-
}
211-
return $record;
212-
}
213164
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace B13\Container\Domain\Factory;
6+
7+
/*
8+
* This file is part of TYPO3 CMS-based extension "container" by b13.
9+
*
10+
* It is free software; you can redistribute it and/or modify it under
11+
* the terms of the GNU General Public License, either version 2
12+
* of the License, or any later version.
13+
*/
14+
15+
use B13\Container\Domain\Model\Container;
16+
use B13\Container\Tca\Registry;
17+
use TYPO3\CMS\Core\Context\Context;
18+
use TYPO3\CMS\Core\Context\LanguageAspect;
19+
use TYPO3\CMS\Core\SingletonInterface;
20+
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
21+
22+
class FrontendContainerFactory implements SingletonInterface
23+
{
24+
25+
protected Registry $tcaRegistry;
26+
27+
public function __construct(Registry $tcaRegistry)
28+
{
29+
$this->tcaRegistry = $tcaRegistry;
30+
}
31+
32+
public function buildContainer(ContentObjectRenderer $cObj, Context $context, ?int $uid = null): Container
33+
{
34+
if ($uid === null) {
35+
$record = $cObj->data;
36+
} else {
37+
$records = $cObj->getRecords('tt_content', ['where' => 'uid=' . $uid]);
38+
if (empty($records)) {
39+
throw new Exception('no record ' . $uid, 1734946029);
40+
}
41+
$record = $records[0];
42+
}
43+
if (!$this->tcaRegistry->isContainerElement($record['CType'])) {
44+
throw new Exception('not a container element with uid ' . $uid, 1734946028);
45+
}
46+
$conf = ['where' => 'tx_container_parent=' . $record['uid']];
47+
/** @var LanguageAspect $languageAspect */
48+
$languageAspect = $context->getAspect('language');
49+
if ($languageAspect->getOverlayType() === LanguageAspect::OVERLAYS_OFF && $record['l18n_parent'] > 0) {
50+
$conf['where'] .= ' OR tx_container_parent=' . $record['l18n_parent'];
51+
}
52+
$childRecords = $cObj->getRecords('tt_content', $conf);
53+
$childRecords = $this->recordsByColPosKey($childRecords);
54+
$container = new Container($record, $childRecords, (int)$record['sys_language_uid']);
55+
return $container;
56+
}
57+
58+
protected function recordsByColPosKey(array $records): array
59+
{
60+
$recordsByColPosKey = [];
61+
foreach ($records as $record) {
62+
if (empty($recordsByColPosKey[$record['colPos']])) {
63+
$recordsByColPosKey[$record['colPos']] = [];
64+
}
65+
$recordsByColPosKey[$record['colPos']][] = $record;
66+
}
67+
return $recordsByColPosKey;
68+
}
69+
}

Classes/Domain/Factory/PageView/Backend/ContainerFactory.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use B13\Container\Tca\Registry;
1717
use TYPO3\CMS\Core\Context\Context;
1818

19-
class ContainerFactory extends \B13\Container\Domain\Factory\PageView\ContainerFactory
19+
class ContainerFactory extends \B13\Container\Domain\Factory\ContainerFactory
2020
{
2121
/**
2222
* @var ContentStorage
@@ -32,4 +32,36 @@ public function __construct(
3232
parent::__construct($database, $tcaRegistry, $context);
3333
$this->contentStorage = $contentStorage;
3434
}
35+
36+
protected function children(array $containerRecord, int $language): array
37+
{
38+
return $this->contentStorage->getContainerChildren($containerRecord, $language);
39+
}
40+
41+
protected function localizedRecordsByDefaultRecords(array $defaultRecords, int $language): array
42+
{
43+
$childRecords = parent::localizedRecordsByDefaultRecords($defaultRecords, $language);
44+
return $this->contentStorage->workspaceOverlay($childRecords);
45+
}
46+
47+
protected function containerByUid(int $uid): ?array
48+
{
49+
$record = $this->database->fetchOneRecord($uid);
50+
if ($record === null) {
51+
return null;
52+
}
53+
return $this->contentStorage->containerRecordWorkspaceOverlay($record);
54+
}
55+
56+
protected function defaultContainer(array $localizedContainer): ?array
57+
{
58+
if (isset($localizedContainer['_ORIG_uid'])) {
59+
$localizedContainer = $this->database->fetchOneRecord((int)$localizedContainer['uid']);
60+
}
61+
$defaultRecord = $this->database->fetchOneDefaultRecord($localizedContainer);
62+
if ($defaultRecord === null) {
63+
return null;
64+
}
65+
return $this->contentStorage->containerRecordWorkspaceOverlay($defaultRecord);
66+
}
3567
}

0 commit comments

Comments
 (0)