Inserter media: save item metadata on the uploaded attachment#80370
Inserter media: save item metadata on the uploaded attachment#80370thrijith wants to merge 5 commits into
Conversation
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
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. |
…:thrijith/gutenberg into add/60378-inserter-media-attachment-meta
What?
When an image from an inserter media category (Openverse or one registered via
registerInserterMediaCategory()) is uploaded to the media library, the item'stitle,alt, and new optionaldescriptionare now saved on the attachment. A new optionalfilenameproperty sets the uploaded file's name.data:/blob:URLs no longer have a filename derived from them.Fixes #60378.
Why?
Only
captionwas forwarded to the upload. Title and alt text reached the block but not the attachment, so the media library filled with items that had no alt text and a URL-derived title and filename (e.g.image-n.pngfor generated images). Image-generation providers like ClassifAI (see 10up/classifai#729) know the prompt at insert time and need a way to store it as the attachment's title, alt text, and description.How?
MediaPreview'sonMediaInsertaddsalt_text,title, anddescriptionto the upload'sadditionalData, each only when the item provides a value, so server-side defaults still apply otherwise.filenameanddescriptionproperties onInserterMediaItem.media.filename || getFilename( url ) || 'image.jpg', skippinggetFilename()fordata:/blob:URLs since they contain no filename. Previously the derived name for adata:URL had no valid extension and the upload could fail.Known limitation: drag-and-drop from the media tab uses the image block's sideload path and doesn't carry item metadata; that needs cross-package plumbing and is left as a follow-up.
Testing Instructions
Register a test category in the browser console on a post editor screen:
Inserter → Media → Test → click the item; wait for "Image uploaded and inserted."
Media Library → newest attachment: file is
my-image.jpg; title, alt text, and description match the item.Repeat with a
data:image/png;base64,…urland nofilename: upload succeeds, file namedimage.png.Openverse: insert a CORS-allowed result (e.g. "Vincent van Gogh sunflowers painting") — attachment title matches the item title.
npm run test:unit -- packages/block-editor/src/components/inserter/media-tab/test/media-preview.js— 6 tests pass.