-
Notifications
You must be signed in to change notification settings - Fork 4.6k
WIP: Explore mediaRoles in block config
#72792
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
base: trunk
Are you sure you want to change the base?
Conversation
|
Size Change: +132 B (+0.01%) Total Size: 2.37 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in be2f49d. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/18915118688
|
Mamaduka
left a comment
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.
The top-level setting name aside, I like that the definition can be static and doesn't require. This will also allow developers to extend existing blocks and enable the feature.
cc @fabiankaegy
| "mediaRoles": { | ||
| "id": "id", | ||
| "url": "url", | ||
| "alt": "alt", | ||
| "type": { "attribute": "backgroundType" } | ||
| }, |
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.
If I understand this correctly, the type can have a hardcoded value or derive it from a specific attribute. Is that correct?
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 needed to handle both blocks without a type attribute like Image and the ones that have a type.
What I haven't thought much right now is what happens if blocks have already a similar type attribute, but its values are not strictly among image|video|audio. This is not the case for the core blocks, but something that we might need to consider for 3rd party development.
|
I wonder how this relates with the idea of block attributes being the same thing as "dataviews field API" and also the same thing conceptually as JSON Schema. How do images get represented in JSON Schema is something we should be looking at. Maybe it's a type (current approach in DataViews), maybe it's something else. There's some consolidation to think about it here. |
|
Interesting exploration. Enforcing some structure for content attributes is becoming more critical as we scale the block editor capabilities. @ockham did a bit of different but related research on how to map an image object properties to the Image block or Featured Image block attributes through Pattern Overrides or other forms of Block Bindings to support native functions like get_the_post_thumbnail_url or custom post meta: My only comment is that this proposal is very specific to a small number of blocks, so it's worth considering generalizing it to content where |
@youknowriad can you elaborate a bit on these? |
|
This is a cool exploration, useful regardless of outcome. You got me thinking about a couple of things: the possible overuse of If, like me, you're curious about what roles are currently used in the core block library: fig.: all attributes with a set role{
"core/accordion-heading": {
"title": "content"
},
"core/audio": {
"blob": "local",
"src": "content",
"caption": "content",
"id": "content"
},
"core/button": {
"url": "content",
"title": "content",
"text": "content",
"linkTarget": "content",
"rel": "content"
},
"core/categories": {
"label": "content"
},
"core/code": {
"content": "content"
},
"core/cover": {
"url": "content"
},
"core/details": {
"summary": "content"
},
"core/embed": {
"url": "content",
"caption": "content",
"type": "content",
"providerNameSlug": "content",
"responsive": "content",
"previewable": "content"
},
"core/file": {
"blob": "local",
"href": "content",
"fileName": "content",
"textLinkHref": "content",
"downloadButtonText": "content"
},
"core/form-input": {
"label": "content",
"placeholder": "content"
},
"core/gallery": {
"caption": "content"
},
"core/heading": {
"content": "content"
},
"core/home-link": {
"label": "content"
},
"core/html": {
"content": "content"
},
"core/image": {
"blob": "local",
"url": "content",
"alt": "content",
"caption": "content",
"title": "content",
"href": "content",
"id": "content"
},
"core/list-item": {
"content": "content"
},
"core/list": {
"ordered": "content",
"values": "content"
},
"core/math": {
"latex": "content"
},
"core/media-text": {
"mediaAlt": "content",
"mediaId": "content",
"mediaUrl": "content",
"href": "content",
"mediaType": "content"
},
"core/more": {
"customText": "content"
},
"core/navigation-link": {
"label": "content"
},
"core/navigation-submenu": {
"label": "content"
},
"core/paragraph": {
"content": "content"
},
"core/post-author-name": {
"isLink": "content",
"linkTarget": "content"
},
"core/post-author": {
"isLink": "content",
"linkTarget": "content"
},
"core/post-date": {
"datetime": "content",
"isLink": "content"
},
"core/post-excerpt": {
"moreText": "content"
},
"core/post-featured-image": {
"isLink": "content",
"rel": "content",
"linkTarget": "content"
},
"core/post-navigation-link": {
"label": "content"
},
"core/post-terms": {
"prefix": "content",
"suffix": "content"
},
"core/post-title": {
"isLink": "content",
"rel": "content",
"linkTarget": "content"
},
"core/preformatted": {
"content": "content"
},
"core/pullquote": {
"value": "content",
"citation": "content"
},
"core/quote": {
"value": "content",
"citation": "content"
},
"core/read-more": {
"content": "content"
},
"core/rss": {
"feedURL": "content"
},
"core/search": {
"label": "content",
"placeholder": "content",
"buttonText": "content"
},
"core/shortcode": {
"text": "content"
},
"core/site-logo": {
"isLink": "content",
"linkTarget": "content"
},
"core/site-title": {
"isLink": "content",
"linkTarget": "content"
},
"core/social-link": {
"url": "content",
"label": "content"
},
"core/table": {
"caption": "content"
},
"core/verse": {
"content": "content"
},
"core/video": {
"caption": "content",
"id": "content",
"blob": "local",
"src": "content",
"tracks": "content"
}
}src:
|
Thanks for the ping! I can't say for sure, but I'd wager such metadata would be useful, for example, to target bespoke behaviour for various media blocks in content only mode. The first thing that comes to mind is editable fields. cc @talldan |
This distinction is central to contentOnly mode, because the attributes that have the I'm not sure a |
It's still quite an early draft, but agree it could be helpful for that - I added some very similar 'mapping' code in the PR, which I planned to make optional, but this would hopefully allow me to remove that completely for media fields. Another use case might be related to an idea I had - being able to surface all the 'attachments' that are used within a post. One thing I'll mention is that the So I wonder if this can be made more general to map any kind of entity or resource. That way it could allow for discovering any kind of entity usage within block content and support parsing values. It might contribute to solving this - Tracking and providing insights about consumption of global elements, and also be useful for things like preloading entities. |
@talldan can you expand a bit on this? What kind of config would be useful to handle the wp/block to pattern post types for example? |
Something like this to indicate that the resources: {
block: { id: 'ref' } // maps to `postType/block` resource
}
getBlockResource( 'block' ) // { id: 12 }
getBlockResource( 'attachment' ) // { id: 32, src: 'https://example.com/cover.png', mediaType: 'image' }Though I'm not sure the more I think on it, this is quite different to what others are discussing and maybe it's not the right use case to solve with this API. What has been mentioned in other comments is the config is more related to dataview fields. So I think it's similar to what I'm working on in #71730. In that PR I'm trying to generate a 'form' (I plan to make it a DataForm at some point) for editing blocks in the inspector. At the moment it's only concerned with content attributes, and across our core blocks that's really only Text, Links and Media field types. Link and Media are the two that have very inconsistent attribute definitions so need some kind of mapping. I think for your use case in List View, you could possibly render a 'read only' version of a media field. |
|
I shared here what I think about the connection of this PR with the
So, to answer @youknowriad's question, I don't think the semantic info we want should be part of type or format. We could have conventions/mappers about the roles to match a specific type (mediaAlt->string), but probably that would be it. So maybe this exploration, expanded to support more things other than media roles, with some kind of mapping with |
|
Sorry for the delay in responding @ntsekouras, I had some AFK and missed the ping. I think it's pretty difficult to predict right now what's going to happen as there's a lot of work happening in parallel. I would say what's known is that there's going to be a way in the near future to map block attributes to dataviews fields. There is already a rudimentary API that's being explored as part of the Whether that's enough to satisfy your use case, I'm not sure. I think there will be a way to associate attributes with their purpose for a @oandregal is the fields expert, so might be able to help with interpretation. 😄 TBH, the proposals feel quite closely associated, so maybe it's worth waiting to see how the block fields develop. |
|
Just noting, for the purposes of traceability, that this work is also very related to #73845. |
What?
An exploration related to: #65186 and #70714.
I spent some time exploring the above issues that are about adding some semantic info in media blocks that could potentially normalize some behaviors across blocks, that right now have very specific handling per block.
I didn't want to spend much time for it and start some discussions about whether such an API could be valuable and worths the effort.
Initially the obvious use cases for me that can use this, are the cases handled in this POC:
Groupor more images inCover, if they have more images nested. Is this something we would want though design wise? 🤔 This opens of course the opportunity to show images from 3rd party blocks too.post publish paneleven from 3rd party blocks that use the API.Possible use cases without exploring them
Image,VideoandAudioblocks`.useOnBlockDropto create a gallery withcore/imagehardcoded checks.Current suggestion rationale and alternatives
Media blocks would need to identify at least these roles:
url,id(persisted data),alt(for images) andtype(image|video|audio).typeis an important part because different media types have different tags and handling.Approaches that I considered
roleprop of block attributes, but many of them already have thecontentrole applied. We could consider media roles as content, but not being explicit can lead to bugs and unwanted behaviors. Another alternative is to makerolealso accept and array of roles (ex['content', 'mediaId']). It's doable but didn't chose this for start because it feels to me right now thatcontenthas been overused for content only editing and might entangle things more. That is a concern I already have and it's worth discussing on its own, although I don't have a clear way forward to solve this.. Another main obstacle for this approach or even having a new prop in block attributes likemediaRoleis that block need to define theirtypemedia role but don't have such an attribute. Adding a new attribute in blocks just for this doesn't seem like a good approach.Current suggestion
I ended up trying this with a new top level
mediaRolesprop in block config. I'm not sure about the name either since this prop is a map of the media roles to each block's related attributes. This solves thetypemedia role for blocks without adding any new attributes.Questions
--cc @WordPress/gutenberg-core @youknowriad @mcsf @Mamaduka @mtias
Screenshots
List view
Screen.Recording.2025-10-30.at.8.20.49.AM.mov