From e3f842f2d320d6fd67360eb691109aa4e5e20121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Mummert?= Date: Wed, 4 Mar 2026 17:26:46 +0100 Subject: [PATCH] Fix image lightbox click handling and module image size rendering --- .../FrontendModule/PinboardController.php | 29 +++++++++++++++++-- src/Resources/public/js/pinboard.js | 4 +++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/Controller/FrontendModule/PinboardController.php b/src/Controller/FrontendModule/PinboardController.php index 391d50b..239bc0a 100644 --- a/src/Controller/FrontendModule/PinboardController.php +++ b/src/Controller/FrontendModule/PinboardController.php @@ -5,15 +5,22 @@ declare(strict_types=1); namespace Eiswurm\ContaoPinboardBundle\Controller\FrontendModule; use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController; +use Contao\CoreBundle\Image\Studio\Studio; use Contao\CoreBundle\Twig\FragmentTemplate; use Contao\FilesModel; use Contao\ModuleModel; +use Contao\StringUtil; use Eiswurm\ContaoPinboardBundle\Model\PinboardModel; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; final class PinboardController extends AbstractFrontendModuleController { + public function __construct( + private readonly Studio $studio, + ) { + } + protected function getResponse(FragmentTemplate $template, ModuleModel $model, Request $request): Response { $collection = PinboardModel::findBy( @@ -26,11 +33,27 @@ final class PinboardController extends AbstractFrontendModuleController if (null !== $collection) { foreach ($collection as $entry) { - $imagePath = null; + $imageFigure = null; if ($entry->bild) { $fileModel = FilesModel::findByUuid($entry->bild); - $imagePath = $fileModel?->path; + + if (null !== $fileModel) { + $figureBuilder = $this->studio + ->createFigureBuilder() + ->fromFilesModel($fileModel) + ->enableLightbox() + ->setLightboxGroupIdentifier('pinnwand-'.$model->id) + ; + + $imageSize = StringUtil::deserialize($model->imgSize, true); + + if ([] !== $imageSize) { + $figureBuilder->setSize($imageSize); + } + + $imageFigure = $figureBuilder->buildIfResourceExists(); + } } $notes[] = [ @@ -40,7 +63,7 @@ final class PinboardController extends AbstractFrontendModuleController 'link' => (string) $entry->link, 'dateAdded' => (int) $entry->dateAdded, 'dateModified' => (int) $entry->dateModified, - 'imagePath' => $imagePath, + 'imageFigure' => $imageFigure, 'highlighted' => '1' === $entry->hervorgehoben, ]; } diff --git a/src/Resources/public/js/pinboard.js b/src/Resources/public/js/pinboard.js index 158c4ee..6f7684a 100644 --- a/src/Resources/public/js/pinboard.js +++ b/src/Resources/public/js/pinboard.js @@ -57,6 +57,10 @@ let offsetY = 0; note.addEventListener('pointerdown', (event) => { + if (event.target instanceof Element && event.target.closest('a, button, input, select, textarea, label')) { + return; + } + dragging = true; pointerId = event.pointerId; note.setPointerCapture(pointerId);