-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
to get container child records for FE cleanup pageview layer unused method in database
- Loading branch information
1 parent
9d29e35
commit fa1bb98
Showing
15 changed files
with
183 additions
and
429 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.