Conversation
| */ | ||
| function register_block_core_navigation_menu() { | ||
|
|
||
| function register_block_core_navigation() { |
There was a problem hiding this comment.
Not sure why this can't be prefixed with gutenberg_?
There was a problem hiding this comment.
They are prefixed, but not in the source. The prefix is added at build time:
https://github.com/WordPress/gutenberg/blob/6fc0b70/webpack.config.js#L129-L139
You can see this in the build output:
It's done this way because core copies these files directly from Gutenberg:
https://github.com/WordPress/wordpress-develop/blob/4ebaf2b/tools/webpack/packages.js#L96-L108
Since Gutenberg needs to replace / augment the implementation of core blocks, and in order to avoid redeclaring the function, a prefix is added automatically.
As far as what I was suggesting with my comments in the previous pull request, we should write the source as though we expect these functions to exist one day in core, and as such consider whether build_css_colors is named specific enough given that it's used only by this one block (and not a generalized utility for building CSS colors).
There was a problem hiding this comment.
I did not know that Gutenberg would do that. In that case the prefix should probably change to something like block_{blockname}_*
draganescu
left a comment
There was a problem hiding this comment.
This works OK after the refactor of the function names. Will need to be rebased if #18607 is merged in first.
|
Is this just waiting on something to merge? |
|
d98437c to
32c5bc4
Compare
aduth
left a comment
There was a problem hiding this comment.
I should have been clearer in my comment at #18589 (comment), but: We do not want any Gutenberg-specific prefixes here, because this code will be used verbatim as the core implementation. But, as such, for functions which are being added to the global PHP scope, they should be named in such a way that they are unique and sensible in the context of WordPress, because they will effectively become part of the WordPress public API.
Some prior art:
So for something like build_css_colors, naming it in a way which makes it clearer that it's intended to be used specifically as a utility function for the navigation block (if it can't otherwise be made into a generic utility). Something like get_navigation_block_css_colors.
It could also be something worth considering to mark as an @access private internal function. I'm not really sure the guidelines around this, but considering that these functions don't really have value outside their use by the block itself, it would seem to make sense to me.
|
@obenland Plans for this PR? |
|
That's a good question. In an ideal world I'd introduce a
That tells me we should prefix them with Is the solution to introduce a new |
For context, I'm not really familiar if one of the original goals with this block was that it not depend on anything with how WordPress deals with menus, etc. But at the point a block includes a PHP file, it seems to me there's a pretty high expectation about where that block is going to be able to run (namely, WordPress). And if it doesn't require any WordPress functions, is it even dynamic? And if it's not dynamic, then why does the PHP file exist at all (vs. saving static markup from the block's To me, the agnosticism is more about removing biases about how we tend to think of content, avoiding unnecessary dependencies, and maximizing reusability. I also think that as long as we treat block types as individual units, these decisions and compromises can be made on a block-by-block basis. Maybe it's fine this block depends on WordPress, and another implementation of a Navigation block could work entirely differently. Back to the original question:
So it would be okay enough I think. There might be better alternatives. Even in the context of WordPress core code, I tend to see the Consider as well the name and structure of the Navigation block registration function: There could be something of a pattern here around So something like:
Maybe not the most expressive, but they at least align to a consistent pattern to follow. The prior art is a bit all over the place, to be honest. |
|
Appears that this was handled separately in #20039. |
Description
Adds
gutenberg_prefix to navigation block functions.These functions will get merged to Core verbatim, so let's make sure functions like
build_css_colors()don't clash.For some reason Gutenberg doesn't recognize registration callback function names that don't start with
register_block_?!How has this been tested?
Loaded a navigation block in editor and frontend on a local install and made sure it doesn't cause errors.
Checklist: