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
+28 -7
@@ -14,6 +14,7 @@ use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Resource\FileRepository; use TYPO3\CMS\Core\Resource\FileRepository;
use TYPO3\CMS\Core\Service\FlexFormService; use TYPO3\CMS\Core\Service\FlexFormService;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Service\ImageService;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
/** /**
@@ -349,13 +350,33 @@ final class MenuBuilder
return null; return null;
} }
try { try {
return [ // Menu tiles are small: ship a processed 640px webp instead of the
'url' => $reference->getPublicUrl(), // original upload - multi-MB teaser images went over the wire
'alternative' => (string)$reference->getProperty('alternative'), // (found 2026-10-23). 640 matches the search-tile convention; the
'title' => (string)$reference->getProperty('title'), // original URL stays the fallback when processing fails, so the
'width' => (int)$reference->getProperty('width'), // menu never loses an image over a converter hiccup.
'height' => (int)$reference->getProperty('height'), 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'),
'title' => (string)$reference->getProperty('title'),
'width' => (int)$reference->getProperty('width'),
'height' => (int)$reference->getProperty('height'),
];
}
} catch (\Throwable) { } catch (\Throwable) {
return null; return null;
} }