Hi Daniel,
We ran into this while migrating a v13 site to v17. If you put an Umbraco Image Cropper on a block's element type and then try to save the page, the save fails with:
It isn't specific to the Image Cropper – the File Upload editor has exactly the same problem. Both store their uploaded file against the content (via MediaFileManager.GetMediaPath(fileName, contentKey, propertyTypeKey)), so both need the content key. Editors that only store a reference save fine – including Media Picker (v3), which stores a reference to the Media library rather than a file on the content, so it never touches the content key.
Root cause
In ContentBlocksValueEditor.FromEditor each inner block property is passed through its own value editor like this:
var propData = new ContentPropertyData(prop.Value, configuration);
prop.Value = valueEditor.FromEditor(propData, prop.Value);
The ContentPropertyData is built without a ContentKey or PropertyTypeKey, so both default to Guid.Empty. Both ImageCropperPropertyValueEditor.FromEditor and FileUploadPropertyValueEditor.FromEditor explicitly throw "Invalid content key" when the key is empty, and use it to build the media storage path. Editors that don't write a file on the content ignore those two properties, which is why everything else saves without a problem.
Umbraco core hit the exact same thing in its own block editors – image cropper in a block wouldn't save (umbraco/Umbraco-CMS#16664) – and handles it in BlockValuePropertyValueEditorBase.MapBlockItemDataFromEditor by setting both keys before calling the inner FromEditor:
var propertyData = new ContentPropertyData(editedValue?.Value, configuration)
{
ContentKey = contentKey,
PropertyTypeKey = propertyType.Key,
};
(That core change landed in umbraco/Umbraco-CMS#18976.)
Suggested fix
Set the same two keys in ContentBlocksValueEditor.FromEditor, mirroring core – the content key is already available on the incoming editorValue:
var propData = new ContentPropertyData(prop.Value, configuration)
{
ContentKey = editorValue.ContentKey,
PropertyTypeKey = prop.PropertyType.Key,
};
With that in place both the Image Cropper and File Upload save correctly inside a block. Happy to open a PR for this.
Environment
- Umbraco 17.x
- Perplex.ContentBlocks v4
Hi Daniel,
We ran into this while migrating a v13 site to v17. If you put an Umbraco Image Cropper on a block's element type and then try to save the page, the save fails with:
It isn't specific to the Image Cropper – the File Upload editor has exactly the same problem. Both store their uploaded file against the content (via
MediaFileManager.GetMediaPath(fileName, contentKey, propertyTypeKey)), so both need the content key. Editors that only store a reference save fine – including Media Picker (v3), which stores a reference to the Media library rather than a file on the content, so it never touches the content key.Root cause
In
ContentBlocksValueEditor.FromEditoreach inner block property is passed through its own value editor like this:The
ContentPropertyDatais built without aContentKeyorPropertyTypeKey, so both default toGuid.Empty. BothImageCropperPropertyValueEditor.FromEditorandFileUploadPropertyValueEditor.FromEditorexplicitly throw"Invalid content key"when the key is empty, and use it to build the media storage path. Editors that don't write a file on the content ignore those two properties, which is why everything else saves without a problem.Umbraco core hit the exact same thing in its own block editors – image cropper in a block wouldn't save (umbraco/Umbraco-CMS#16664) – and handles it in
BlockValuePropertyValueEditorBase.MapBlockItemDataFromEditorby setting both keys before calling the innerFromEditor:(That core change landed in umbraco/Umbraco-CMS#18976.)
Suggested fix
Set the same two keys in
ContentBlocksValueEditor.FromEditor, mirroring core – the content key is already available on the incomingeditorValue:With that in place both the Image Cropper and File Upload save correctly inside a block. Happy to open a PR for this.
Environment