From 19367cdb8c261b4a10310cc9f92f43806bdb43b8 Mon Sep 17 00:00:00 2001 From: Sten Govaerts Date: Mon, 18 Nov 2024 13:18:05 +0100 Subject: [PATCH] Fix translatable asset controller: make sure the locale is properly passed --- src/Http/Controllers/AssetController.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Http/Controllers/AssetController.php b/src/Http/Controllers/AssetController.php index 273bef2..52b26d3 100644 --- a/src/Http/Controllers/AssetController.php +++ b/src/Http/Controllers/AssetController.php @@ -40,11 +40,14 @@ private function getAssetMedia(HasMedia $asset, ?string $locale = null): ?Media $assetMedia = null; if (! $locale && FilamentFlexibleBlocksAssetManagerConfig::hasTranslatableAssets()) { $locale = app()->getLocale(); - $filters = ['locale' => $locale]; - $assetMedia = $asset->getFirstMedia($asset->getAssetCollection(), $filters); } + //first try with locale + $filters = ['locale' => $locale]; + $assetMedia = $asset->getFirstMedia($asset->getAssetCollection(), $filters); + if (! $assetMedia) { + //if no media with locale try fallback: $assetMedia = $asset->getFirstMedia($asset->getAssetCollection()); }