Skip to content

Commit

Permalink
TASK: Allow sizes and multiplier for container
Browse files Browse the repository at this point in the history
Related: #22
  • Loading branch information
d-g-codappix committed Apr 4, 2024
1 parent b6aeb22 commit 5a9a3de
Show file tree
Hide file tree
Showing 11 changed files with 349 additions and 16 deletions.
20 changes: 20 additions & 0 deletions Classes/Sizes/AbstractContentElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
30 changes: 28 additions & 2 deletions Classes/Sizes/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,6 +45,7 @@ public function __construct(array $data)
{
parent::__construct($data);

$this->readConfiguration();
$this->determineColumns();
}

Expand Down Expand Up @@ -63,15 +74,29 @@ public function getActiveColumn(): Column
*/
public function getMultiplier(): array
{
return $this->getActiveColumn()->getMultiplier();
return $this->multiplier;
}

/**
* @return int[]
*/
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
Expand All @@ -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);
Expand Down
27 changes: 13 additions & 14 deletions Classes/Sizes/ContentElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
}
10 changes: 10 additions & 0 deletions Classes/Sizes/Rootline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

use B13\Container\Tca\ContainerConfiguration;
use B13\Container\Tca\Registry;
use TYPO3\CMS\Core\Utility\GeneralUtility;

(static function (string $cType = 'example_container-2col-50-50-with-container-multiplier'): void {
GeneralUtility::makeInstance(Registry::class)->configureContainer(new ContainerConfiguration(
$cType,
'2 Column: 50-50',
'(50% / 50%)',
[
[
[
'name' => 'Column 101',
'colPos' => 101,
],
[
'name' => 'Column 102',
'colPos' => 102,
],
],
]
));
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

use B13\Container\Tca\ContainerConfiguration;
use B13\Container\Tca\Registry;
use TYPO3\CMS\Core\Utility\GeneralUtility;

(static function (string $cType = 'example_container-2col-50-50-with-container-size'): void {
GeneralUtility::makeInstance(Registry::class)->configureContainer(new ContainerConfiguration(
$cType,
'2 Column: 50-50',
'(50% / 50%)',
[
[
[
'name' => 'Column 101',
'colPos' => 101,
],
[
'name' => 'Column 102',
'colPos' => 102,
],
],
]
));
})();
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

return [
'tt_content' => [
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',
],
],
];
Loading

0 comments on commit 5a9a3de

Please sign in to comment.