-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLEANUP: Make Rootline class a factory
- Loading branch information
1 parent
941c219
commit ff1e07c
Showing
3 changed files
with
27 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
declare(strict_types=1); | ||
|
||
namespace Codappix\ResponsiveImages\Sizes; | ||
namespace Codappix\ResponsiveImages\Domain\Factory; | ||
|
||
/* | ||
* Copyright (C) 2024 Justus Moroni <[email protected]> | ||
|
@@ -26,41 +26,44 @@ | |
|
||
use B13\Container\Tca\Registry; | ||
use Codappix\ResponsiveImages\Domain\Repository\ContainerRepository; | ||
use Codappix\ResponsiveImages\Sizes\BackendLayout; | ||
use Codappix\ResponsiveImages\Sizes\BackendLayoutColumn; | ||
use Codappix\ResponsiveImages\Sizes\Container; | ||
use Codappix\ResponsiveImages\Sizes\ContainerColumn; | ||
use Codappix\ResponsiveImages\Sizes\ContentElement; | ||
use Codappix\ResponsiveImages\Sizes\ContentElementInterface; | ||
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Frontend\Page\PageLayoutResolver; | ||
|
||
final class Rootline | ||
final class RootlineFactory | ||
{ | ||
private readonly ContentElementInterface $contentElement; | ||
|
||
private BackendLayout $backendLayout; | ||
|
||
private array $finalSizes = []; | ||
|
||
private string $fieldName; | ||
|
||
private string $backendLayoutIdentifier; | ||
|
||
public function __construct( | ||
private ContainerRepository $containerRepository, | ||
private readonly ContainerRepository $containerRepository, | ||
private readonly PageLayoutResolver $pageLayoutResolver | ||
) { | ||
} | ||
|
||
public function getFinalSizes( | ||
array $data, | ||
string $fieldName | ||
) { | ||
): array { | ||
$this->determineBackendLayout(); | ||
|
||
$this->fieldName = $fieldName; | ||
$this->contentElement = $this->determineContentElement(null, $data); | ||
$contentElement = $this->determineContentElement(null, $data); | ||
|
||
$this->determineRootline($this->contentElement); | ||
$this->determineRootline($contentElement); | ||
|
||
$this->finalSizes = $this->contentElement->getFinalSize([]); | ||
} | ||
|
||
public function getFinalSizes(): array | ||
{ | ||
$sizes = $this->finalSizes; | ||
$sizes = $contentElement->getFinalSize([]); | ||
|
||
foreach ($sizes as $sizeName => &$size) { | ||
foreach ($sizes as &$size) { | ||
$size = ceil($size); | ||
} | ||
|
||
|
@@ -71,9 +74,10 @@ private function determineBackendLayout(): void | |
{ | ||
$typoscriptFrontendController = $GLOBALS['TSFE']; | ||
|
||
$this->backendLayoutIdentifier = GeneralUtility::makeInstance(PageLayoutResolver::class) | ||
->getLayoutForPage($typoscriptFrontendController->page, $typoscriptFrontendController->rootLine) | ||
; | ||
$this->backendLayoutIdentifier = $this->pageLayoutResolver->getLayoutForPage( | ||
$typoscriptFrontendController->page, | ||
$typoscriptFrontendController->rootLine | ||
); | ||
|
||
$this->backendLayout = new BackendLayout($this->backendLayoutIdentifier); | ||
} | ||
|
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