Skip to content

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

Open
skosarin wants to merge 7 commits 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 7 commits intoapostrophecms:mainfrom
skosarin:sk.fix.archived-image-resulting-in-no-placeholder-and-error

Conversation

@skosarin
Copy link
Contributor

@skosarin skosarin commented Dec 15, 2025

Summary

Fixes an issue where the image widget could incorrectly have aposPlaceholder: false even when its _image relationship is empty. This ensures the placeholder displays correctly for image widgets with no selected image.

This situation can occur when a previously selected image is archived, and an editor later opens the page containing that image widget.

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

Other information:
Normalizes widget state during widget loading to prevent aposPlaceholder from remaining false when _image is an empty array. This avoids a broken/non-placeholder UI state after archiving images previously selected by an image widget.

Extends the load method to set aposPlaceholder to true when a widget has an empty _image array, ensuring proper placeholder display for image widgets without selected images.

Issue occurs when an already selected image is archived and a user edits the page with said image-widget
Adds changelog entry documenting the fix for image widgets failing to display placeholders when selected images are archived, resulting in empty _image relationships.
@BoDonkey BoDonkey requested review from BoDonkey and boutell December 15, 2025 19:18
Copy link
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.

Adds early return in load method to skip placeholder processing when aposEdit query parameter is not set to '1', preventing unnecessary placeholder logic execution outside of edit context.
@skosarin
Copy link
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
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
Member

boutell commented Dec 17, 2025

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

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