Bugfix
This commit is contained in:
@@ -8,4 +8,7 @@ services:
|
|||||||
|
|
||||||
MummertMedia\ContaoMeilisearchBundle\EventListener\IndexPageListener:
|
MummertMedia\ContaoMeilisearchBundle\EventListener\IndexPageListener:
|
||||||
tags:
|
tags:
|
||||||
- { name: contao.hook, hook: indexPage, method: onIndexPage }
|
- { name: contao.hook, hook: indexPage, method: onIndexPage }
|
||||||
|
|
||||||
|
Contao\CoreBundle\Filesystem\FilesystemInterface:
|
||||||
|
alias: filesStorage
|
||||||
@@ -2,59 +2,44 @@
|
|||||||
|
|
||||||
namespace MummertMedia\ContaoMeilisearchBundle\Service;
|
namespace MummertMedia\ContaoMeilisearchBundle\Service;
|
||||||
|
|
||||||
|
use Contao\CoreBundle\Filesystem\FilesystemInterface;
|
||||||
|
use Contao\Image\Studio;
|
||||||
use Contao\Config;
|
use Contao\Config;
|
||||||
use Contao\CoreBundle\Filesystem\VirtualFilesystemInterface;
|
|
||||||
use Contao\CoreBundle\Image\Studio\Studio;
|
|
||||||
|
|
||||||
class MeilisearchImageHelper
|
class MeilisearchImageHelper
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly Studio $studio,
|
private readonly FilesystemInterface $filesStorage,
|
||||||
private readonly VirtualFilesystemInterface $filesystem,
|
private readonly Studio $imageStudio,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
|
||||||
* UUID → finaler Bildpfad für tl_search.imagepath
|
|
||||||
*/
|
|
||||||
public function getImagePathFromUuid(string $uuid): ?string
|
public function getImagePathFromUuid(string $uuid): ?string
|
||||||
{
|
{
|
||||||
try {
|
// UUID → Datei
|
||||||
$file = $this->filesystem->read($uuid);
|
if (!$this->filesStorage->fileExists($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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$file = $this->filesStorage->get($uuid);
|
||||||
|
$path = $file->getPath();
|
||||||
|
|
||||||
|
// SVG: nicht skalieren
|
||||||
|
if (str_ends_with(strtolower($path), '.svg')) {
|
||||||
|
return '/' . ltrim($path, '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bildgröße aus tl_settings
|
||||||
|
$sizeId = (int) Config::get('meilisearch_imagesize');
|
||||||
|
if ($sizeId <= 0) {
|
||||||
|
return '/' . ltrim($path, '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bild über Image Studio erzeugen
|
||||||
|
$figure = $this->imageStudio
|
||||||
|
->createFigure($uuid)
|
||||||
|
->setSize($sizeId)
|
||||||
|
->build();
|
||||||
|
|
||||||
|
return $figure?->getImage()?->getSrc() ?? null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user