Skip to content

Commit 6fceebd

Browse files
simonworkhouseKailum
andauthored
[5.x] Fix values being wrapped in arrays causing multiple selected options (#11630)
Co-authored-by: Kailum <kailum.bull@workhouseadvertising.com.au>
1 parent 5e08d26 commit 6fceebd

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

src/Fieldtypes/HasSelectOptions.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ public function preProcessIndex($value)
5252
{
5353
$values = $this->preProcess($value);
5454

55-
$values = collect(is_array($values) ? $values : [$values]);
56-
57-
return $values->map(function ($value) {
55+
// NOTE: Null-coalescing into `[null]` as that matches old behaviour.
56+
return collect($values ?? [null])->map(function ($value) {
5857
return $this->getLabel($value);
5958
})->all();
6059
}
@@ -67,9 +66,8 @@ public function preProcess($value)
6766
return [];
6867
}
6968

70-
$value = is_array($value) ? $value : [$value];
71-
72-
$values = collect($value)->map(function ($value) {
69+
// NOTE: Null-coalescing into `[null]` as that matches old behaviour.
70+
$values = collect($value ?? [null])->map(function ($value) {
7371
return $this->config('cast_booleans') ? $this->castFromBoolean($value) : $value;
7472
});
7573

0 commit comments

Comments
 (0)