-
Notifications
You must be signed in to change notification settings - Fork 115
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
FIX Ensure files can be removed from elemental blocks #1267
FIX Ensure files can be removed from elemental blocks #1267
Conversation
// Would usually be handled by $form->saveInto($element) but since the field names | ||
// in the form have been namespaced, we need to handle it ourselves. | ||
$element->updateFromFormData($dataWithoutNamespaces); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really we should just rename the fields in the form, and then call $form->saveInto($element)
- but doing that now would be an API break because someone may have customised the updateFromFormData()
method in their custom elements.
continue; | ||
} | ||
|
||
$cmsFields = $this->getCMSFields()->saveableFields(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting the saveableFields()
explicitly - things like LiteralField
don't need to be touched here.
foreach ($cmsFields as $fieldName => $field) { | ||
$datum = $data[$fieldName] ?? null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's data, set to the value in the data - otherwise set to null.
This is still skipping a bunch of stuff that $form->saveInto()
would do, but fully replicating that logic isn't in scope here. This change is the least disruptive change required to fix the bug.
94cd28b
to
87a4e42
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code change looks good
I've merged the frameworktest PR and re-rerun behat and it all works
One tiny change
87a4e42
to
527b221
Compare
In CMS 5.2 and earlier, all fields in the form are included in the POST data, including empty upload fields.
In CMS 5.3 the formschema form submission logic is used instead, which omits data for empty upload fields (and possibly for other empty fields as well).
Normally this would be handled just fine with
$form->saveInto($record)
, but elemental doesn't use that so missing data just gets ignored instead of being set to null.CI note
The new behat test relies on a test extension added in silverstripe/silverstripe-frameworktest#210
That PR needs to be merged before this can go green.
Issue