Data loss on Content preview
Not sure if really a bug but there is a specific case where fields are removed on content preview.
Details
| Question | Answer |
|---|---|
| Relevant Bolt Version | 5.1.4 |
| Install type | Composer install |
| BC Break | no |
| PHP version | 7.4 |
Reproduction
The condition is to have a contentType with bad typed field, for example :
entries:
name: Entries
singular_name: Entry
fields:
title:
type: string # instead of text
class: large
group: content
On edit, we can save the content with a valid title, but the field will be persisted with the generic type
After some investigation, I understood that the field is removed beforehand because of the type check in hasField
https://github.com/bolt/core/blob/2d02f5d4893ab00ea18ca5d2a909e30c71102f18/src/Controller/Backend/ContentEditController.php#L483-L493
The point is that the Preview behaviour is to reproduce the Save behaviour without persist, but the removed field is still flushed, thus losing data.
I know the issue won't happen with a correct configuration but I still wanted to warn those who'd face the same case as me.
In an effort to keep our issue list manageable, we are marking this issue as stale because it has been 60 days without activity. If this issue is still relevant, please let us know by posting a quick comment so that it remains open.