36 lines
916 B
PHP
36 lines
916 B
PHP
<?php
|
|
|
|
namespace App\Framework\View\Functions;
|
|
|
|
use App\Domain\Media\ImageSlotRepository;
|
|
use App\Domain\Media\ImageSourceSetGenerator;
|
|
use App\Framework\View\ComponentRenderer;
|
|
|
|
final readonly class ImageSlotFunction implements TemplateFunction
|
|
{
|
|
public string $functionName;
|
|
|
|
public function __construct(
|
|
private ImageSlotRepository $imageSlotRepository,
|
|
private ComponentRenderer $componentRenderer
|
|
){
|
|
$this->functionName = 'imageslot';
|
|
}
|
|
|
|
public function __invoke(string $slotName): string
|
|
{
|
|
$image = $this->imageSlotRepository->findBySlotName($slotName)->image;
|
|
|
|
$srcGen = new ImageSourceSetGenerator();
|
|
|
|
return $srcGen->generatePictureElement($image);
|
|
|
|
$data = [
|
|
'image' => $image->filename,
|
|
'alt' => $image->altText
|
|
];
|
|
|
|
return $this->componentRenderer->render('imageslot', $data);
|
|
}
|
|
}
|