diff --git a/Classes/Configuration/ConfigurationManager.php b/Classes/Configuration/ConfigurationManager.php index 5b50bb1..be0b4a6 100644 --- a/Classes/Configuration/ConfigurationManager.php +++ b/Classes/Configuration/ConfigurationManager.php @@ -31,7 +31,7 @@ final class ConfigurationManager { public function __construct( - private array $settings + private readonly array $settings ) { } @@ -40,13 +40,13 @@ public function get(): array return $this->settings; } - public function isValidPath(string $path): bool + public function isValidPath(array|string $path): bool { - return ArrayUtility::isValidPath($this->settings, $path, '.'); + return ArrayUtility::isValidPath($this->settings, $path); } - public function getByPath(string $path): mixed + public function getByPath(array|string $path): mixed { - return ArrayUtility::getValueByPath($this->settings, $path, '.'); + return ArrayUtility::getValueByPath($this->settings, $path); } } diff --git a/Classes/DataProcessing/ResponsiveImagesProcessor.php b/Classes/DataProcessing/ResponsiveImagesProcessor.php index 0d4dc8b..bd1608c 100644 --- a/Classes/DataProcessing/ResponsiveImagesProcessor.php +++ b/Classes/DataProcessing/ResponsiveImagesProcessor.php @@ -23,18 +23,16 @@ * 02110-1301, USA. */ -use Codappix\ResponsiveImages\Configuration\ConfigurationManager; -use Codappix\ResponsiveImages\Sizes\Breakpoint; -use Codappix\ResponsiveImages\Sizes\Rootline; +use Codappix\ResponsiveImages\Domain\Factory\BreakpointFactory; +use Codappix\ResponsiveImages\Domain\Factory\RootlineFactory; +use RuntimeException; use TYPO3\CMS\Core\Resource\FileInterface; -use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface; +use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; final class ResponsiveImagesProcessor implements DataProcessorInterface { - private readonly ConfigurationManager $configurationManager; - /** * @var FileInterface[] */ @@ -44,9 +42,10 @@ final class ResponsiveImagesProcessor implements DataProcessorInterface private array $contentElementSizes = []; - public function __construct() - { - $this->configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class); + public function __construct( + private readonly BreakpointFactory $breakpointFactory, + private readonly RootlineFactory $rootlineFactory + ) { } public function process( @@ -54,7 +53,7 @@ public function process( array $contentObjectConfiguration, array $processorConfiguration, array $processedData - ) { + ): array { if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) { return $processedData; } @@ -76,7 +75,13 @@ public function process( return $processedData; } - $this->contentElementSizes = (new Rootline($processedData['data'], $fieldName))->getFinalSizes(); + $tsfe = $cObj->getRequest()->getAttribute('frontend.controller'); + if (!$tsfe instanceof TypoScriptFrontendController) { + throw new RuntimeException('Could not fetch TypoScriptFrontendController from request.', 1712819889); + } + + $rootline = $this->rootlineFactory->create($processedData['data'], $fieldName, $tsfe); + $this->contentElementSizes = $rootline->getFinalSize(); $this->calculateFileDimensions(); $targetFieldName = (string) $cObj->stdWrapValue( @@ -106,9 +111,8 @@ private function calculateFileDimensionForBreakpoints(): array { $fileDimensions = []; - $breakpoints = $this->getBreakpoints(); + $breakpoints = $this->breakpointFactory->getByConfigurationPath(['breakpoints']); - /** @var Breakpoint $breakpoint */ foreach ($breakpoints as $breakpoint) { if (isset($this->contentElementSizes[$breakpoint->getIdentifier()]) === false) { continue; @@ -122,19 +126,4 @@ private function calculateFileDimensionForBreakpoints(): array return $fileDimensions; } - - private function getBreakpoints(): array - { - $breakpoints = []; - - $breakpointsByPath = $this->configurationManager->getByPath('breakpoints'); - - if (is_iterable($breakpointsByPath)) { - foreach ($breakpointsByPath as $breakpointIdentifier => $breakpointData) { - $breakpoints[$breakpointIdentifier] = new Breakpoint($breakpointIdentifier, $breakpointData); - } - } - - return $breakpoints; - } } diff --git a/Classes/Domain/Factory/BreakpointFactory.php b/Classes/Domain/Factory/BreakpointFactory.php new file mode 100644 index 0000000..bcd4081 --- /dev/null +++ b/Classes/Domain/Factory/BreakpointFactory.php @@ -0,0 +1,53 @@ + + * + * 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; + } +} diff --git a/Classes/Domain/Factory/RootlineElementFactory.php b/Classes/Domain/Factory/RootlineElementFactory.php new file mode 100644 index 0000000..e457ee2 --- /dev/null +++ b/Classes/Domain/Factory/RootlineElementFactory.php @@ -0,0 +1,42 @@ + + * + * 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); + } +} diff --git a/Classes/Domain/Factory/RootlineFactory.php b/Classes/Domain/Factory/RootlineFactory.php new file mode 100644 index 0000000..b954ad5 --- /dev/null +++ b/Classes/Domain/Factory/RootlineFactory.php @@ -0,0 +1,182 @@ + + * + * 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); + } + } +} diff --git a/Classes/Domain/Factory/ScalingFactory.php b/Classes/Domain/Factory/ScalingFactory.php new file mode 100644 index 0000000..d637563 --- /dev/null +++ b/Classes/Domain/Factory/ScalingFactory.php @@ -0,0 +1,49 @@ + + * + * 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\Scaling; + +final class ScalingFactory +{ + public function __construct( + private readonly ConfigurationManager $configurationManager + ) { + } + + public function getByConfigurationPath(array|string $configurationPath): Scaling + { + $configuration = $this->configurationManager->getByPath($configurationPath); + $multiplier = []; + $sizes = []; + + if (is_array($configuration)) { + $multiplier = !empty($configuration['multiplier']) ? $configuration['multiplier'] : []; + $sizes = !empty($configuration['sizes']) ? $configuration['sizes'] : []; + } + + return new Scaling($multiplier, $sizes); + } +} diff --git a/Classes/Sizes/Breakpoint.php b/Classes/Domain/Model/Breakpoint.php similarity index 95% rename from Classes/Sizes/Breakpoint.php rename to Classes/Domain/Model/Breakpoint.php index a295d9f..29c143a 100644 --- a/Classes/Sizes/Breakpoint.php +++ b/Classes/Domain/Model/Breakpoint.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Codappix\ResponsiveImages\Sizes; +namespace Codappix\ResponsiveImages\Domain\Model; /* * Copyright (C) 2020 Justus Moroni @@ -31,7 +31,7 @@ final class Breakpoint { public function __construct( private readonly string $identifier, - private array $data + private readonly array $data ) { } diff --git a/Classes/Domain/Model/Rootline.php b/Classes/Domain/Model/Rootline.php new file mode 100644 index 0000000..f2d4b6e --- /dev/null +++ b/Classes/Domain/Model/Rootline.php @@ -0,0 +1,43 @@ + + * + * 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. + */ + +final class Rootline implements RootlineInterface +{ + public function __construct( + private readonly RootlineElementInterface $rootlineElement + ) { + } + + public function getFinalSize(): array + { + $finalSize = $this->rootlineElement->getFinalSize([]); + + foreach ($finalSize as &$size) { + $size = ceil($size); + } + + return $finalSize; + } +} diff --git a/Classes/Domain/Model/RootlineElement.php b/Classes/Domain/Model/RootlineElement.php new file mode 100644 index 0000000..be23c68 --- /dev/null +++ b/Classes/Domain/Model/RootlineElement.php @@ -0,0 +1,115 @@ + + * Copyright (C) 2024 Daniel Gohlke + * + * 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 Exception; + +final class RootlineElement implements RootlineElementInterface +{ + private ?int $colPos = null; + + private ?RootlineElementInterface $parent = null; + + public function __construct( + private readonly Scaling $scaling, + private readonly array $data + ) { + if (isset($data['colPos'])) { + $this->colPos = (int) $data['colPos']; + } + } + + public function getParent(): ?RootlineElementInterface + { + return $this->parent; + } + + public function setParent(RootlineElementInterface $rootlineElement): void + { + $this->parent = $rootlineElement; + } + + public function getScaling(): Scaling + { + return $this->scaling; + } + + public function getFinalSize(array $multiplier): array + { + if ($this->getScaling()->getSizes()) { + if (empty($multiplier)) { + return $this->getScaling()->getSizes(); + } + + return $this->multiplyArray($this->getScaling()->getSizes(), $multiplier); + } + + if (is_null($this->getParent())) { + return $this->multiplyArray($this->getScaling()->getMultiplier(), $multiplier); + } + + return $this->getParent()->getFinalSize( + $this->multiplyArray($this->getScaling()->getMultiplier(), $multiplier) + ); + } + + public function getData(?string $dataIdentifier = null): mixed + { + if ($dataIdentifier === null) { + return $this->data; + } + + if (isset($this->data[$dataIdentifier]) === false) { + throw new Exception('No data found for key ' . $dataIdentifier . ' in $this->data.'); + } + + return $this->data[$dataIdentifier]; + } + + public function getColPos(): ?int + { + return $this->colPos; + } + + private function multiplyArray(array $factor1, array $factor2): array + { + if (empty($factor1)) { + return $factor2; + } + if (empty($factor2)) { + return $factor1; + } + + foreach ($factor1 as $sizeName => &$size) { + if (isset($factor2[$sizeName]) === false) { + continue; + } + + $factor1[$sizeName] *= $factor2[$sizeName]; + } + + return $factor1; + } +} diff --git a/Classes/Domain/Model/RootlineElementInterface.php b/Classes/Domain/Model/RootlineElementInterface.php new file mode 100644 index 0000000..3f74fc5 --- /dev/null +++ b/Classes/Domain/Model/RootlineElementInterface.php @@ -0,0 +1,40 @@ + + * Copyright (C) 2024 Daniel Gohlke + * + * 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. + */ + +interface RootlineElementInterface +{ + public function getParent(): ?self; + + public function setParent(self $rootlineElement): void; + + public function getScaling(): Scaling; + + public function getFinalSize(array $multiplier): array; + + public function getColPos(): ?int; + + public function getData(?string $dataIdentifier = null): mixed; +} diff --git a/Classes/Sizes/Multiplier.php b/Classes/Domain/Model/RootlineInterface.php similarity index 67% rename from Classes/Sizes/Multiplier.php rename to Classes/Domain/Model/RootlineInterface.php index 79f0806..7f8f4e3 100644 --- a/Classes/Sizes/Multiplier.php +++ b/Classes/Domain/Model/RootlineInterface.php @@ -2,10 +2,11 @@ declare(strict_types=1); -namespace Codappix\ResponsiveImages\Sizes; +namespace Codappix\ResponsiveImages\Domain\Model; /* - * Copyright (C) 2020 Justus Moroni + * Copyright (C) 2024 Justus Moroni + * Copyright (C) 2024 Daniel Gohlke * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,16 +24,7 @@ * 02110-1301, USA. */ -/** - * This class only provides the functionality to parse a string to a correct - * float value. - */ -final class Multiplier +interface RootlineInterface { - public static function parse(string $value): float - { - $value = str_replace(',', '.', $value); - - return (float) $value; - } + public function getFinalSize(): array; } diff --git a/Classes/Sizes/BackendLayout/Column.php b/Classes/Domain/Model/Scaling.php similarity index 63% rename from Classes/Sizes/BackendLayout/Column.php rename to Classes/Domain/Model/Scaling.php index 5fdccce..d4a5ed2 100644 --- a/Classes/Sizes/BackendLayout/Column.php +++ b/Classes/Domain/Model/Scaling.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace Codappix\ResponsiveImages\Sizes\BackendLayout; +namespace Codappix\ResponsiveImages\Domain\Model; /* - * Copyright (C) 2020 Justus Moroni + * Copyright (C) 2024 Daniel Gohlke * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,9 +23,7 @@ * 02110-1301, USA. */ -use Codappix\ResponsiveImages\Sizes\Multiplier; - -class Column +final class Scaling { /** * @var float[] @@ -37,24 +35,17 @@ class Column */ private array $sizes = []; - public function __construct( - private readonly int $identifier, - array $data - ) { - if (isset($data['multiplier'])) { - $this->multiplier = array_map(static fn ($multiplier): float => Multiplier::parse($multiplier), $data['multiplier']); + public function __construct(array $multiplier, array $sizes) + { + if (!empty($multiplier)) { + $this->multiplier = array_map('floatval', $multiplier); } - if (isset($data['sizes'])) { - $this->sizes = array_map(static fn ($size): int => (int) $size, $data['sizes']); + if (!empty($sizes)) { + $this->sizes = array_map('intval', $sizes); } } - public function getIdentifier(): int - { - return $this->identifier; - } - /** * @return float[] */ diff --git a/Classes/Domain/Repository/ContainerRepository.php b/Classes/Domain/Repository/ContainerRepository.php new file mode 100644 index 0000000..ae05e17 --- /dev/null +++ b/Classes/Domain/Repository/ContainerRepository.php @@ -0,0 +1,57 @@ + + * + * 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 TYPO3\CMS\Core\Database\Connection; +use TYPO3\CMS\Core\Error\Exception; + +final class ContainerRepository +{ + public function __construct( + private readonly Connection $connection + ) { + } + + /** + * @throws \Doctrine\DBAL\Exception + * @throws Exception + */ + public function findByIdentifier(int $identifier): array + { + $queryBuilder = $this->connection->createQueryBuilder(); + $rawData = $queryBuilder + ->select('uid', 'colPos', 'CType', 'tx_container_parent') + ->from('tt_content') + ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($identifier, Connection::PARAM_INT))) + ->executeQuery() + ->fetchAssociative() + ; + + if ($rawData === false) { + throw new Exception("Content element '" . $identifier . "' not found."); + } + + return $rawData; + } +} diff --git a/Classes/Sizes/AbstractContentElement.php b/Classes/Sizes/AbstractContentElement.php deleted file mode 100644 index 71330e0..0000000 --- a/Classes/Sizes/AbstractContentElement.php +++ /dev/null @@ -1,87 +0,0 @@ - - * - * 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 Exception; -use TYPO3\CMS\Core\Utility\GeneralUtility; - -abstract class AbstractContentElement implements ContentElementInterface -{ - protected ConfigurationManager $configurationManager; - - protected int $colPos; - - protected string $contentType; - - protected array $data; - - protected ContentElementInterface $parent; - - public function __construct(array $data) - { - $this->configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class); - - $this->contentType = $data['CType']; - $this->colPos = $data['colPos']; - $this->data = $data; - } - - public function getData(?string $dataIdentifier = null): mixed - { - if ($dataIdentifier === null) { - return $this->data; - } - - if (isset($this->data[$dataIdentifier]) === false) { - throw new Exception('No data found for key ' . $dataIdentifier . ' in $this->data.'); - } - - return $this->data[$dataIdentifier]; - } - - public function getColPos(): int - { - return $this->colPos; - } - - public function getContentType(): string - { - return $this->contentType; - } - - public function getParent(): ?ContentElementInterface - { - return $this->parent; - } - - public function setParent(ContentElementInterface $contentElement): void - { - if ($contentElement instanceof Container) { - $contentElement->setActiveColumn($contentElement->getColumn($this->colPos)); - } - - $this->parent = $contentElement; - } -} diff --git a/Classes/Sizes/BackendLayout.php b/Classes/Sizes/BackendLayout.php deleted file mode 100644 index 47d31a1..0000000 --- a/Classes/Sizes/BackendLayout.php +++ /dev/null @@ -1,105 +0,0 @@ - - * - * 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\Sizes\BackendLayout\Column; -use TYPO3\CMS\Core\Utility\GeneralUtility; - -final class BackendLayout -{ - private array $sizes = []; - - private array $columns = []; - - private Column $activeColumn; - - private readonly ConfigurationManager $configurationManager; - - public function __construct( - protected string $identifier - ) { - $this->configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class); - - $this->determineSizes(); - $this->determineColumns(); - } - - public function getSizes(): array - { - return $this->sizes; - } - - public function getColumns(): array - { - return $this->columns; - } - - public function getColumn(int $columnPosition): Column - { - return $this->columns[$columnPosition]; - } - - public function setActiveColumn(Column $column): void - { - $this->activeColumn = $column; - } - - public function getActiveColumn(): Column - { - return $this->activeColumn; - } - - private function determineSizes(): void - { - $sizesPath = implode('.', [ - 'backendlayouts', - $this->identifier, - 'sizes', - ]); - - if (is_array($this->configurationManager->getByPath($sizesPath))) { - $this->sizes = $this->configurationManager->getByPath($sizesPath); - } - } - - private function determineColumns(): array - { - $sizesPath = implode('.', [ - 'backendlayouts', - $this->identifier, - 'columns', - ]); - - $breakpointsByPath = $this->configurationManager->getByPath($sizesPath); - - if (is_iterable($breakpointsByPath)) { - foreach ($breakpointsByPath as $columnIdentifier => $columnData) { - $this->columns[$columnIdentifier] = new Column($columnIdentifier, $columnData); - } - } - - return $this->columns; - } -} diff --git a/Classes/Sizes/Container.php b/Classes/Sizes/Container.php deleted file mode 100644 index 3d7e590..0000000 --- a/Classes/Sizes/Container.php +++ /dev/null @@ -1,92 +0,0 @@ - - * - * 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\Sizes\BackendLayout\Column; - -final class Container extends AbstractContentElement -{ - private array $columns = []; - - private Column $activeColumn; - - public function __construct(array $data) - { - parent::__construct($data); - - $this->determineColumns(); - } - - public function getColumns(): array - { - return $this->columns; - } - - public function getColumn(int $columnPosition): Column - { - return $this->columns[$columnPosition]; - } - - public function setActiveColumn(Column $column): void - { - $this->activeColumn = $column; - } - - public function getActiveColumn(): Column - { - return $this->activeColumn; - } - - /** - * @return float[] - */ - public function getMultiplier(): array - { - return $this->getActiveColumn()->getMultiplier(); - } - - /** - * @return int[] - */ - public function getSizes(): array - { - return $this->getActiveColumn()->getSizes(); - } - - private function determineColumns(): void - { - $sizesPath = implode('.', [ - 'container', - $this->contentType, - 'columns', - ]); - - $columnsByPath = $this->configurationManager->getByPath($sizesPath); - if (is_iterable($columnsByPath)) { - foreach ($columnsByPath as $columnIdentifier => $columnData) { - $this->columns[$columnIdentifier] = new Column($columnIdentifier, $columnData); - } - } - } -} diff --git a/Classes/Sizes/ContentElement.php b/Classes/Sizes/ContentElement.php deleted file mode 100644 index 8d495ae..0000000 --- a/Classes/Sizes/ContentElement.php +++ /dev/null @@ -1,77 +0,0 @@ - - * - * 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. - */ - -class ContentElement extends AbstractContentElement -{ - /** - * @var float[] - */ - private array $multiplier = []; - - /** - * @var int[] - */ - private array $sizes = []; - - public function __construct( - array $data, - private readonly string $fieldName - ) { - parent::__construct($data); - - $this->readConfiguration(); - } - - public function getSizes(): array - { - return $this->sizes; - } - - public function getMultiplier(): array - { - return $this->multiplier; - } - - public function readConfiguration(): void - { - $configurationPath = implode('.', [ - 'contentelements', - $this->contentType, - $this->fieldName, - ]); - - $configuration = $this->configurationManager->getByPath($configurationPath); - - if (is_array($configuration)) { - if (isset($configuration['multiplier'])) { - $this->multiplier = array_map(static fn ($multiplier): float => Multiplier::parse($multiplier), $configuration['multiplier']); - } - - if (isset($configuration['sizes'])) { - $this->sizes = array_map(static fn ($size): int => (int) $size, $configuration['sizes']); - } - } - } -} diff --git a/Classes/Sizes/ContentElementInterface.php b/Classes/Sizes/ContentElementInterface.php deleted file mode 100644 index 12842bb..0000000 --- a/Classes/Sizes/ContentElementInterface.php +++ /dev/null @@ -1,26 +0,0 @@ - - * - * 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 B13\Container\Tca\Registry; -use TYPO3\CMS\Core\Database\Connection; -use TYPO3\CMS\Core\Database\ConnectionPool; -use TYPO3\CMS\Core\Database\Query\QueryBuilder; -use TYPO3\CMS\Core\Error\Exception; -use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; -use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Frontend\Page\PageLayoutResolver; - -final class Rootline -{ - private readonly ContentElementInterface $contentElement; - - private BackendLayout $backendLayout; - - private array $rootline = []; - - private array $finalSizes = []; - - private string $fieldName; - - public function __construct(array $data, string $fieldName) - { - $this->determineBackendLayout(); - $this->fieldName = $fieldName; - $this->contentElement = $this->determineContentElement($data); - - $this->determineRootline(); - $this->calculateSizes(); - } - - public function getFinalSizes(): array - { - return $this->finalSizes; - } - - private function determineBackendLayout(): void - { - $typoscriptFrontendController = $GLOBALS['TSFE']; - - $backendLayoutIdentifier = GeneralUtility::makeInstance(PageLayoutResolver::class) - ->getLayoutForPage($typoscriptFrontendController->page, $typoscriptFrontendController->rootLine) - ; - - $this->backendLayout = new BackendLayout($backendLayoutIdentifier); - } - - private function determineContentElement(array $data): ContentElementInterface - { - if ( - class_exists(Registry::class) - && GeneralUtility::makeInstance(Registry::class)->isContainerElement($data['CType']) - ) { - return new Container($data); - } - - return new ContentElement($data, $this->fieldName); - } - - private function determineRootline(): void - { - $this->rootline[] = $this->contentElement; - - $this->parseRootline($this->contentElement); - } - - private function parseRootline(ContentElementInterface $contentElement): void - { - if (array_key_exists($contentElement->getColPos(), $this->backendLayout->getColumns())) { - $this->backendLayout->setActiveColumn( - $this->backendLayout->getColumn($contentElement->getColPos()) - ); - - return; - } - - if (ExtensionManagementUtility::isLoaded('b13/container')) { - $parentContainer = $contentElement->getData('tx_container_parent'); - assert(is_int($parentContainer)); - $parent = $this->fetchContentElementFromDatabase($parentContainer); - - $this->rootline[] = $parent; - $this->parseRootline($parent); - - $contentElement->setParent($parent); - } - } - - /** - * @throws \Doctrine\DBAL\Exception - * @throws Exception - */ - private function fetchContentElementFromDatabase(int $identifier): ContentElementInterface - { - /** @var QueryBuilder $queryBuilder */ - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content'); - $rawData = $queryBuilder - ->select('*') - ->from('tt_content') - ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($identifier, Connection::PARAM_INT))) - ->executeQuery() - ->fetchAssociative() - ; - - if ($rawData === false) { - throw new Exception("Content element '" . $identifier . "' not found."); - } - - return $this->determineContentElement($rawData); - } - - private function calculateSizes(): void - { - [$sizes, $multiplier] = $this->getSizesAndMultiplierFromRootline(); - - $this->calculateFinalSizes($sizes, $multiplier); - } - - private function getSizesAndMultiplierFromRootline(): array - { - $multiplier = []; - $sizes = []; - - foreach ($this->rootline as $contentElement) { - if ($contentElement instanceof ContentElementInterface) { - $sizes = $contentElement->getSizes(); - if (!empty($sizes)) { - break; - } - $multiplier[] = $contentElement->getMultiplier(); - } - } - - if (empty($sizes)) { - $sizes = $this->backendLayout->getSizes(); - } - - return [$sizes, $multiplier]; - } - - private function calculateFinalSizes(array $sizes, array $multiplier): void - { - foreach ($sizes as $sizeName => &$size) { - foreach ($multiplier as $multiplierItem) { - if (isset($multiplierItem[$sizeName]) === false) { - continue; - } - - $size *= $multiplierItem[$sizeName]; - } - - $size = ceil($size); - } - - $this->finalSizes = $sizes; - } -} diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index ade47c2..67ea82d 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -8,6 +8,14 @@ services: Codappix\ResponsiveImages\: resource: '../Classes/*' + dbconnection.tt_content: + class: 'TYPO3\CMS\Core\Database\Connection' + factory: + - '@TYPO3\CMS\Core\Database\ConnectionPool' + - 'getConnectionForTable' + arguments: + - 'tt_content' + extbaseSettings.ResponsiveImages: class: 'array' factory: @@ -18,7 +26,13 @@ services: $extensionName: 'ResponsiveImages' $pluginName: '' - Codappix\ResponsiveImages\Configuration\ConfigurationManager: + Codappix\ResponsiveImages\DataProcessing\ResponsiveImagesProcessor: public: true + + Codappix\ResponsiveImages\Configuration\ConfigurationManager: arguments: $settings: '@extbaseSettings.ResponsiveImages' + + Codappix\ResponsiveImages\Domain\Repository\ContainerRepository: + arguments: + - '@dbconnection.tt_content' diff --git a/Tests/Fixtures/container_example/Configuration/TCA/Overrides/tt_content_container_2col_50_50_with_container_multiplier.php b/Tests/Fixtures/container_example/Configuration/TCA/Overrides/tt_content_container_2col_50_50_with_container_multiplier.php new file mode 100644 index 0000000..7152be1 --- /dev/null +++ b/Tests/Fixtures/container_example/Configuration/TCA/Overrides/tt_content_container_2col_50_50_with_container_multiplier.php @@ -0,0 +1,27 @@ +configureContainer(new ContainerConfiguration( + $cType, + '2 Column: 50-50', + '(50% / 50%)', + [ + [ + [ + 'name' => 'Column 101', + 'colPos' => 101, + ], + [ + 'name' => 'Column 102', + 'colPos' => 102, + ], + ], + ] + )); +})(); diff --git a/Tests/Fixtures/container_example/Configuration/TCA/Overrides/tt_content_container_2col_50_50_with_container_size.php b/Tests/Fixtures/container_example/Configuration/TCA/Overrides/tt_content_container_2col_50_50_with_container_size.php new file mode 100644 index 0000000..dade616 --- /dev/null +++ b/Tests/Fixtures/container_example/Configuration/TCA/Overrides/tt_content_container_2col_50_50_with_container_size.php @@ -0,0 +1,27 @@ +configureContainer(new ContainerConfiguration( + $cType, + '2 Column: 50-50', + '(50% / 50%)', + [ + [ + [ + 'name' => 'Column 101', + 'colPos' => 101, + ], + [ + 'name' => 'Column 102', + 'colPos' => 102, + ], + ], + ] + )); +})(); diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-33-66.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-33-66.typoscript index 789c1d7..df04d23 100644 --- a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-33-66.typoscript +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-33-66.typoscript @@ -7,9 +7,9 @@ plugin.tx_responsiveimages { multiplier { xs = 1 sm = 1 - md = 0,333 - lg = 0,333 - xl = 0,333 + md = 0.333 + lg = 0.333 + xl = 0.333 } } @@ -17,9 +17,9 @@ plugin.tx_responsiveimages { multiplier { xs = 1 sm = 1 - md = 0,666 - lg = 0,666 - xl = 0,666 + md = 0.666 + lg = 0.666 + xl = 0.666 } } } diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50-with-container-multiplier.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50-with-container-multiplier.typoscript new file mode 100644 index 0000000..5b5673d --- /dev/null +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50-with-container-multiplier.typoscript @@ -0,0 +1,41 @@ +plugin.tx_responsiveimages { + settings { + container { + example_container-2col-50-50-with-container-multiplier { + columns { + 101 { + multiplier { + xs = 1 + sm = 1 + md = 0.5 + lg = 0.5 + xl = 0.5 + } + } + + 102 { + multiplier { + xs = 1 + sm = 1 + md = 0.5 + lg = 0.5 + xl = 0.5 + } + } + } + multiplier { + xs = 0.8 + sm = 0.8 + md = 0.8 + lg = 0.8 + xl = 0.8 + } + } + } + } +} + +tt_content.example_container-2col-50-50-with-container-multiplier < lib.containerElement +tt_content.example_container-2col-50-50-with-container-multiplier { + templateName = 2col-50-50 +} diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50-with-container-size.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50-with-container-size.typoscript new file mode 100644 index 0000000..1026963 --- /dev/null +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50-with-container-size.typoscript @@ -0,0 +1,41 @@ +plugin.tx_responsiveimages { + settings { + container { + example_container-2col-50-50-with-container-size { + columns { + 101 { + multiplier { + xs = 1 + sm = 1 + md = 0.5 + lg = 0.5 + xl = 0.5 + } + } + + 102 { + multiplier { + xs = 1 + sm = 1 + md = 0.5 + lg = 0.5 + xl = 0.5 + } + } + } + sizes { + xs = 600 + sm = 900 + md = 1200 + lg = 1500 + xl = 1800 + } + } + } + } +} + +tt_content.example_container-2col-50-50-with-container-size < lib.containerElement +tt_content.example_container-2col-50-50-with-container-size { + templateName = 2col-50-50 +} diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50.typoscript index 33a760c..bc7746f 100644 --- a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50.typoscript +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50.typoscript @@ -7,9 +7,9 @@ plugin.tx_responsiveimages { multiplier { xs = 1 sm = 1 - md = 0,5 - lg = 0,5 - xl = 0,5 + md = 0.5 + lg = 0.5 + xl = 0.5 } } @@ -17,9 +17,9 @@ plugin.tx_responsiveimages { multiplier { xs = 1 sm = 1 - md = 0,5 - lg = 0,5 - xl = 0,5 + md = 0.5 + lg = 0.5 + xl = 0.5 } } } diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-66-33.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-66-33.typoscript index 4266f20..257c424 100644 --- a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-66-33.typoscript +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-66-33.typoscript @@ -7,9 +7,9 @@ plugin.tx_responsiveimages { multiplier { xs = 1 sm = 1 - md = 0,666 - lg = 0,666 - xl = 0,666 + md = 0.666 + lg = 0.666 + xl = 0.666 } } @@ -17,9 +17,9 @@ plugin.tx_responsiveimages { multiplier { xs = 1 sm = 1 - md = 0,333 - lg = 0,333 - xl = 0,333 + md = 0.333 + lg = 0.333 + xl = 0.333 } } } diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/3col.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/3col.typoscript index 2a283ea..64d5b27 100644 --- a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/3col.typoscript +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/3col.typoscript @@ -7,9 +7,9 @@ plugin.tx_responsiveimages { multiplier { xs = 1 sm = 1 - md = 0,333 - lg = 0,333 - xl = 0,333 + md = 0.333 + lg = 0.333 + xl = 0.333 } } @@ -17,9 +17,9 @@ plugin.tx_responsiveimages { multiplier { xs = 1 sm = 1 - md = 0,333 - lg = 0,333 - xl = 0,333 + md = 0.333 + lg = 0.333 + xl = 0.333 } } @@ -27,9 +27,9 @@ plugin.tx_responsiveimages { multiplier { xs = 1 sm = 1 - md = 0,333 - lg = 0,333 - xl = 0,333 + md = 0.333 + lg = 0.333 + xl = 0.333 } } } diff --git a/Tests/Fixtures/container_example/Test/Fixtures/1col2colWidthContainerMultiplierDatabase.php b/Tests/Fixtures/container_example/Test/Fixtures/1col2colWidthContainerMultiplierDatabase.php new file mode 100644 index 0000000..d7e9faa --- /dev/null +++ b/Tests/Fixtures/container_example/Test/Fixtures/1col2colWidthContainerMultiplierDatabase.php @@ -0,0 +1,61 @@ + [ + 0 => [ + 'uid' => '1', + 'pid' => '2', + 'hidden' => '0', + 'sorting' => '1', + 'CType' => 'example_container-1col', + 'header' => '1col', + 'deleted' => '0', + 'starttime' => '0', + 'endtime' => '0', + 'colPos' => '0', + 'sys_language_uid' => '0', + 'tx_container_parent' => '0', + ], + 1 => [ + 'uid' => '2', + 'pid' => '2', + 'hidden' => '0', + 'sorting' => '1', + 'CType' => 'example_container-2col-50-50-with-container-multiplier', + 'header' => '2col in 2col', + 'deleted' => '0', + 'starttime' => '0', + 'endtime' => '0', + 'colPos' => '101', + 'sys_language_uid' => '0', + 'tx_container_parent' => '1', + ], + 2 => [ + 'uid' => '3', + 'pid' => '2', + 'hidden' => '0', + 'sorting' => '1', + 'CType' => 'image', + 'header' => 'image in 2col in 1col', + 'deleted' => '0', + 'starttime' => '0', + 'endtime' => '0', + 'colPos' => '102', + 'sys_language_uid' => '0', + 'image' => '1', + 'tx_container_parent' => '2', + ], + ], + 'sys_file_reference' => [ + 0 => [ + 'uid' => '1', + 'pid' => '2', + 'uid_local' => '1', + 'uid_foreign' => '3', + 'tablenames' => 'tt_content', + 'fieldname' => 'image', + ], + ], +]; diff --git a/Tests/Fixtures/container_example/Test/Fixtures/1col2colWidthContainerSizeDatabase.php b/Tests/Fixtures/container_example/Test/Fixtures/1col2colWidthContainerSizeDatabase.php new file mode 100644 index 0000000..e02ec12 --- /dev/null +++ b/Tests/Fixtures/container_example/Test/Fixtures/1col2colWidthContainerSizeDatabase.php @@ -0,0 +1,61 @@ + [ + 0 => [ + 'uid' => '1', + 'pid' => '2', + 'hidden' => '0', + 'sorting' => '1', + 'CType' => 'example_container-1col', + 'header' => '1col', + 'deleted' => '0', + 'starttime' => '0', + 'endtime' => '0', + 'colPos' => '0', + 'sys_language_uid' => '0', + 'tx_container_parent' => '0', + ], + 1 => [ + 'uid' => '2', + 'pid' => '2', + 'hidden' => '0', + 'sorting' => '1', + 'CType' => 'example_container-2col-50-50-with-container-size', + 'header' => '2col in 2col', + 'deleted' => '0', + 'starttime' => '0', + 'endtime' => '0', + 'colPos' => '101', + 'sys_language_uid' => '0', + 'tx_container_parent' => '1', + ], + 2 => [ + 'uid' => '3', + 'pid' => '2', + 'hidden' => '0', + 'sorting' => '1', + 'CType' => 'image', + 'header' => 'image in 2col in 1col', + 'deleted' => '0', + 'starttime' => '0', + 'endtime' => '0', + 'colPos' => '102', + 'sys_language_uid' => '0', + 'image' => '1', + 'tx_container_parent' => '2', + ], + ], + 'sys_file_reference' => [ + 0 => [ + 'uid' => '1', + 'pid' => '2', + 'uid_local' => '1', + 'uid_foreign' => '3', + 'tablenames' => 'tt_content', + 'fieldname' => 'image', + ], + ], +]; diff --git a/Tests/Fixtures/container_example/Test/Fixtures/2col_66_33_Database.php b/Tests/Fixtures/container_example/Test/Fixtures/2col_66_33_ImageLeft_Database.php similarity index 100% rename from Tests/Fixtures/container_example/Test/Fixtures/2col_66_33_Database.php rename to Tests/Fixtures/container_example/Test/Fixtures/2col_66_33_ImageLeft_Database.php diff --git a/Tests/Fixtures/container_example/Test/Fixtures/2col_66_33_ImageRight_Database.php b/Tests/Fixtures/container_example/Test/Fixtures/2col_66_33_ImageRight_Database.php new file mode 100644 index 0000000..a1c4b96 --- /dev/null +++ b/Tests/Fixtures/container_example/Test/Fixtures/2col_66_33_ImageRight_Database.php @@ -0,0 +1,47 @@ + [ + 0 => [ + 'uid' => '1', + 'pid' => '2', + 'hidden' => '0', + 'sorting' => '1', + 'CType' => 'example_container-2col-66-33', + 'header' => '1col', + 'deleted' => '0', + 'starttime' => '0', + 'endtime' => '0', + 'colPos' => '0', + 'sys_language_uid' => '0', + 'tx_container_parent' => '0', + ], + 1 => [ + 'uid' => '2', + 'pid' => '2', + 'hidden' => '0', + 'sorting' => '1', + 'CType' => 'image', + 'header' => 'image in 2col', + 'deleted' => '0', + 'starttime' => '0', + 'endtime' => '0', + 'colPos' => '102', + 'sys_language_uid' => '0', + 'image' => '1', + 'tx_container_parent' => '1', + ], + ], + 'sys_file_reference' => [ + 0 => [ + 'uid' => '1', + 'pid' => '2', + 'uid_local' => '1', + 'uid_foreign' => '2', + 'tablenames' => 'tt_content', + 'fieldname' => 'image', + ], + ], +]; diff --git a/Tests/Functional/ContainerTest.php b/Tests/Functional/ContainerTest.php index 42e133b..1c41226 100644 --- a/Tests/Functional/ContainerTest.php +++ b/Tests/Functional/ContainerTest.php @@ -95,8 +95,8 @@ public static function imageScalingValuesDataProvider(): iterable '4' => 'large 281 (min-width: 1480px)', ], ]; - yield '2 Column 66-33' => [ - '2col_66_33_Database.php', + yield '2 Column 66-33 Image in left Column' => [ + '2col_66_33_ImageLeft_Database.php', [ '0' => 'mobile 734 (max-width: 480px)', '1' => 'mobile 704 (max-width: 767px)', @@ -105,6 +105,16 @@ public static function imageScalingValuesDataProvider(): iterable '4' => 'large 375 (min-width: 1480px)', ], ]; + yield '2 Column 66-33 Image in right Column' => [ + '2col_66_33_ImageRight_Database.php', + [ + '0' => 'mobile 734 (max-width: 480px)', + '1' => 'mobile 704 (max-width: 767px)', + '2' => 'tablet 308 (max-width: 991px)', + '3' => 'default 375 (max-width: 1479px)', + '4' => 'large 188 (min-width: 1480px)', + ], + ]; yield '2 Column in 1 Column' => [ '1col2colDatabase.php', [ @@ -175,6 +185,26 @@ public static function imageScalingValuesDataProvider(): iterable '4' => 'large 1600 (min-width: 1480px)', ], ]; + yield '2 Column with Container Size in 1 Column' => [ + '1col2colWidthContainerSizeDatabase.php', + [ + '0' => 'mobile 600 (max-width: 480px)', + '1' => 'mobile 900 (max-width: 767px)', + '2' => 'tablet 600 (max-width: 991px)', + '3' => 'default 750 (max-width: 1479px)', + '4' => 'large 450 (min-width: 1480px)', + ], + ]; + yield '2 Column with Container Multiplier in 1 Column' => [ + '1col2colWidthContainerMultiplierDatabase.php', + [ + '0' => 'mobile 588 (max-width: 480px)', + '1' => 'mobile 564 (max-width: 767px)', + '2' => 'tablet 370 (max-width: 991px)', + '3' => 'default 450 (max-width: 1479px)', + '4' => 'large 225 (min-width: 1480px)', + ], + ]; } #[Test]