This commit is contained in:
Jürgen Mummert
2025-12-23 12:35:01 +01:00
parent 22c6a3e0b6
commit 872a242794
2 changed files with 8 additions and 12 deletions
-2
View File
@@ -10,5 +10,3 @@ services:
tags: tags:
- { name: contao.hook, hook: indexPage, method: onIndexPage } - { name: contao.hook, hook: indexPage, method: onIndexPage }
Contao\CoreBundle\Filesystem\FilesystemInterface:
alias: filesStorage
+8 -10
View File
@@ -2,39 +2,37 @@
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\FilesModel;
use Contao\Image\Studio;
class MeilisearchImageHelper class MeilisearchImageHelper
{ {
public function __construct( public function __construct(
private readonly FilesystemInterface $filesStorage,
private readonly Studio $imageStudio, private readonly Studio $imageStudio,
) {} ) {}
public function getImagePathFromUuid(string $uuid): ?string public function getImagePathFromUuid(string $uuid): ?string
{ {
// UUID → Datei $file = FilesModel::findByUuid($uuid);
if (!$this->filesStorage->fileExists($uuid)) {
if ($file === null) {
return null; return null;
} }
$file = $this->filesStorage->get($uuid); $path = $file->path;
$path = $file->getPath();
// SVG: nicht skalieren // SVG niemals skalieren
if (str_ends_with(strtolower($path), '.svg')) { if (str_ends_with(strtolower($path), '.svg')) {
return '/' . ltrim($path, '/'); return '/' . ltrim($path, '/');
} }
// Bildgröße aus tl_settings
$sizeId = (int) Config::get('meilisearch_imagesize'); $sizeId = (int) Config::get('meilisearch_imagesize');
if ($sizeId <= 0) { if ($sizeId <= 0) {
return '/' . ltrim($path, '/'); return '/' . ltrim($path, '/');
} }
// Bild über Image Studio erzeugen
$figure = $this->imageStudio $figure = $this->imageStudio
->createFigure($uuid) ->createFigure($uuid)
->setSize($sizeId) ->setSize($sizeId)