Skip to content

[5.x] Ensure null values are filtered out in dictionary field config #11773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Fieldtypes/DictionaryFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function process($data): string|array
return $dictionary->handle();
}

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

public function extraRules(): array
Expand Down
17 changes: 17 additions & 0 deletions tests/Fieldtypes/DictionaryFieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,23 @@ public function it_processes_dictionary_fields_into_a_string_when_dictionary_has
$this->assertEquals('fake_dictionary', $process);
}

#[Test]
public function it_processes_dictionary_fields_and_filters_out_null_values()
{
$fieldtype = FieldtypeRepository::find('dictionary_fields');

$process = $fieldtype->process([
'type' => 'fake_dictionary',
'category' => 'foo',
'foo' => null,
]);

$this->assertEquals([
'type' => 'fake_dictionary',
'category' => 'foo',
], $process);
}

#[Test]
public function it_returns_validation_rules()
{
Expand Down