Skip to content

Add placeholder flag when image widget has empty _image array#5228

Open
skosarin wants to merge 1 commit intoapostrophecms:mainfrom
skosarin:sk.fix.archived-image-resulting-in-no-placeholder-and-error
Open

Add placeholder flag when image widget has empty _image array#5228
skosarin wants to merge 1 commit intoapostrophecms:mainfrom
skosarin:sk.fix.archived-image-resulting-in-no-placeholder-and-error

Conversation

@skosarin
Copy link
Copy Markdown
Contributor

@skosarin skosarin commented Dec 15, 2025

Summary

Fixes an issue where the image widget fails to display its placeholder after a previously selected image is archived, leaving the widget in a broken state with an empty _image relationship.

The fix extends sanitize to set aposPlaceholder = true before validation when the widget has an empty imageIds array. This is necessary because aposPlaceholder widgets bypass schema conversion entirely — without marking the widget as a placeholder early, the required _image field triggers an error that crashes ApostropheCMS's handleConvertErrors due to an upstream bug with numeric error paths.

What are the specific steps to test this change?

  1. Run the website and log in as an admin.
  2. Create a page with an image widget and select an image.
  3. Archive the selected image (so the widget's _image relationship becomes empty).
  4. Re-open the page editor containing the image widget.
  5. Confirm the image widget displays the placeholder (and does not behave as if an image is still selected).

What kind of change does this PR introduce?

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • Build-related changes
  • Other

Make sure the PR fulfills these requirements:

  • It includes a) the existing issue ID being resolved, b) a convincing reason for adding this feature, or c) a clear description of the bug it resolves
  • The changelog is updated
  • Related documentation has been updated
  • Related tests have been updated

@BoDonkey BoDonkey requested review from BoDonkey and boutell December 15, 2025 19:18
Copy link
Copy Markdown
Member

@boutell boutell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing this. I see the reasoning behind it and I do see how it would be useful to editors. However this would also cause it to appear for the public, which is never intended to occur. So it wouldn't be suitable in its current form.

However, checking for req.query.aposEdit === '1' first might resolve that. I suggest you try that and see if it ensures the placeholder is displayed only when editing and not previewing or just a member of the public viewing the site.

@skosarin
Copy link
Copy Markdown
Contributor Author

at least on my local, it behaves as desired -- no placeholder image when in preview/published, but placeholder appears on edit, and no page error occurs

@boutell
Copy link
Copy Markdown
Member

boutell commented Dec 17, 2025

OK fair, we will QA it directly to see if any further change is actually needed cc @BoDonkey

@boutell
Copy link
Copy Markdown
Member

boutell commented Dec 17, 2025

Oh excuse me, I see you did add the change! Your comment makes more sense now 👍

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.
@skosarin skosarin force-pushed the sk.fix.archived-image-resulting-in-no-placeholder-and-error branch from 8a5a081 to 1cf5160 Compare April 9, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants