-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Block Bindings: Try using __default for generic bindings
#71002
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
|
The next question to answer will be how the source (i.e. |
|
Size Change: -24 B (0%) Total Size: 1.91 MB
ℹ️ View Unchanged
|
|
One thing to consider would be e.g. how the Featured Image block currently fetches a post's featured image, and how it maps the latter's properties to its attributes -- especially considering that in the long run, it should be possible to express the Featured Image block as an Image block bound to the |
The Featured Image block is dynamic, so everything is handled with the gutenberg/packages/block-library/src/cover/index.php Lines 48 to 64 in 4171f27
|
When connecting the |
Yeah, that's the big question here. As we discussed on our call, there's no one-size-fits-all mapper; e.g. while the image-related attributes are called This means that the mappers are still fully determined by the block type. This would probably allow us to make Block Bindings smart enough to make the The individual attribute mappings -- which I had originally suggested to read {
"alt":{"src":"core/post-data","args":{"key":"featuredMedia"}},
"id":{"src":"core/post-data","args":{"key":"featuredMedia"}},
"title":{"src":"core/post-data","args":{"key":"featuredMedia"}},
"url":{"src":"core/post-data","args":{"key":"featuredMedia"}}
}should however probably expose the attribute that's actually mapped; otherwise, there's to much magic going on. So maybe {
"__default":{"src":"core/post-data","args":{"key":"featuredMedia"}}
}should expand to {
"alt":{"src":"core/post-data","args":{"key":"featuredMedia.alt_text"}},
"id":{"src":"core/post-data","args":{"key":"featuredMedia.id"}},
"title":{"src":"core/post-data","args":{"key":"featuredMedia.title"}},
"url":{"src":"core/post-data","args":{"key":"featuredMedia. source_url"}}
}in case of the {
"mediaAlt":{"src":"core/post-data","args":{"key":"featuredMedia.alt_text"}},
"mediaId":{"src":"core/post-data","args":{"key":"featuredMedia.id"}},
"mediaUrl":{"src":"core/post-data","args":{"key":"featuredMedia. source_url"}}
}in case of (I still want to tweak the |
__default for generic bindings
bf4b0bf to
26a519b
Compare
|
Another loose thought: JavaScript's object destructuring syntax could serve as inspiration for getting multiple "fields" from a source, and mapping the values to different block attribute names. const { alt_text: alt, id, title: { rendered: title }, source_url: url } = featuredMedia;Though I'm of course not sure how to best express this in JSON and within the existing framework of block bindings syntax 🤔 So it's probably more for inspiration. Edit: The most "direct" translation of the left-hand side into JSON would probably be {
"alt_text": "alt",
"id": "id",
"title": { "rendered": "title" },
"source_url": "url"
} |
|
One possible way of using this way of defining a mapper could be by specifying it as a separate property: {
"__default":{
"src":"core/post-data",
"args":{
"key":"featuredMedia"
},
"map":{
"alt_text": "alt",
"id": "id",
"title": { "rendered": "title" },
"source_url": "url"
}
}
} |
|
(The reason why I wouldn't include it in |
|
In particular, for |
|
I'm still debating if the above format should transform into {
"alt":{"src":"core/post-data","args":{"key":"featuredMedia.alt_text"}},
"id":{"src":"core/post-data","args":{"key":"featuredMedia.id"}},
"title":{"src":"core/post-data","args":{"key":"featuredMedia.title.rendered"}},
"url":{"src":"core/post-data","args":{"key":"featuredMedia.source_url"}}
}or into something different 🤔 |
|
The problem is that sources are pretty much free in what |
|
Jotting down some more thoughts on this.
|

What?
Experiment, based on some internal discussions with @cbravobernal and @gziolo.
Extend the mechanism that currently maps the
__defaultblock binding for pattern overrides to any kind of block binding. In other words, if an image block (whose supported attributes areid,url,title, andalt) has block bindings as follows:{ "__default":{"src":"core/post-data","args":{"key":"featuredMedia"}} }they are expanded into
{ "alt":{"src":"core/post-data","args":{"key":"featuredMedia"}}, "id":{"src":"core/post-data","args":{"key":"featuredMedia"}}, "title":{"src":"core/post-data","args":{"key":"featuredMedia"}}, "url":{"src":"core/post-data","args":{"key":"featuredMedia"}} }Why?
To explore a straightforward way and syntax of binding a block to a non-primitive source object (e.g. an image).
How?
TBD
Testing Instructions
TBD