Skip to content

Commit 4eb06bf

Browse files
committed
[TASK] cleanup pageview layer
1 parent 580f871 commit 4eb06bf

File tree

7 files changed

+103
-175
lines changed

7 files changed

+103
-175
lines changed

Build/phpstan-baseline-13.neon

-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +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
73

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

Classes/Domain/Factory/Database.php

+4-30
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();

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

+33-1
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
}

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

+64-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,74 @@
1212
* of the License, or any later version.
1313
*/
1414

15+
use B13\Container\Domain\Factory\Database;
1516
use TYPO3\CMS\Backend\Utility\BackendUtility;
17+
use TYPO3\CMS\Core\Context\Context;
1618
use TYPO3\CMS\Core\Versioning\VersionState;
1719

18-
class ContentStorage extends \B13\Container\Domain\Factory\PageView\ContentStorage
20+
class ContentStorage
1921
{
22+
/**
23+
* @var ?mixed[]
24+
*/
25+
protected $records;
26+
27+
/**
28+
* @var Database
29+
*/
30+
protected $database;
31+
32+
/**
33+
* @var int
34+
*/
35+
protected $workspaceId = 0;
36+
37+
public function __construct(Database $database, Context $context)
38+
{
39+
$this->database = $database;
40+
$this->workspaceId = (int)$context->getPropertyFromAspect('workspace', 'id');
41+
}
42+
43+
protected function buildRecords(int $pid, int $language): array
44+
{
45+
$records = $this->database->fetchRecordsByPidAndLanguage($pid, $language);
46+
$records = $this->workspaceOverlay($records);
47+
$records = $this->recordsByContainer($records);
48+
return $records;
49+
}
50+
51+
protected function recordsByContainer(array $records): array
52+
{
53+
$recordsByContainer = [];
54+
foreach ($records as $record) {
55+
if ($record['tx_container_parent'] > 0) {
56+
if (empty($recordsByContainer[$record['tx_container_parent']])) {
57+
$recordsByContainer[$record['tx_container_parent']] = [];
58+
}
59+
$recordsByContainer[$record['tx_container_parent']][] = $record;
60+
}
61+
}
62+
return $recordsByContainer;
63+
}
64+
65+
public function getContainerChildren(array $containerRecord, int $language): array
66+
{
67+
$pid = (int)$containerRecord['pid'];
68+
if (isset($containerRecord['t3ver_oid']) && $containerRecord['t3ver_oid'] > 0) {
69+
$defaultContainerRecord = $this->database->fetchOneRecord((int)$containerRecord['t3ver_oid']);
70+
$uid = (int)$defaultContainerRecord['uid'];
71+
} else {
72+
$uid = (int)$containerRecord['uid'];
73+
}
74+
if (!isset($this->records[$pid][$language])) {
75+
$this->records[$pid][$language] = $this->buildRecords($pid, $language);
76+
}
77+
if (empty($this->records[$pid][$language][$uid])) {
78+
return [];
79+
}
80+
return $this->records[$pid][$language][$uid];
81+
}
82+
2083
public function workspaceOverlay(array $records): array
2184
{
2285
$filtered = [];

Classes/Domain/Factory/PageView/ContainerFactory.php

-53
This file was deleted.

Classes/Domain/Factory/PageView/ContentStorage.php

-84
This file was deleted.

Tests/Unit/Domain/Factory/PageView/ContainerFactoryTest.php Tests/Unit/Domain/Factory/PageView/Backend/ContainerFactoryTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace B13\Container\Tests\Unit\Domain\Factory\PageView;
5+
namespace B13\Container\Tests\Unit\Domain\Factory\PageView\Backend;
66

77
/*
88
* This file is part of TYPO3 CMS-based extension "container" by b13.
@@ -13,7 +13,7 @@
1313
*/
1414

1515
use B13\Container\Domain\Factory\Database;
16-
use B13\Container\Domain\Factory\PageView\ContainerFactory;
16+
use B13\Container\Domain\Factory\PageView\Backend\ContainerFactory;
1717
use B13\Container\Tca\Registry;
1818
use TYPO3\CMS\Core\Context\Context;
1919
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

0 commit comments

Comments
 (0)