-
Notifications
You must be signed in to change notification settings - Fork 219
BlockTemplateController: adds the ability to load and manage block template files #4981
Conversation
Size Change: 0 B Total Size: 1.24 MB ℹ️ View Unchanged
|
src/BlockTemplatesController.php
Outdated
$template_files = $this->get_block_templates(); | ||
|
||
foreach ( $template_files as $template_file ) { | ||
$query_result[] = _gutenberg_build_template_result_from_file( $template_file, 'wp_template' ); |
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.
What is the significance of the function starting with an underscore (_
) here?
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 wonder the same. I would assume that means the function shouldn't be considered public. 🤔 Could we check with somebody from the Gutenberg project about this (via Slack or in their repo)?
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.
@tjcafferkey pinged me for info here but unfortunately I don't know the answer either.
I would ask in the #core-editor
channel in Core slack.
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.
Just surfacing the reasoning:
The _
prefix means the function it shouldn't be used publicly and can change at any time. Because of this I've duplicated the functions into this repo and will kick off a discussion around this to understand what is needed, and if they can become available for public usage.
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 is working as expected and code looks great. I left some inline comments below, but overall it's looking good.
Regarding the usage of functions prepended by an underscore, I agree we should investigate what that means and whether it's safe to use them in our repo or there are chances they will break in the future.
src/BlockTemplatesController.php
Outdated
$template_files = $this->get_block_templates(); | ||
|
||
foreach ( $template_files as $template_file ) { | ||
$query_result[] = _gutenberg_build_template_result_from_file( $template_file, 'wp_template' ); |
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 wonder the same. I would assume that means the function shouldn't be considered public. 🤔 Could we check with somebody from the Gutenberg project about this (via Slack or in their repo)?
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.
LGTM, I left one last comment, but besides that, this is good to go.
* BlockTemplateController * Check if theme already has template * ThemeUtils file to check for FSE enabled themes * Use Gutenberg global gutenberg_supports_block_templates * Remove ThemeUtils reference * Update with code review comments * Delete ThemeUtils and move supports_block_templates check * Duplicate functions from Gutenberg into Utils file * Remove template file * Check template directory and stylesheet directory for template
* BlockTemplateController * Check if theme already has template * ThemeUtils file to check for FSE enabled themes * Use Gutenberg global gutenberg_supports_block_templates * Remove ThemeUtils reference * Update with code review comments * Delete ThemeUtils and move supports_block_templates check * Duplicate functions from Gutenberg into Utils file * Remove template file * Check template directory and stylesheet directory for template
Added
BlockTemplateController
which will give us the ability to load default block templates in the future. In this specific PR the class is checking if they exist in the theme before loading them from Woo Blockstemplates/block-templates/
directory.Fixes #4969
Testing
Automated Tests
Manual Testing
How to test the changes in this Pull Request:
/theme-dir/block-templates/single-product.html
/woo-blocks/templates/block-templates/single-product.html
Changelog