From 15a93466b6574aed4979f391ebcc3973555dea91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Mummert?= Date: Sun, 1 Mar 2026 10:56:38 +0100 Subject: [PATCH] Adjust FilePond sizing and upload resize rules --- .../templates/frontend/event_edit.html.twig | 38 +++++++++++++++++++ .../frontend/organization_edit.html.twig | 38 +++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/contao/templates/frontend/event_edit.html.twig b/contao/templates/frontend/event_edit.html.twig index 16d6351..09623ae 100644 --- a/contao/templates/frontend/event_edit.html.twig +++ b/contao/templates/frontend/event_edit.html.twig @@ -10,11 +10,19 @@ + + + {{ form_start(form, { action: app.request.uri, attr: { 'aria-live': 'polite' } }) }} @@ -212,6 +220,12 @@ if (typeof window.FilePondPluginImagePreview !== 'undefined') { window.FilePond.registerPlugin(window.FilePondPluginImagePreview); } + if (typeof window.FilePondPluginImageResize !== 'undefined') { + window.FilePond.registerPlugin(window.FilePondPluginImageResize); + } + if (typeof window.FilePondPluginImageTransform !== 'undefined') { + window.FilePond.registerPlugin(window.FilePondPluginImageTransform); + } const filePondOptions = { instantUpload: false, @@ -220,6 +234,30 @@ allowReplace: true, credits: false, acceptedFileTypes: ['image/*'], + allowImageResize: true, + imageResizeUpscale: false, + allowImageTransform: true, + onaddfile: function (error, fileItem) { + if (error || !fileItem || typeof fileItem.setMetadata !== 'function') { + return; + } + + const fileType = fileItem.fileType || (fileItem.file && fileItem.file.type) || ''; + + if (fileType === 'image/svg+xml') { + fileItem.setMetadata('resize', null); + return; + } + + fileItem.setMetadata('resize', { + mode: 'contain', + upscale: false, + size: { + width: 2000, + height: 2000 + } + }); + }, labelIdle: 'Bild hierher ziehen oder durchsuchen' }; diff --git a/contao/templates/frontend/organization_edit.html.twig b/contao/templates/frontend/organization_edit.html.twig index df29c5b..c2a09ce 100644 --- a/contao/templates/frontend/organization_edit.html.twig +++ b/contao/templates/frontend/organization_edit.html.twig @@ -8,9 +8,17 @@ + + + {{ form_start(form, { attr: { 'aria-live': 'polite' } }) }} @@ -73,6 +81,12 @@ if (typeof window.FilePondPluginImagePreview !== 'undefined') { window.FilePond.registerPlugin(window.FilePondPluginImagePreview); } + if (typeof window.FilePondPluginImageResize !== 'undefined') { + window.FilePond.registerPlugin(window.FilePondPluginImageResize); + } + if (typeof window.FilePondPluginImageTransform !== 'undefined') { + window.FilePond.registerPlugin(window.FilePondPluginImageTransform); + } const filePondOptions = { instantUpload: false, @@ -81,6 +95,30 @@ allowReplace: true, credits: false, acceptedFileTypes: ['image/*'], + allowImageResize: true, + imageResizeUpscale: false, + allowImageTransform: true, + onaddfile: function (error, fileItem) { + if (error || !fileItem || typeof fileItem.setMetadata !== 'function') { + return; + } + + const fileType = fileItem.fileType || (fileItem.file && fileItem.file.type) || ''; + + if (fileType === 'image/svg+xml') { + fileItem.setMetadata('resize', null); + return; + } + + fileItem.setMetadata('resize', { + mode: 'contain', + upscale: false, + size: { + width: 800, + height: 800 + } + }); + }, labelIdle: 'Logo hierher ziehen oder durchsuchen' };