Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/apostrophe/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## UNRELEASED

### Fixes

- Fixes an issue where an image widget could fail to display its placeholder after the selected image is archived, leaving an empty `_image` relationship.

## 4.28.0

### Adds
Expand Down
19 changes: 19 additions & 0 deletions packages/apostrophe/modules/@apostrophecms/image-widget/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,25 @@ module.exports = {
},
extendMethods(self) {
return {
async sanitize(_super, req, input, options, convertOptions) {
// If the widget has no image and is not already a placeholder,
// mark it as a placeholder before validation so the required
// _image field check is skipped (aposPlaceholder widgets bypass
// schema conversion entirely). Without this, the required field
// error crashes ApostropheCMS's handleConvertErrors due to an
// upstream bug with numeric error paths.

// NOTE: This function only runs during the render-widget API call
// (the admin editor's widget validation/rendering endpoint)
if (
input.aposPlaceholder === false &&
Array.isArray(input.imageIds) &&
input.imageIds.length === 0
) {
input.aposPlaceholder = true;
}
return _super(req, input, options, convertOptions);
},
getBrowserData(_super, req) {
return {
..._super(req),
Expand Down
Loading