-
Notifications
You must be signed in to change notification settings - Fork 219
Fix reverting customisations by refactoring pre_get_block_file_template #5746
Conversation
Size Change: +364 B (0%) Total Size: 813 kB
ℹ️ View Unchanged
|
Noticed one little glitch, but not related to the changes here. If we revert multiple templates from the templates list we'll get multiple notifications/flash messages without any context when entering one of the pages creating more noise than providing information - esp. with toast notifications in bottom left. |
There is another glitch where the "Clear Customizations" is not present in the dropdown. But also not related to this change - It can happen when:
Going to templates lists and back fixes it and button is available again. Clear customisations on the templates list from the |
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.
Looks and works great.
The refactor was a great call and the BlockTemplatesController is much easier to follow now, highlights edge cases much better and is better aligned with how Gutenberg handles the get_block_file_template flow.
With handling for deprecated slugs and template fallbacks don't think there is anything else there to add 🎉
Confirmed the "Clear customisations" to be on our templates only apparently as per updated comment above - so there is something extra there. Could you evaluate the glitches we've seen and create follow up issues where it makes sense? 🙇
Thank you for the thorough testing and feedback on this PR @tomasztunik and @frontdevde !
Yep, having looked at the issues you've raised I believe these should be logged in the Gutenberg repo as issues, I'll add it to be to do list to do this. Thanks for the detailed descriptions and highlighting these. |
Fixes #5704
Description
pre_get_block_file_template
in BlockTemplateController.gutenberg_
prefix fromgutenberg_create_new_block_template_object
as it's confusing and unncessary.get_single_block_template
as it's no longer being used.woocommerce
into a const value alongside the correct one.trunk
and the latest version of WooCommerce (6.2 at the time of writing)Context
There are two methods used to get block templates in Gutenberg, they are
get_block_template
andget_block_file_template
.get_block_template
- Will query the database for a customised post, and if one does not exist it will then callget_block_file_template
get_block_file_template
- Will load the template from the themes file system and return aWP_Template
object.When we revert a template, we pass specific query params with the request which lands us here calling the
get_block_file_template
. This will ultimately fail because of this check as$theme
for our template iswoocommerce/woocommerce
which does not equalwp_get_theme()->get_stylesheet()
which would be the active themes id (e.g.twentytwentytwo
). This was happening because we were using cores method recursively on itself (but removing hooks so we didn't end up with an infinite loop), and core does not currently account for templates being loaded from plugins like WooCommerce, only themes. So we needed to refactor this.With all of the above in mind we can conclude that
pre_get_block_file_template
filter only runs when its retrieving the original block template fileWP_Template
object from the filesystem (withinget_block_file_template
). Knowing this I have refactored the callback to only do this for our block templates, but to also consider the edge case of a theme having aproduct-archive.html
template file only, which would also be used for Product Category and Tag templates.Testing
Automated Tests
Manual Testing
How to test the changes in this Pull Request:
single-product.html
) into your theme or download and install this version of TwentyTwentyTwo and test steps 1-10 again.Please also do some regression testing of your own around the feature with and without WooCommerce templates within the theme as this is a significant refactor to fix this bug and we don't have the luxury of a test suite as of yet.
Video of testing steps
revert-customizations-fix.mp4
User Facing Testing
These are steps for user testing (where "user" is someone interacting with this change that is not editing any code).
Changelog