[5.x] Drop default values from fieldtypes #10272
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In Statamic 5, we introduced some changes to how field configs work. Instead of saving all of a field's config options in a blueprint or fieldset's YAML file, we only saved the config options that differ from the option's default. This change is intended to help tidy up blueprints & fieldsets.
As a side affect of this change, it meant that when fieldtypes went to get their config values, they'd only be able to access those config options which are explicitly set in the field config (eg. the config values which differ from their defaults).
We fixed this in #10139, where the
Fieldtype::config()
method now merges in the default values from the fieldtype's config options.However, as a result of this fix, it means that the
$defaultValue
property set on some of our fieldtypes would be the value it'd fallback to.For some of our fieldtypes (including the
Relationship
one), the default value was set to an empty array. However, our fieldtypes were expecting to getnull
when no value was provided.This PR fixes that by removing the
$defaultValue = []
property from some of our fieldtypes, to ensure the default value for them isnull
.Fixes #10268.
Replaces #10270.