Skip to content
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

[5.x] Use default value from field config #9010

Merged
merged 9 commits into from Apr 17, 2024

Conversation

duncanmcclean
Copy link
Member

This pull request makes it so when there's no raw value for a field (eg. data saved for the field in an entry's YAML file), Statamic will now augment the default value for the field, if one is provided. This means that you no longer need to re-save all entries after setting the default value for a field.

This PR is targeting master (Statamic 5) since changing the behaviour is a breaking change.

Fixes #8804.

src/Fields/Value.php Outdated Show resolved Hide resolved
- show that the default value definitely gets augmented
- show that having a default value configured doesn't mess with a passed value
@jasonvarga
Copy link
Member

jasonvarga commented Mar 7, 2024

I was about to merge this but then realized we have Field::defaultValue() and Fieldtype::defaultValue(). Maybe we should think about all the relevant spots and make sure it all works as expected.

Maybe it's just that $this->fieldtype->config('default') should get changed to $this->fieldtype->field()->defaultValue(). Tests would need to check for fieldtypes that provide their own default values.

@jasonvarga
Copy link
Member

Just dumping thoughts here. You don't need to make any changes. I'll loop back around to this.

Somewhere that this is a little iffy is in any entry listing.

My Something field has a default value, but you don't see it anywhere. I'd expect to see it.

CleanShot 2024-03-07 at 15 36 23

This is because we deal with just values, not augmented values:

$value = $extra[$key] ?? $this->resource->value($key);

I don't think Entry::value() should be inheriting the default values though, since it's supposed to just be a way to see what values have been explicitly set.

So maybe we just change that ListedEntry::values() method to get the default fallbacks.

Within templates, GraphQL, and the API, it all seems good. 👌

@jasonvarga jasonvarga self-assigned this Mar 25, 2024
@jasonvarga jasonvarga changed the title [5.x] Augment using default value when no raw value exists [5.x] Use default value from field config Apr 17, 2024
@jasonvarga jasonvarga merged commit ec5a829 into master Apr 17, 2024
31 checks passed
@jasonvarga jasonvarga deleted the when-no-value-exists-augment-to-the-default-value branch April 17, 2024 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants