Skip to content

Commit

Permalink
[TASK] Fluid ViewHelper: Add sizes option
Browse files Browse the repository at this point in the history
Similar to the Fusion prototype, allow setting a sizes attribute that
defines which size variants are generated (instead of the default
set taken from Settings).

The sizes are passed as a comma-separated string.
  • Loading branch information
lorenzulrich committed Nov 11, 2024
1 parent 117ee04 commit dfbe519
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Classes/ViewHelpers/ImageViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function initializeArguments()
$this->registerUniversalTagAttributes();
$this->registerTagAttribute('alt', 'string', 'Specifies an alternate text for an image', true);
$this->registerArgument('image', ImageInterface::class, 'The image to be rendered as an image');
$this->registerArgument('sizes', 'string', 'Comma-separated list of image sizes');
$this->registerArgument('ratio', 'float', 'The aspect ratio for the image');
$this->registerArgument('maximumWidth', 'integer', 'Desired maximum width of the image');
$this->registerArgument('maximumHeight', 'integer', 'Desired maximum height of the image');
Expand All @@ -72,7 +73,11 @@ public function initializeArguments()
*/
public function render()
{
$sizes = $this->sizesPresets['Default'];
if ($this->arguments['sizes']) {
$sizes = array_map('trim', explode(',', $this->arguments['sizes']));
} else {
$sizes = $this->sizesPresets['Default'];
}

$srcSetString = $this->srcSetService->getSrcSetAttribute(
$this->arguments['image'],
Expand Down

0 comments on commit dfbe519

Please sign in to comment.