-
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
Open up "Pattern Overrides" and therefore intern block bindings to custom dynamic blocks #64870
Comments
CC: @gziolo @SantosGuillamot since you participated in the conversation in slack :) Would love to get your take on whether I captured things correctly here and to fill in all the nuances that I am missing |
Also pinging the outreach group @WordPress/outreach to chime in especially on use cases adn further thoughts |
I can chime in and provide some use case examples also :) First of all, pretty much all blocks we built on custom sites are dynamic block. The reason for this is mostly due to design flexibility with continually changing design requirements. Some examples of these custom blocks we have on pretty much every project:
It would be great be to able to use that inside a synced pattern and enable overrides so that the user can still change the actual icon that should be used whilst all the design options of how large, what color, etc the icon is are still synced. The end goal that would the make this feature soooooo much more powerful is to allow for all of this in Synced Theme Patterns (#59272) |
I can certainly see how this would be useful. Having the allowed blocks hard-coded is not ideal. I am confused by
I thought the HTML API was stable and released back in WP 6.2? 😕 |
That was HTML Tag Processor in WP 6.2. We are talking about HTML Processor and two features it will allow to support - gutenberg/packages/block-library/src/image/block.json Lines 50 to 56 in 07c7821
Which would be equivalent to JavaScript: document.querySelector( 'figure > a' ).href = 'new value'; gutenberg/packages/block-library/src/image/block.json Lines 31 to 36 in 07c7821
Which would be equivalent to JavaScript: document.querySelector( 'figcaption' ).innerHTML = '<strong>new value</strong>'; |
One addendum on the point of I'd really like to focus on the semantics of the role and avoid introducing decorator flags like "bindable". The ideal state of this setup is that the role of an attribute signals everything necessary for augmentation. This will be an important aspect of multilingual as well. The attributes designated as "content" would be the immediate candidates for localization. The more this is architected around the topology of the role itself and less about operational flags the more it simplifies adoption and the overall clarity for extenders. It's a do more with less kind of thing. |
@mtias thank you for chiming in here. I’m not sure I understand how the full spectrum of which fields should be bindable etc, which should be translatable etc can be accomplished by one single content role. As an example, we have an icon block that stores a slug of a selected icon as an attribute. This attribute should still be changeable by a user when inside a content only locked section or a pattern override. However it is not something that should get translated. So at least for that stage I personally believe that we will need some kind of operators to opt out of things like translatable for example. And the same goes for transforms. I’m not sure how just having content as an available role is enough. Using this same example of the icon block. If that slug is marked as content because its the only way to make it bindable, then swapping the pattern it it in could result in that slug now becoming a heading / paragraph of some kind… so if we want to make all this derived I think the we at least need more different kinds of roles. Maybe even a way to register custom roles / manage what properties are derived for each role. |
Thank you for the clarification, @mtias.
I'm in favor of providing a good default where
I think it also does some magic with patterns. I don't remember what exactly, though 😅
That sounds like an interesting path to explore that would remove the need to introduce multiple boolean flags in the attribute's schema. It's worth highlighting, there is also |
Just wanted to echo @fabiankaegy's comments above. I experimented with making my own icon block editable when contentOnly is enabled. The code is here. Whatever the final outcome is, I plan to cover this on the Developer Blog (WordPress/developer-blog-content#303). |
I see that @getdave is working on making the Great timing. I’ll see if we can connect that change with ensuring it’s used as an indicator for Block Bindings based on the conditions discussed in this issue. @talldan, does Pattern Overrides use the role |
At the moment the pattern block uses |
@talldan But under the hood |
Yep! Apart from the List Block, which has some special logic that needs to be reviewed. |
@fabiankaegy Yes it does:
|
This issue is coming out of a discussion in the Make WordPress Slack Outreach Channel where we discussed some of the reasons why we are not ready to adopt pattern overrides on custom build projects.
Currently, pattern overrides is limited to only a small set of core blocks that have handling for their block bindings HTML replacement handled manually. With that, we have opted not to expose the mechanisms to create blocks that make use of the Pattern Overrides feature publicly until the HTML API lands in core.
However, we just realized that this limitation to wait on the HTML API only really applies to static blocks (ones that serialize their HTML to the database). For dynamic blocks (block rendered via a
render_callback
in PHP) this limitation does not exist.Because of that I would propose that we open up the block bindings / pattern overrides feature for custom blocks that use dynamic rendering.
How to achieve that:
First we would need to find a way to indicate which attributes of which blocks actually allow to be bound to something. Currently, this is managed in a hard-coded list. #64756 explores adding a
bindable
decorator to the attributes definition which could be used to get that list dynamically.Once we know which attributes of which blocks support bindings, we would need to also use that to handle saving attributes / passing in the correct value of attributes correctly in the editor.
And finally, we can use that same
bindable
key to replace https://github.com/WordPress/wordpress-develop/blob/e569967ee45e23186f6aa7f479fcb48a7511436b/src/wp-includes/class-wp-block.php#L246-L251 with the dynamic lookup of supported bindings.The text was updated successfully, but these errors were encountered: