-
-
Notifications
You must be signed in to change notification settings - Fork 177
Fix unsetting field values in changes #7116
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
base: v5/develop
Are you sure you want to change the base?
Conversation
34ad72e
to
b9a286b
Compare
@bastianallgeier It appears to solve part of the problem (image focus can be unset, saved and on reload it remains without focus). However, I am still running in one related problem:
I think the problem originates in |
3a7f208
to
9a7723e
Compare
@distantnative I've tracked it down yesterday and it's getting more complicated again. There are three parts to this. Kirby\Panel\Model::content() should look something like this: public function content(): array
{
$version = $this->model->version('changes');
if ($version->exists('current') === false) {
$version = $this->model->version('latest');
}
// create a form which will collect the latest values for the model,
// but also pass along unpublished changes as overwrites
return Form::for(
model: $this->model,
props: [
'values' => $version->content('current')->toArray()
],
merge: false
)->values();
} This would be very clean, but the problem here is that there might be extra fields in "latest" which will no longer be in the final version. I.e. uuid, slug or template for files. Selectively merging them seems very complicated. Then we need to work on the changes method in our content.js module. We simply ignore removed fields in there. One option could be another loop: changes(env = {}) {
// changes can only be computed for the current view
if (this.isCurrent(env) === false) {
throw new Error("Cannot get changes for another view");
}
const changes = {};
for (const field in panel.view.props.content) {
const changed = JSON.stringify(panel.view.props.content[field]);
const original = JSON.stringify(panel.view.props.originals[field]);
if (changed !== original) {
changes[field] = panel.view.props.content[field];
}
}
for (const field in panel.view.props.originals) {
if (changes[field] === undefined) {
changes[field] = null;
}
}
return changes;
}, Then there's still a problematic part in Controller\Changes::save where we use the form again and it will merge the submitted content with the original version once more. I tried to fix it there as well, but failed so far. It really is still quite a complicated setup. |
Description
When passing null as field value when saving changes, the value from the latest version would be magically merged back in. This PR fixes this regression.
Changelog
Fixes
null
as field value will remove the field correctly from the latest version, when publishing changes.Version::isIdentical()
is now comparing two versions more reliably, by not merging original values.Enhancements
merge: true
argument forKirby\Form\Form::for()
which will disable merging original values. Merging is activated by default.Breaking changes
None
Ready?
For review team