Skip to content

Commit 65d0a15

Browse files
committed
fix: Files field id handling
1 parent 7839292 commit 65d0a15

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

config/fields/files.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use Kirby\Cms\File;
44
use Kirby\Cms\ModelWithContent;
55
use Kirby\Panel\Controller\Dialog\FilesPickerDialogController;
6+
use Kirby\Toolkit\A;
67

78
return [
89
'mixins' => [
@@ -58,14 +59,20 @@
5859
},
5960
],
6061
'methods' => [
61-
'toId' => function (File $file) {
62-
return match ($file->parent() !== $this->model()) {
63-
true => $file->id(),
64-
false => $file->filename()
65-
};
66-
},
6762
'toModel' => function (string $id) {
6863
return $this->kirby()->file($id, $this->model);
64+
},
65+
'toStoredValues' => function ($value = null) {
66+
return A::map(
67+
$value ?? [],
68+
function (string $id) {
69+
$file = $this->toModel($id);
70+
return match ($file->parent() !== $this->model()) {
71+
true => (string)$file->{$this->store}(),
72+
false => $file->filename()
73+
};
74+
}
75+
);
6976
}
7077
],
7178
'api' => function () {

0 commit comments

Comments
 (0)