chore: complete update
This commit is contained in:
35
src/Framework/View/Functions/ImageSlotFunction.php
Normal file
35
src/Framework/View/Functions/ImageSlotFunction.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user