diff --git a/Classes/Sizes/AbstractContentElement.php b/Classes/Sizes/AbstractContentElement.php index 71330e0..4ddd504 100644 --- a/Classes/Sizes/AbstractContentElement.php +++ b/Classes/Sizes/AbstractContentElement.php @@ -84,4 +84,24 @@ public function setParent(ContentElementInterface $contentElement): void $this->parent = $contentElement; } + + protected function readConfigurationByPath(string $configurationPath): array + { + $configuration = $this->configurationManager->getByPath($configurationPath); + + $multiplier = []; + $sizes = []; + + if (is_array($configuration)) { + if (isset($configuration['multiplier'])) { + $multiplier = array_map(static fn($multiplier): float => Multiplier::parse($multiplier), $configuration['multiplier']); + } + + if (isset($configuration['sizes'])) { + $sizes = array_map(static fn($size): int => (int)$size, $configuration['sizes']); + } + } + + return [$multiplier, $sizes]; + } } diff --git a/Classes/Sizes/Container.php b/Classes/Sizes/Container.php index 3d7e590..b843d54 100644 --- a/Classes/Sizes/Container.php +++ b/Classes/Sizes/Container.php @@ -27,6 +27,16 @@ final class Container extends AbstractContentElement { + /** + * @var float[] + */ + private array $multiplier = []; + + /** + * @var int[] + */ + private array $sizes = []; + private array $columns = []; private Column $activeColumn; @@ -35,6 +45,7 @@ public function __construct(array $data) { parent::__construct($data); + $this->readConfiguration(); $this->determineColumns(); } @@ -63,7 +74,7 @@ public function getActiveColumn(): Column */ public function getMultiplier(): array { - return $this->getActiveColumn()->getMultiplier(); + return $this->multiplier; } /** @@ -71,7 +82,21 @@ public function getMultiplier(): array */ public function getSizes(): array { - return $this->getActiveColumn()->getSizes(); + return $this->sizes; + } + + public function readConfiguration(): void + { + $configurationPath = implode('.', [ + 'container', + $this->contentType, + ]); + + + [$multiplier, $sizes] = $this->readConfigurationByPath($configurationPath); + + $this->multiplier = $multiplier; + $this->sizes = $sizes; } private function determineColumns(): void @@ -83,6 +108,7 @@ private function determineColumns(): void ]); $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 index 8d495ae..b85e3f1 100644 --- a/Classes/Sizes/ContentElement.php +++ b/Classes/Sizes/ContentElement.php @@ -44,14 +44,20 @@ public function __construct( $this->readConfiguration(); } - public function getSizes(): array + /** + * @return float[] + */ + public function getMultiplier(): array { - return $this->sizes; + return $this->multiplier; } - public function getMultiplier(): array + /** + * @return int[] + */ + public function getSizes(): array { - return $this->multiplier; + return $this->sizes; } public function readConfiguration(): void @@ -62,16 +68,9 @@ public function readConfiguration(): void $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']); - } + [$multiplier, $sizes] = $this->readConfigurationByPath($configurationPath); - if (isset($configuration['sizes'])) { - $this->sizes = array_map(static fn ($size): int => (int) $size, $configuration['sizes']); - } - } + $this->multiplier = $multiplier; + $this->sizes = $sizes; } } diff --git a/Classes/Sizes/Rootline.php b/Classes/Sizes/Rootline.php index 4fb3c3b..c29ad7f 100644 --- a/Classes/Sizes/Rootline.php +++ b/Classes/Sizes/Rootline.php @@ -148,10 +148,20 @@ private function getSizesAndMultiplierFromRootline(): array foreach ($this->rootline as $contentElement) { if ($contentElement instanceof ContentElementInterface) { + if ($contentElement instanceof Container) { + $sizes = $contentElement->getActiveColumn()->getSizes(); + if (!empty($sizes)) { + break; + } + + $multiplier[] = $contentElement->getActiveColumn()->getMultiplier(); + } + $sizes = $contentElement->getSizes(); if (!empty($sizes)) { break; } + $multiplier[] = $contentElement->getMultiplier(); } } 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-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..0777761 --- /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..597946e --- /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/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/Functional/ContainerTest.php b/Tests/Functional/ContainerTest.php index 42e133b..ed89065 100644 --- a/Tests/Functional/ContainerTest.php +++ b/Tests/Functional/ContainerTest.php @@ -175,6 +175,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]