Fix adding blocks through media tab with experimental modal.#73029
Fix adding blocks through media tab with experimental modal.#73029tellthemachines merged 4 commits intotrunkfrom
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +31 B (0%) Total Size: 2.47 MB
ℹ️ View Unchanged
|
| if ( ! filters.media_type ) { | ||
| filters.media_type = allowedTypes.includes( '*' ) | ||
| ? undefined | ||
| : allowedTypes[ 0 ]; |
There was a problem hiding this comment.
I'm getting an 400 error when sending multiple media types in 6.8.
{
"code": "rest_invalid_param",
"message": "Invalid parameter(s): media_type",
"data": {
"status": 400,
"params": {
"media_type": "media_type is not one of image, video, text, application, and audio."
},
"details": {
"media_type": {
"code": "rest_not_in_enum",
"message": "media_type is not one of image, video, text, application, and audio.",
"data": null
}
}
}
}It results in an empty modal.
Multiple types are supported in 6.9 after
WordPress/wordpress-develop#10054
I checked against 6.9 and it's all good. 👍🏻
Just mentioning, I'm not sure it's an issue right now given that this is behind an experiment and that it'll be bundled with WP 7 eventually (I guess 😅 )
Gutenberg only supports one version behind the latest if I recall correctly.
There was a problem hiding this comment.
Hmm, once we remove the experiment flag - which will hopefully happen well before 7.0 is prepared - we'll run into that issue because we'll still be supporting 6.8 in Gutenberg.
Is there any easy way to check for support of multiple media files so we can add a condition to this code?
There was a problem hiding this comment.
I'm not sure if there's an easy way to check for support. One option might be to copy over the 6.9 changes to the REST Attachments Controller's prepare_items_query function to the Gutenberg repo for compatibility. That might not need to happen now, but could be something to do before stabilising the experiment?
There was a problem hiding this comment.
Hmm yea I might actually do that in this PR so it's one less thing to remember later!
There was a problem hiding this comment.
Do you have the media processing experiment enabled?
There was a problem hiding this comment.
Nope, media processing experiment is disabled.
There was a problem hiding this comment.
Ok I see what's happening, we can't just copy the core prepare_items_query function because it calls its parent, which in the case of the gutenberg class will be the core one, with the outdated logic 😅
There was a problem hiding this comment.
Re-testing after d070b3b, and the 500 error is no longer present, and multiple media types are available from the media modal 👍
There was a problem hiding this comment.
Follow up here:
I think it's that we haven't created dedicated media fields yet, so the modal is using a naive approach right now for the image. But we should be able to resolve it once we build out dedicated media fields (i.e. in #72612) IMO (i.e. for non-image media, render text of the filename instead of displaying an image in the thumbnail). |
Yes, and for audio (and maybe video?) files that have an associated image we should support displaying that image, like the media library currently does. |
| * @return array Modified array of arguments. | ||
| */ | ||
| function gutenberg_override_attachments_rest_controller( $args, $post_type ) { | ||
| if ( 'attachment' === $post_type && ! gutenberg_is_experiment_enabled( 'gutenberg-media-processing' ) ) { |
There was a problem hiding this comment.
In order to avoid collisions with the media processing experiment which also overrides the same class, we check whether it's enabled before overriding.
I also suffixed the class with _6_9 to avoid redeclaring Gutenberg_REST_Attachments_Controller which already exists in the media processing experiment.
|
Flaky tests detected in cf51c9f. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/19158599738
|
lib/compat/wordpress-6.9/class-gutenberg-rest-attachments-controller-6-9.php
Show resolved
Hide resolved
|
Thanks for the reviews folks! |


What?
Closes
Follow-up from #71944.
Fixes a bug in the media modal experiment where adding media from the media modal that opens in the media tab caused an error in the added block, because the block derives its type from the media type.
Also enables correct media types to display in the media tab modal.
Testing Instructions
media_tab_modal.mp4