Add placeholder flag when image widget has empty _image array#5228
Add placeholder flag when image widget has empty _image array#5228skosarin wants to merge 1 commit intoapostrophecms:mainfrom
Conversation
boutell
left a comment
There was a problem hiding this comment.
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.
|
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 |
|
OK fair, we will QA it directly to see if any further change is actually needed cc @BoDonkey |
|
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.
8a5a081 to
1cf5160
Compare
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
_imagerelationship.The fix extends
sanitizeto setaposPlaceholder = truebefore validation when the widget has an emptyimageIdsarray. This is necessary becauseaposPlaceholderwidgets bypass schema conversion entirely — without marking the widget as a placeholder early, the required_imagefield triggers an error that crashes ApostropheCMS'shandleConvertErrorsdue to an upstream bug with numeric error paths.What are the specific steps to test this change?
_imagerelationship becomes empty).What kind of change does this PR introduce?
Make sure the PR fulfills these requirements: