-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[WIP] Blocks: Explore how we could divide server and client block properties #5652
Conversation
* @since 2.5.0 | ||
* @var string | ||
*/ | ||
public $icon; |
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.
This probably should stay on the client as it is UI related.
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.
IS this path to file or the SVG itself? If it's path to file, I think it's easier if it's done in PHP.
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.
I will have to double check, but I believe you can provide JSX there.
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.
It's just the name of the Dashicon to use.
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.
In core we use Dashicons, but it also works with SVG components, see https://github.com/WordPress/gutenberg/blob/master/blocks/block-icon/index.js.
Replying to @gziolo -
What if the code missing was a custom capability/ authorization check?
Attribute default values also may need to be translated. Not sure what to do about that, as I love this idea of registering with JSON. |
Can you explain the motivation for wanting a JSON file in the first place? Block discovery sounds nice, but I have no reason to think this would be intuitive for a developer; or, at least, no more intuitive than simply registering a block in PHP. Introducing a third file to help deal with our concerns over two files is perhaps flawed, even before considering drawbacks such as inability to localize text (or other dynamic content trivial to accomplish in PHP). I agree with the general concern that registering a block twice is not sensible. The current behavior is such that registering on the client extends settings which are provided from the server. As noted in the original comment, perhaps we need to be more explicit that this is an extension of settings ( |
I assumed that having JSON file will allow providing auto-discovery for both JS and PHP codebases in a sense that we wouldn't have to call those register methods explicitly. Another reasoning was that it is going to be possible to load this data directly without exposing them in HTML code. It seems like it is isn't possible because to satisfy a few different requirements we should expose a hook on PHP side to make it possible to perform some operations on Having said that, I'm closing this PR with a plan to open a follow-up PR later this week, where I will propose an alternative solution that is going to do the following after the transition period:
Thanks for all your feedback. I will let you know when I have something working. |
@gziolo This make sense. I have onequestion about your proposed path forward. If I register a block server-side how do I make it so only I can modify it with I think it would be great if your answer was the second option. That gives us one single way to create or extend these block features. But, merging attributes or callback functions is complicated and sounds like we might need a priority system like we have with hooks. |
We need to see how it goes. I think that at least |
Description
Related to #2751.
In this PR I tried to explore one of the possible ways of having block registration moved server side. At the moment it is quite confusing that you need to register your dynamic block on both the server and client. It is more intuitive for static blocks, as everything happens on the client, but it introduces other limitations as we don't have access to the internals of WordPress. Examples:
supports
flag, but it is not clear how to handle the case where you need to expose the same attribute on the server for the render callback. It would require making sure that the same hook is executed on both server and client.The general idea behind this PR is to split which attributes are declared on the server and keep the rest on the client. As discussed on Slack, we might want to rename the function on the client to reflect the fact that the server registers the block, but on the client, we only add the missing parts which are JS based and UI specific like
edit
,save
oricon
(SVG involved here).This is what I explored in this PR:
register_block_type
. It happens behind the scenes.registerBlockType
to a different name which better reflects what happens.Issues discovered:
title
ordescription
located in the JSON file it seems to be not possible as they can't be wrapped with translation functions this way.How Has This Been Tested?
TBD
Types of changes
Technical exploration.
Checklist: