diff --git a/Classes/DataProcessing/ContainerProcessor.php b/Classes/DataProcessing/ContainerProcessor.php index fbf7d0d7..4c58f986 100644 --- a/Classes/DataProcessing/ContainerProcessor.php +++ b/Classes/DataProcessing/ContainerProcessor.php @@ -13,11 +13,10 @@ */ 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; @@ -25,10 +24,6 @@ class ContainerProcessor implements DataProcessorInterface { - /** - * @var ContainerFactory - */ - protected $containerFactory; /** * @var ContentDataProcessor @@ -36,12 +31,13 @@ class ContainerProcessor implements DataProcessorInterface 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( @@ -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; @@ -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 */ diff --git a/Classes/Domain/Factory/FrontendContainerFactory.php b/Classes/Domain/Factory/FrontendContainerFactory.php new file mode 100644 index 00000000..b39e78d7 --- /dev/null +++ b/Classes/Domain/Factory/FrontendContainerFactory.php @@ -0,0 +1,69 @@ +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; + } +} diff --git a/Tests/Functional/Frontend/Fixtures/Workspace/container_with_ws_child_moved_from_outside.csv b/Tests/Functional/Frontend/Fixtures/Workspace/container_with_ws_child_moved_from_outside.csv index 78f879a0..45b07556 100644 --- a/Tests/Functional/Frontend/Fixtures/Workspace/container_with_ws_child_moved_from_outside.csv +++ b/Tests/Functional/Frontend/Fixtures/Workspace/container_with_ws_child_moved_from_outside.csv @@ -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 \ No newline at end of file +,202,1,"header","header-ws",200,200,1,201,4 \ No newline at end of file