-
-
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.
TASK: Allow sizes and multiplier for container (#26)
* Daniel Siepmann couldn't resist to miss use this review to refactor the architecture. Related: #22 --------- Co-authored-by: Daniel Gohlke <[email protected]> Co-authored-by: Daniel Siepmann <[email protected]>
- Loading branch information
1 parent
b72561d
commit 694f7a8
Showing
33 changed files
with
998 additions
and
665 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Codappix\ResponsiveImages\Domain\Factory; | ||
|
||
/* | ||
* Copyright (C) 2024 Daniel Gohlke <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
use Codappix\ResponsiveImages\Configuration\ConfigurationManager; | ||
use Codappix\ResponsiveImages\Domain\Model\Breakpoint; | ||
|
||
final class BreakpointFactory | ||
{ | ||
public function __construct( | ||
private readonly ConfigurationManager $configurationManager | ||
) { | ||
} | ||
|
||
/** | ||
* @return Breakpoint[] | ||
*/ | ||
public function getByConfigurationPath(array|string $configurationPath): array | ||
{ | ||
$breakpoints = []; | ||
|
||
$breakpointsByPath = $this->configurationManager->getByPath($configurationPath); | ||
|
||
if (is_iterable($breakpointsByPath)) { | ||
foreach ($breakpointsByPath as $breakpointIdentifier => $breakpointData) { | ||
$breakpoints[$breakpointIdentifier] = new Breakpoint($breakpointIdentifier, $breakpointData); | ||
} | ||
} | ||
|
||
return $breakpoints; | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Codappix\ResponsiveImages\Domain\Factory; | ||
|
||
/* | ||
* Copyright (C) 2024 Daniel Gohlke <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
use Codappix\ResponsiveImages\Domain\Model\RootlineElement; | ||
use Codappix\ResponsiveImages\Domain\Model\RootlineElementInterface; | ||
|
||
final class RootlineElementFactory | ||
{ | ||
public function __construct( | ||
private readonly ScalingFactory $scalingFactory | ||
) { | ||
} | ||
|
||
public function create(array $data, array|string $configurationPath): RootlineElementInterface | ||
{ | ||
$scaling = $this->scalingFactory->getByConfigurationPath($configurationPath); | ||
|
||
return new RootlineElement($scaling, $data); | ||
} | ||
} |
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,182 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Codappix\ResponsiveImages\Domain\Factory; | ||
|
||
/* | ||
* Copyright (C) 2024 Daniel Gohlke <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
use Codappix\ResponsiveImages\Configuration\ConfigurationManager; | ||
use Codappix\ResponsiveImages\Domain\Model\Rootline; | ||
use Codappix\ResponsiveImages\Domain\Model\RootlineElementInterface; | ||
use Codappix\ResponsiveImages\Domain\Repository\ContainerRepository; | ||
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; | ||
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; | ||
use TYPO3\CMS\Frontend\Page\PageLayoutResolver; | ||
|
||
final class RootlineFactory | ||
{ | ||
public array $columns = []; | ||
|
||
private RootlineElementInterface $backendLayout; | ||
|
||
private RootlineElementInterface $contentElement; | ||
|
||
private string $backendLayoutIdentifier; | ||
|
||
public function __construct( | ||
private readonly ConfigurationManager $configurationManager, | ||
private readonly ContainerRepository $containerRepository, | ||
private readonly PageLayoutResolver $pageLayoutResolver, | ||
private readonly RootlineElementFactory $rootlineElementFactory | ||
) { | ||
} | ||
|
||
public function create( | ||
array $data, | ||
string $fieldName, | ||
TypoScriptFrontendController $tsfe | ||
): Rootline { | ||
$this->createBackendLayoutRootlineElement($tsfe); | ||
$this->determineBackendLayoutColumns(); | ||
|
||
$this->createContentElementRootlineElement($data, $fieldName); | ||
$this->determineRootline($this->contentElement); | ||
|
||
return new Rootline($this->contentElement); | ||
} | ||
|
||
public function createContainerColumnRootlineElement( | ||
array $data, | ||
RootlineElementInterface $contentElement | ||
): RootlineElementInterface { | ||
$newContainerColumn = $this->rootlineElementFactory->create( | ||
$data, | ||
[ | ||
'container', | ||
$data['CType'], | ||
'columns', | ||
(string) $contentElement->getColPos(), | ||
] | ||
); | ||
$contentElement->setParent($newContainerColumn); | ||
|
||
return $newContainerColumn; | ||
} | ||
|
||
public function determineBackendLayoutColumns(): void | ||
{ | ||
$columns = $this->configurationManager->getByPath( | ||
[ | ||
'backendlayouts', | ||
$this->backendLayoutIdentifier, | ||
'columns', | ||
] | ||
); | ||
|
||
assert(is_array($columns)); | ||
$this->columns = array_map('intval', array_keys($columns)); | ||
} | ||
|
||
private function createBackendLayoutRootlineElement(TypoScriptFrontendController $tsfe): void | ||
{ | ||
$this->backendLayoutIdentifier = $this->pageLayoutResolver->getLayoutForPage( | ||
$tsfe->page, | ||
$tsfe->rootLine | ||
); | ||
|
||
$this->backendLayout = $this->rootlineElementFactory->create( | ||
[], | ||
[ | ||
'backendlayouts', | ||
$this->backendLayoutIdentifier, | ||
] | ||
); | ||
} | ||
|
||
private function createBackendLayoutColumnRootlineElement(RootlineElementInterface $contentElement): void | ||
{ | ||
$newBackendLayoutColumn = $this->rootlineElementFactory->create( | ||
[], | ||
[ | ||
'backendlayouts', | ||
$this->backendLayoutIdentifier, | ||
'columns', | ||
(string) $contentElement->getColPos(), | ||
] | ||
); | ||
|
||
$newBackendLayoutColumn->setParent($this->backendLayout); | ||
$contentElement->setParent($newBackendLayoutColumn); | ||
} | ||
|
||
private function createContainerRootlineElement( | ||
array $data, | ||
RootlineElementInterface $contentElement | ||
): RootlineElementInterface { | ||
$newContainerColumn = $this->createContainerColumnRootlineElement($data, $contentElement); | ||
|
||
$newContainer = $this->rootlineElementFactory->create( | ||
$data, | ||
[ | ||
'container', | ||
$data['CType'], | ||
] | ||
); | ||
$newContainerColumn->setParent($newContainer); | ||
|
||
return $newContainer; | ||
} | ||
|
||
private function createContentElementRootlineElement( | ||
array $data, | ||
string $fieldName | ||
): void { | ||
$this->contentElement = $this->rootlineElementFactory->create( | ||
$data, | ||
[ | ||
'contentelements', | ||
$data['CType'], | ||
$fieldName, | ||
] | ||
); | ||
} | ||
|
||
private function determineRootline(RootlineElementInterface $contentElement): void | ||
{ | ||
if (in_array($contentElement->getColPos(), $this->columns, true)) { | ||
$this->createBackendLayoutColumnRootlineElement($contentElement); | ||
|
||
return; | ||
} | ||
|
||
if (ExtensionManagementUtility::isLoaded('b13/container')) { | ||
$parentContainer = $contentElement->getData('tx_container_parent'); | ||
assert(is_int($parentContainer)); | ||
|
||
$parent = $this->createContainerRootlineElement( | ||
$this->containerRepository->findByIdentifier($parentContainer), | ||
$contentElement | ||
); | ||
|
||
$this->determineRootline($parent); | ||
} | ||
} | ||
} |
Oops, something went wrong.