Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Build/phpstan-baseline-11-7.4.neon
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Domain\\\\Repository\\\\PageRepository\\:\\:getLanguageOverlay\\(\\) invoked with 3 parameters, 2 required\\.$#"
count: 1
path: ../Classes/Domain/Factory/PageView/Frontend/ContainerFactory.php

-
message: "#^Constant LF not found\\.$#"
Expand Down
4 changes: 0 additions & 4 deletions Build/phpstan-baseline-11.neon
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Domain\\\\Repository\\\\PageRepository\\:\\:getLanguageOverlay\\(\\) invoked with 3 parameters, 2 required\\.$#"
count: 1
path: ../Classes/Domain/Factory/PageView/Frontend/ContainerFactory.php

-
message: "#^Constant LF not found\\.$#"
Expand Down
4 changes: 0 additions & 4 deletions Build/phpstan-baseline-12.neon
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Call to protected method getRecordOverlay\\(\\) of class TYPO3\\\\CMS\\\\Core\\\\Domain\\\\Repository\\\\PageRepository\\.$#"
count: 1
path: ../Classes/Domain/Factory/PageView/Frontend/ContainerFactory.php

-
message: "#^Constant LF not found\\.$#"
Expand Down
19 changes: 0 additions & 19 deletions Build/phpstan-baseline-13.neon
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Database\\\\Query\\\\Restriction\\\\FrontendWorkspaceRestriction not found\\.$#"
count: 1
path: ../Classes/Domain/Factory/Database.php

-
message: "#^Call to protected method getRecordOverlay\\(\\) of class TYPO3\\\\CMS\\\\Core\\\\Domain\\\\Repository\\\\PageRepository\\.$#"
count: 1
path: ../Classes/Domain/Factory/PageView/Frontend/ContainerFactory.php

-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Domain\\\\Repository\\\\PageRepository\\:\\:getRecordOverlay\\(\\) invoked with 4 parameters, 3 required\\.$#"
count: 1
path: ../Classes/Domain/Factory/PageView/Frontend/ContainerFactory.php

-
message: "#^Parameter \\#3 \\$languageAspect of method TYPO3\\\\CMS\\\\Core\\\\Domain\\\\Repository\\\\PageRepository\\:\\:getRecordOverlay\\(\\) expects TYPO3\\\\CMS\\\\Core\\\\Context\\\\LanguageAspect, int given\\.$#"
count: 1
path: ../Classes/Domain/Factory/PageView/Frontend/ContainerFactory.php

-
message: "#^Constant LF not found\\.$#"
Expand Down
29 changes: 7 additions & 22 deletions Classes/DataProcessing/ContainerProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,31 @@
*/

use B13\Container\Domain\Factory\Exception;
use B13\Container\Domain\Factory\PageView\Frontend\ContainerFactory;
use B13\Container\Domain\Factory\FrontendContainerFactory;
use B13\Container\Domain\Model\Container;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\LanguageAspect;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;

class ContainerProcessor implements DataProcessorInterface
{
/**
* @var ContainerFactory
*/
protected $containerFactory;

/**
* @var ContentDataProcessor
*/
protected $contentDataProcessor;

protected Context $context;
protected FrontendContainerFactory $frontendContainerFactory;

public function __construct(ContainerFactory $containerFactory, ContentDataProcessor $contentDataProcessor, Context $context)
public function __construct(ContentDataProcessor $contentDataProcessor, Context $context, FrontendContainerFactory $frontendContainerFactory)
{
$this->containerFactory = $containerFactory;
$this->contentDataProcessor = $contentDataProcessor;
$this->context = $context;
$this->frontendContainerFactory = $frontendContainerFactory;
}

public function process(
Expand All @@ -53,16 +49,15 @@ public function process(
if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) {
return $processedData;
}
$contentId = null;
if ($processorConfiguration['contentId.'] ?? false) {
$contentId = (int)$cObj->stdWrap($processorConfiguration['contentId'], $processorConfiguration['contentId.']);
} elseif ($processorConfiguration['contentId'] ?? false) {
$contentId = (int)$processorConfiguration['contentId'];
} else {
$contentId = (int)$cObj->data['uid'];
}

try {
$container = $this->containerFactory->buildContainer($contentId);
$container = $this->frontendContainerFactory->buildContainer($cObj, $this->context, $contentId);
} catch (Exception $e) {
// do nothing
return $processedData;
Expand Down Expand Up @@ -109,22 +104,12 @@ protected function processColPos(
if ($contentRecordRenderer === null) {
throw new ContainerDataProcessingFailedException('RECORDS content object not available.', 1691483526);
}

$conf = [
'tables' => 'tt_content',
];
/** @var LanguageAspect $languageAspect */
$languageAspect = $this->context->getAspect('language');
foreach ($children as &$child) {
if (!isset($processorConfiguration['skipRenderingChildContent']) || (int)$processorConfiguration['skipRenderingChildContent'] === 0) {
if ($child['l18n_parent'] > 0 && $languageAspect->doOverlays()) {
$conf['source'] = $child['l18n_parent'];
} else {
$conf['source'] = $child['uid'];
}
if ($child['t3ver_oid'] > 0) {
$conf['source'] = $child['t3ver_oid'];
}
$conf['source'] = $child['uid'];
$child['renderedContent'] = $cObj->render($contentRecordRenderer, $conf);
}
/** @var ContentObjectRenderer $recordContentObjectRenderer */
Expand Down
57 changes: 4 additions & 53 deletions Classes/Domain/Factory/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,12 @@
* of the License, or any later version.
*/

use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer;
use TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand All @@ -48,33 +42,13 @@ public function __construct(Context $context)
protected function getQueryBuilder(): QueryBuilder
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
if ($this->getServerRequest() instanceof ServerRequestInterface
&& ApplicationType::fromRequest($this->getServerRequest())->isFrontend()
) {
$queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));
if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() < 12) {
// do not use FrontendWorkspaceRestriction
$queryBuilder->getRestrictions()
->removeByType(FrontendWorkspaceRestriction::class)
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->workspaceId));
}
if ($this->workspaceId > 0) {
$queryBuilder->getRestrictions()->removeByType(HiddenRestriction::class);
}
} else {
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->workspaceId));
}
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->workspaceId));
return $queryBuilder;
}

protected function getServerRequest(): ?ServerRequestInterface
{
return $GLOBALS['TYPO3_REQUEST'] ?? null;
}

public function fetchRecordsByPidAndLanguage(int $pid, int $language): array
{
$queryBuilder = $this->getQueryBuilder();
Expand Down Expand Up @@ -187,27 +161,4 @@ public function fetchOverlayRecords(array $records, int $language): array
->fetchAllAssociative();
return $rows;
}

public function fetchOneOverlayRecord(int $uid, int $language): ?array
{
$queryBuilder = $this->getQueryBuilder();
$record = $queryBuilder->select('*')
->from('tt_content')
->where(
$queryBuilder->expr()->eq(
'l18n_parent',
$queryBuilder->createNamedParameter($uid, Connection::PARAM_INT)
),
$queryBuilder->expr()->eq(
'sys_language_uid',
$queryBuilder->createNamedParameter($language, Connection::PARAM_INT)
)
)
->executeQuery()
->fetchAssociative();
if ($record === false) {
return null;
}
return $record;
}
}
69 changes: 69 additions & 0 deletions Classes/Domain/Factory/FrontendContainerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

namespace B13\Container\Domain\Factory;

/*
* This file is part of TYPO3 CMS-based extension "container" by b13.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*/

use B13\Container\Domain\Model\Container;
use B13\Container\Tca\Registry;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\LanguageAspect;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;

class FrontendContainerFactory implements SingletonInterface
{

protected Registry $tcaRegistry;

public function __construct(Registry $tcaRegistry)
{
$this->tcaRegistry = $tcaRegistry;
}

public function buildContainer(ContentObjectRenderer $cObj, Context $context, ?int $uid = null): Container
{
if ($uid === null) {
$record = $cObj->data;
} else {
$records = $cObj->getRecords('tt_content', ['where' => 'uid=' . $uid]);
if (empty($records)) {
throw new Exception('no record ' . $uid, 1734946029);
}
$record = $records[0];
}
if (!$this->tcaRegistry->isContainerElement($record['CType'])) {
throw new Exception('not a container element with uid ' . $uid, 1734946028);
}
$conf = ['where' => 'tx_container_parent=' . $record['uid']];
/** @var LanguageAspect $languageAspect */
$languageAspect = $context->getAspect('language');
if ($languageAspect->getOverlayType() === LanguageAspect::OVERLAYS_OFF && $record['l18n_parent'] > 0) {
$conf['where'] .= ' OR tx_container_parent=' . $record['l18n_parent'];
}
$childRecords = $cObj->getRecords('tt_content', $conf);
$childRecords = $this->recordsByColPosKey($childRecords);
$container = new Container($record, $childRecords, (int)$record['sys_language_uid']);
return $container;
}

protected function recordsByColPosKey(array $records): array
{
$recordsByColPosKey = [];
foreach ($records as $record) {
if (empty($recordsByColPosKey[$record['colPos']])) {
$recordsByColPosKey[$record['colPos']] = [];
}
$recordsByColPosKey[$record['colPos']][] = $record;
}
return $recordsByColPosKey;
}
}
34 changes: 33 additions & 1 deletion Classes/Domain/Factory/PageView/Backend/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use B13\Container\Tca\Registry;
use TYPO3\CMS\Core\Context\Context;

class ContainerFactory extends \B13\Container\Domain\Factory\PageView\ContainerFactory
class ContainerFactory extends \B13\Container\Domain\Factory\ContainerFactory
{
/**
* @var ContentStorage
Expand All @@ -32,4 +32,36 @@ public function __construct(
parent::__construct($database, $tcaRegistry, $context);
$this->contentStorage = $contentStorage;
}

protected function children(array $containerRecord, int $language): array
{
return $this->contentStorage->getContainerChildren($containerRecord, $language);
}

protected function localizedRecordsByDefaultRecords(array $defaultRecords, int $language): array
{
$childRecords = parent::localizedRecordsByDefaultRecords($defaultRecords, $language);
return $this->contentStorage->workspaceOverlay($childRecords);
}

protected function containerByUid(int $uid): ?array
{
$record = $this->database->fetchOneRecord($uid);
if ($record === null) {
return null;
}
return $this->contentStorage->containerRecordWorkspaceOverlay($record);
}

protected function defaultContainer(array $localizedContainer): ?array
{
if (isset($localizedContainer['_ORIG_uid'])) {
$localizedContainer = $this->database->fetchOneRecord((int)$localizedContainer['uid']);
}
$defaultRecord = $this->database->fetchOneDefaultRecord($localizedContainer);
if ($defaultRecord === null) {
return null;
}
return $this->contentStorage->containerRecordWorkspaceOverlay($defaultRecord);
}
}
Loading