statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
3.58k stars 490 forks source link

Unexpected breaking change for default field values #10002

Closed o1y closed 1 month ago

o1y commented 2 months ago

Bug description

In V5 Statamic seems to always use the default value of a field, even if the field property is not present in the markdown. In V4 null was returned in this case. I'm not sure if this is an expected behavior, but this could break some templates.

How to reproduce

  1. Create a field, e.g. page_layout and put {{ page_layout }} to your Antlers template.
  2. Set a default value to this field, e.g default.
  3. Create a field condition, so the field remains hidden in the public form initially (e.g. by creating a Toggle field).
  4. Save the entry. Correct Result: page_layout property is not saved to the markdown.

Parsing V5 (new):

Parsing V4:

Logs

No response

Environment

v5.0.0-beta.3

Installation

Fresh statamic/statamic site via CLI

Antlers Parser

None

Additional details

No response

jasonvarga commented 2 months ago

Yes in v5 the default value you pick in blueprints will be the actual value now.

o1y commented 2 months ago

Ok, thanks! I’ll then migrate my templates.

o1y commented 1 month ago

This somehow causes more problems than it helps :)

Is it really intended behaviour to return a default value for a field which is completely hidden from the publish form?

duncanmcclean commented 1 month ago

Is it really intended behaviour to return a default value for a field which is completely hidden from the publish form?

Yes, it's intended, field conditions only apply to publish forms.

If you have conditional logic, you should probably be mirroring that in your templates, like this:

{{ if a_toggle_that_controls_whether_another_is_shown }}
  {{ the_other_one }}
{{ /if }}

Instead of just this:

{{ the_other_one }}