Skip to content

Commit 75b7145

Browse files
committed
Bugfix for display value for "Image"/"File" field if translatable
1 parent 64bd76e commit 75b7145

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

src/Fields/Converters/FileConverter.php

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,30 @@ public function toDisplayValue(mixed $sourceValue, ?string $locale, ?string $fal
1111
$disk = $this->fieldTypeConfig->disk ?? config('filesystems.default');
1212
$directory = $this->fieldTypeConfig->directory;
1313

14-
if (! is_array($sourceValue)) {
15-
$sourceValue = array_filter([$sourceValue]);
16-
}
1714

18-
return collect($sourceValue)
19-
->map(fn ($path) => FileDto::fromArray([
20-
'path' => $path,
21-
'disk' => $disk,
22-
'directory' => $directory,
23-
]))
24-
->values()
25-
->all();
15+
try {
16+
// Ensure is array
17+
if (! is_array($sourceValue)) {
18+
$sourceValue = array_filter([$sourceValue]);
19+
}
20+
21+
// Pick value if is translatable
22+
if ($this->fieldTypeConfig->translatable) {
23+
$sourceValue = $sourceValue[$locale] ?? $sourceValue[$fallbackLocale] ?? [];
24+
}
25+
26+
return collect($sourceValue)
27+
->map(fn ($path) => FileDto::fromArray([
28+
'path' => $path,
29+
'disk' => $disk,
30+
'directory' => $directory,
31+
]))
32+
->values()
33+
->all();
34+
35+
} catch (\Throwable $th) {
36+
// fallback as empty array
37+
return [];
38+
}
2639
}
2740
}

0 commit comments

Comments
 (0)