Skip to content

Commit 1cf5160

Browse files
committed
Fix image widget placeholder when selected image is archived
Extends sanitize to set aposPlaceholder before validation when a widget has an empty imageIds array. This bypasses the required _image field check, which is necessary because aposPlaceholder widgets skip schema conversion entirely — without this, a required field error crashes ApostropheCMS's handleConvertErrors due to an upstream bug with numeric error paths.
1 parent f08591f commit 1cf5160

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

packages/apostrophe/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## UNRELEASED
4+
5+
### Fixes
6+
7+
- Fixes an issue where an image widget could fail to display its placeholder after the selected image is archived, leaving an empty `_image` relationship.
8+
39
## 4.28.0
410

511
### Adds

packages/apostrophe/modules/@apostrophecms/image-widget/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,25 @@ module.exports = {
189189
},
190190
extendMethods(self) {
191191
return {
192+
async sanitize(_super, req, input, options, convertOptions) {
193+
// If the widget has no image and is not already a placeholder,
194+
// mark it as a placeholder before validation so the required
195+
// _image field check is skipped (aposPlaceholder widgets bypass
196+
// schema conversion entirely). Without this, the required field
197+
// error crashes ApostropheCMS's handleConvertErrors due to an
198+
// upstream bug with numeric error paths.
199+
200+
// NOTE: This function only runs during the render-widget API call
201+
// (the admin editor's widget validation/rendering endpoint)
202+
if (
203+
input.aposPlaceholder === false &&
204+
Array.isArray(input.imageIds) &&
205+
input.imageIds.length === 0
206+
) {
207+
input.aposPlaceholder = true;
208+
}
209+
return _super(req, input, options, convertOptions);
210+
},
192211
getBrowserData(_super, req) {
193212
return {
194213
..._super(req),

0 commit comments

Comments
 (0)