Megamenu: ship menu images as processed 640px webp

MenuBuilder::image() returned getPublicUrl() of the ORIGINAL upload, so
the Success Stories teaser cards (and item/featured images) carried
multi-MB files into every page payload. All menu images now go through
the ImageService (maxWidth 640, webp - the search-tile convention);
width/height report the processed size, and the original URL remains
the fallback when processing fails so the menu never loses an image.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
orascheandClaude Fable 5 committed 2026-10-23 14:13:56 +02:00
1 parent cbe46cdba2
commit b1357a6ffe
1 file changed
+21
@@ -14,6 +14,7 @@ use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Resource\FileRepository;
use TYPO3\CMS\Core\Service\FlexFormService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Service\ImageService;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
/**
@@ -349,6 +350,25 @@ final class MenuBuilder
return null;
}
try {
// Menu tiles are small: ship a processed 640px webp instead of the
// original upload - multi-MB teaser images went over the wire
// (found 2026-10-23). 640 matches the search-tile convention; the
// original URL stays the fallback when processing fails, so the
// menu never loses an image over a converter hiccup.
try {
$imageService = GeneralUtility::makeInstance(ImageService::class);
$processed = $imageService->applyProcessingInstructions(
$reference,
['maxWidth' => 640, 'fileExtension' => 'webp']
);
return [
'url' => $imageService->getImageUri($processed),
'alternative' => (string)$reference->getProperty('alternative'),
'title' => (string)$reference->getProperty('title'),
'width' => (int)$processed->getProperty('width'),
'height' => (int)$processed->getProperty('height'),
];
} catch (\Throwable) {
return [
'url' => $reference->getPublicUrl(),
'alternative' => (string)$reference->getProperty('alternative'),
@@ -356,6 +376,7 @@ final class MenuBuilder
'width' => (int)$reference->getProperty('width'),
'height' => (int)$reference->getProperty('height'),
];
}
} catch (\Throwable) {
return null;
}