Skip to content

Commit

Permalink
[TASK] use ContentObjectRenderer to get container child records
Browse files Browse the repository at this point in the history
  • Loading branch information
achimfritz committed Dec 24, 2024
1 parent 22538e6 commit aa14963
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 230 deletions.
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
15 changes: 0 additions & 15 deletions Build/phpstan-baseline-13.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,6 @@ parameters:
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\\.$#"
count: 4
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
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;
}
}
118 changes: 0 additions & 118 deletions Classes/Domain/Factory/PageView/Frontend/ContainerFactory.php

This file was deleted.

62 changes: 0 additions & 62 deletions Classes/Domain/Factory/PageView/Frontend/ContentStorage.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
,"uid","pid","CType","header","colPos","tx_container_parent","t3ver_wsid","t3ver_oid","t3ver_state"
,200,1,"b13-2cols-with-header-container",,,,,,
,201,1,"header","header-live",0,0,0,,
,202,1,"header","header-ws",200,200,1,201,0
,202,1,"header","header-ws",200,200,1,201,4

0 comments on commit aa14963

Please sign in to comment.