Bugfix
This commit is contained in:
@@ -2,8 +2,14 @@
|
|||||||
|
|
||||||
namespace MummertMedia\ContaoMeilisearchBundle\EventListener;
|
namespace MummertMedia\ContaoMeilisearchBundle\EventListener;
|
||||||
|
|
||||||
|
use MummertMedia\ContaoMeilisearchBundle\Service\MeilisearchImageHelper;
|
||||||
|
|
||||||
class IndexPageListener
|
class IndexPageListener
|
||||||
{
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly MeilisearchImageHelper $imageHelper,
|
||||||
|
) {}
|
||||||
|
|
||||||
public function onIndexPage(string $content, array &$data, array &$set): void
|
public function onIndexPage(string $content, array &$data, array &$set): void
|
||||||
{
|
{
|
||||||
// Marker vorhanden?
|
// Marker vorhanden?
|
||||||
@@ -72,7 +78,11 @@ class IndexPageListener
|
|||||||
$parsed['custom']['searchimage'] ?? null;
|
$parsed['custom']['searchimage'] ?? null;
|
||||||
|
|
||||||
if (is_string($image) && $image !== '') {
|
if (is_string($image) && $image !== '') {
|
||||||
$set['imagepath'] = trim($image);
|
$path = $this->imageHelper->getImagePathFromUuid($image);
|
||||||
|
|
||||||
|
if ($path !== null) {
|
||||||
|
$set['imagepath'] = $path;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MummertMedia\ContaoMeilisearchBundle\Service;
|
||||||
|
|
||||||
|
use Contao\Config;
|
||||||
|
use Contao\CoreBundle\Filesystem\VirtualFilesystemInterface;
|
||||||
|
use Contao\CoreBundle\Image\Studio\Studio;
|
||||||
|
|
||||||
|
class MeilisearchImageHelper
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly Studio $studio,
|
||||||
|
private readonly VirtualFilesystemInterface $filesystem,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UUID → finaler Bildpfad für tl_search.imagepath
|
||||||
|
*/
|
||||||
|
public function getImagePathFromUuid(string $uuid): ?string
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$file = $this->filesystem->read($uuid);
|
||||||
|
|
||||||
|
if ($file === null || !$file->isFile()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$path = $file->getPath();
|
||||||
|
|
||||||
|
// -------------------------
|
||||||
|
// SVG → niemals skalieren
|
||||||
|
// -------------------------
|
||||||
|
if (str_ends_with(strtolower($path), '.svg')) {
|
||||||
|
return '/' . ltrim($path, '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------
|
||||||
|
// Rasterbild → Image Studio
|
||||||
|
// -------------------------
|
||||||
|
$sizeId = Config::get('meilisearch_imagesize');
|
||||||
|
|
||||||
|
if (!$sizeId) {
|
||||||
|
return '/' . ltrim($path, '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
$figure = $this->studio
|
||||||
|
->createFigureBuilder()
|
||||||
|
->fromFile($file)
|
||||||
|
->setSize($sizeId)
|
||||||
|
->build();
|
||||||
|
|
||||||
|
$image = $figure->getImage();
|
||||||
|
|
||||||
|
return $image?->getUrl();
|
||||||
|
|
||||||
|
} catch (\Throwable) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user