Skip to content

Commit d3f4f70

Browse files
[5.x] Ensure null values are filtered out in dictionary field config (#11773)
1 parent f2becd1 commit d3f4f70

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/Fieldtypes/DictionaryFields.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function process($data): string|array
7171
return $dictionary->handle();
7272
}
7373

74-
return array_merge(['type' => $dictionary->handle()], $values->all());
74+
return array_merge(['type' => $dictionary->handle()], $values->filter()->all());
7575
}
7676

7777
public function extraRules(): array

tests/Fieldtypes/DictionaryFieldsTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,23 @@ public function it_processes_dictionary_fields_into_a_string_when_dictionary_has
116116
$this->assertEquals('fake_dictionary', $process);
117117
}
118118

119+
#[Test]
120+
public function it_processes_dictionary_fields_and_filters_out_null_values()
121+
{
122+
$fieldtype = FieldtypeRepository::find('dictionary_fields');
123+
124+
$process = $fieldtype->process([
125+
'type' => 'fake_dictionary',
126+
'category' => 'foo',
127+
'foo' => null,
128+
]);
129+
130+
$this->assertEquals([
131+
'type' => 'fake_dictionary',
132+
'category' => 'foo',
133+
], $process);
134+
}
135+
119136
#[Test]
120137
public function it_returns_validation_rules()
121138
{

0 commit comments

Comments
 (0)