Repository navigation
Pass the stored value to nested editors when saving a block - #111
talhamalik4025 wants to merge 1 commit into
Conversation
Each nested value went through FromEditor with the incoming editor value as currentValue. Editors that store a file (Image Cropper, File Upload) use currentValue to find the existing file, so clearing one inside a block left the file behind and stored the text "null", after which publishing the page failed. Look up the stored block by id and its value by alias and pass that instead, mirroring Umbraco core's BlockValuePropertyValueEditorBase.MapBlockItemDataFromEditor. Fixes PerplexDigital#110 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| PropertyTypeKey = prop.PropertyType.Key, | ||
| }; | ||
| prop.Value = valueEditor.FromEditor(propData, prop.Value); | ||
| var currentPropValue = currentData?.Values.FirstOrDefault(current => current.Alias == prop.Alias)?.Value; |
There was a problem hiding this comment.
It's hard for me to oversee the consequences of this where you change from prop.Value to currentPropValue. Will this not introduce regressions with other property editors that do not need this fix to begin with? I don't know the answer here either but I am a bit hesitant to update this very import method without knowing the possible effects of this change.
|
Thanks for looking at it, fair question. I went through every value editor in Umbraco 17.7.1 that overrides Before this change, nested editors never saw the stored value. Everywhere else in Umbraco,
Most editors never read it. 13 of the 21 core overrides don't reference The editors that do read it expect the stored value:
A new block, or a property the stored block doesn't have, gets So the change only affects editors that read The 13 core overrides that never read
|
Fixes #110
ContentBlocksValueEditor.FromEditorpassed each nested property's incoming editor value ascurrentValue. File-based editors (Image Cropper, File Upload) usecurrentValueto find the existing file, so clearing an image in a block left the file on disk and stored the text"null", after which Actions → Publish… failed with a 500.This matches the stored blocks by id and their values by alias, as Umbraco's own block editors do (
BlockValuePropertyValueEditorBase.MapBlockItemDataFromEditor), and passes the stored value.Tested on Umbraco 17.7.1 with this branch built from source, on a page with one block keeping its image and one clearing it:
"null"; file stays on disknull; file deletedThe other block's image, its file and its text values are unchanged. A later save with no edits still stores
"null"through Umbraco's own cropper code (umbraco/Umbraco-CMS#24335), which this PR doesn't touch.Not included: Umbraco also deletes the files of blocks that are removed entirely. Happy to add that here or in a follow-up.