Skip to content

Commit

Permalink
CLEANUP: Use determineContainerColumn only one time
Browse files Browse the repository at this point in the history
  • Loading branch information
d-g-codappix committed Apr 10, 2024
1 parent fc27504 commit 92182ff
Showing 1 changed file with 51 additions and 68 deletions.
119 changes: 51 additions & 68 deletions Classes/Domain/Factory/RootlineFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,16 @@
* 02110-1301, USA.
*/

use B13\Container\Tca\Registry;
use Codappix\ResponsiveImages\Domain\Model\BackendLayoutInterface;
use Codappix\ResponsiveImages\Domain\Model\RootlineElementInterface;
use Codappix\ResponsiveImages\Domain\Repository\ContainerRepository;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Page\PageLayoutResolver;

final class RootlineFactory
{
private BackendLayoutInterface $backendLayout;

private string $fieldName;

private string $backendLayoutIdentifier;

public function __construct(
Expand All @@ -54,8 +50,7 @@ public function getFinalSizes(
): array {
$this->determineBackendLayout();

$this->fieldName = $fieldName;
$contentElement = $this->determineContentElement(null, $data);
$contentElement = $this->determineContentElement($data, $fieldName);

$this->determineRootline($contentElement);

Expand All @@ -68,6 +63,19 @@ public function getFinalSizes(
return $sizes;
}

public function determineContainerColumn(
array $data,
RootlineElementInterface $contentElement
): RootlineElementInterface {
$newContainerColumn = $this->rootlineElementFactory->create(
$data,
$this->getConfigPathForContainerColumn($data['CType'], $contentElement)
);
$contentElement->setParent($newContainerColumn);

return $newContainerColumn;
}

private function determineBackendLayout(): void
{
$tsfe = $GLOBALS['TSFE'];
Expand All @@ -82,52 +90,7 @@ private function determineBackendLayout(): void
);
}

private function determineRootline(RootlineElementInterface $contentElement): void
{
if (in_array($contentElement->getColPos(), $this->backendLayout->getColumns(), true)) {
$this->detarmineBackendLayout($contentElement);

return;
}

if (ExtensionManagementUtility::isLoaded('b13/container')) {
$parentContainer = $contentElement->getData('tx_container_parent');
assert(is_int($parentContainer));

$parent = $this->determineContentElement(
$contentElement,
$this->containerRepository->findByIdentifier($parentContainer)
);

$this->determineRootline($parent);
}
}

private function determineContentElement(
?RootlineElementInterface $contentElement,
array $data
): RootlineElementInterface {
if (
class_exists(Registry::class)
&& GeneralUtility::makeInstance(Registry::class)->isContainerElement($data['CType'])
&& !is_null($contentElement)
) {
return $this->determineContainer($data, $contentElement);
}

$newContentElement = $this->rootlineElementFactory->create(
$data,
$this->getConfigPathForContentElement($data['CType'])
);

if (!is_null($contentElement)) {
$contentElement->setParent($newContentElement);
}

return $newContentElement;
}

private function detarmineBackendLayout(RootlineElementInterface $contentElement): void
private function determineBackendLayoutColumn(RootlineElementInterface $contentElement): void
{
$newBackendLayoutColumn = $this->rootlineElementFactory->create(
[],
Expand All @@ -138,13 +101,23 @@ private function detarmineBackendLayout(RootlineElementInterface $contentElement
$contentElement->setParent($newBackendLayoutColumn);
}

private function determineContainer(array $data, RootlineElementInterface $contentElement): RootlineElementInterface
{
$newContainerColumn = $this->rootlineElementFactory->create(
private function determineContentElement(
array $data,
string $fieldName
): RootlineElementInterface {
return $this->rootlineElementFactory->create(
$data,
$this->getConfigPathForContainerColumn($data['CType'], $contentElement)
implode('.', [
'contentelements',
$data['CType'],
$fieldName,
])
);
$contentElement->setParent($newContainerColumn);
}

private function determineContainer(array $data, RootlineElementInterface $contentElement): RootlineElementInterface
{
$newContainerColumn = $this->determineContainerColumn($data, $contentElement);

$newContainer = $this->rootlineElementFactory->create(
$data,
Expand All @@ -155,13 +128,25 @@ private function determineContainer(array $data, RootlineElementInterface $conte
return $newContainer;
}

private function getConfigPathForContentElement(string $CType): string
private function determineRootline(RootlineElementInterface $contentElement): void
{
return implode('.', [
'contentelements',
$CType,
$this->fieldName,
]);
if (in_array($contentElement->getColPos(), $this->backendLayout->getColumns(), true)) {
$this->determineBackendLayoutColumn($contentElement);

return;
}

if (ExtensionManagementUtility::isLoaded('b13/container')) {
$parentContainer = $contentElement->getData('tx_container_parent');
assert(is_int($parentContainer));

$parent = $this->determineContainer(
$this->containerRepository->findByIdentifier($parentContainer),
$contentElement
);

$this->determineRootline($parent);
}
}

private function getConfigPathForContainer(string $CType): string
Expand All @@ -175,8 +160,7 @@ private function getConfigPathForContainer(string $CType): string
private function getConfigPathForContainerColumn(string $CType, RootlineElementInterface $contentElement): string
{
return implode('.', [
'container',
$CType,
$this->getConfigPathForContainer($CType),
'columns',
(string) $contentElement->getColPos(),
]);
Expand All @@ -193,10 +177,9 @@ private function getConfigPathForBackendLayout(): string
private function getConfigPathForBackendLayoutColumn(RootlineElementInterface $contentElement): string
{
return implode('.', [
'backendlayouts',
$this->backendLayoutIdentifier,
$this->getConfigPathForBackendLayout(),
'columns',
$contentElement->getColPos(),
(string) $contentElement->getColPos(),
]);
}
}

0 comments on commit 92182ff

Please sign in to comment.