Open swissspidy opened 9 months ago
I think it's a long (possibly painful) story why it's implemented this way.
@scruffian might be able to tell you more.
This is what I did at first but then we moved it back: https://github.com/WordPress/gutenberg/pull/57979
See also: https://core.trac.wordpress.org/ticket/59867#comment:4 https://github.com/WordPress/gutenberg/pull/58429
In summary, there are several competing wishes...
On the one hand we want to put code into private functions inside classes so that they can't be used elsewhere in WordPress which would give us a larger surface to maintain with respect to backwards compatibility. Static classes are a good way to achieve this.
On the other hand, at the moment all the PHP rendering code for blocks lives in the block library package, and is back-ported automatically. We are reluctant to start moving block specific code outside of this package.
An ideal solution would allow us to keep all the PHP code inside the block-library package, and also to find a mechanism to keep functions clearly namespaced and not exposed globally for everyone to use. PHP namespaces could be an alternative to a static class.
I‘m not suggesting to move this class out of the package, just into a separate file next to index.php. That doesn‘t change anything about the API surface at all.
I think that would be great but it involves making some changes to the way that the PHP files are built for the block library package. Hopefully someone is able to work on that soon!
Core requires class definitions to be in their own file.
The
WP_Navigation_Block_Renderer
class should be moved out ofpackages/block-library/src/navigation/index.php
to its own file,packages/block-library/src/navigation/class-wp-navigation-block-renderer.php
Besides: why is the class not prefixed anyway? I thought Gutenberg fixed class and function prefixes during the build process.