-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block Library - Gallery: Set 'addToGallery' prop to false when images don't have IDs #30122
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking this one! We can also filter out any unexpected data in the array. This can help guard against malformed data (potentially from bugs/accidental user-edits).
@glendaviesnz since you've been 👀 the Gallery block refactor, is it expected that the pattern in two images side-by-side has serialized null ids? If not, do you have a recommendation for a better spot to validate values here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @gwwar, for the review.
It makes sense.
I think we should keep image IDs check separated. While patterns might not have IDs, technically, images are there, and we want to have an edit component in that state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is the way the gallery handles external images, eg. if you add a stand alone image block and choose the option to add it from url, and then transform the image block to a gallery block it will add a
null
entry to theids
array.I had a quick look at it appears like the ideal fix for this will need to go in the core media browser, as it needs to know that if it is passed an
addToGallery=true
, but an emptyvalue
, to assume that a gallery with external images is being updated, and in which case it would need to display those images in the gallery edit screen, even though they are not saved in the media library.Currently @Mamaduka your fix prevents all of the images being added by default, but the media library defaults to 'Create gallery' which means that the existing images are overwritten:
This is ok with the patterns use case, as we can probably assume the user wants to replace the placeholder images, but as mentioned above it is possible for a user to create their own gallery with
null
image ids, in which case their images will be lost if they try to add additional images from the media library.I had a quick look and couldn't see a way around this from the block side of things. I will have a look at the core side and see what options there might be, but not familiar with that code so not sure how far I will get.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the current behaviour anyway I just realised, ie. if a user edits a gallery with
null
id images their existing images are lost, so we wouldn't make things any worse by at least not adding all images by default.