-
Notifications
You must be signed in to change notification settings - Fork 219
Add a compatibility layer to keep extensions continue working with Blockified Archive Templates #8172
Conversation
The release ZIP for this PR is accessible via:
Script Dependencies ReportThe
This comment was automatically generated by the TypeScript Errors Report
🎉 🎉 This PR does not introduce new TS errors. |
Size Change: 0 B Total Size: 1.08 MB ℹ️ View Unchanged
|
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.
Direction is looking good. I just have a couple comments that impact mergeability.
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 looks great, @dinhtungdu! 👏 I left some comments inline but overall looking good.
), | ||
), | ||
'core/query-no-results' => array( | ||
'woocommerce_no_products_found' => array( |
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.
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.
Yeah, I noticed the same issue.
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 fixed this issue by checking the block content before injecting the hooks.
Great work, Tung! |
if ( empty( $block_content ) ) { | ||
return $block_content; | ||
} |
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.
Will this mean the woocommerce_no_products_found
won't fire?
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 makes the actions fire only when blocks return non-empty content. For the core/query-no-results
case, when the query has products, the block content will be empty, then woocommerce_no_products_found
shouldn't be fired.
But this will be false positive if we remove all inner blocks from core/query-no-results
. We need a second thought on this 🤔 .
* | ||
* @param array $hook_data Hook data. | ||
*/ | ||
return apply_filters( 'woocommerce_blocks_hooks_compatibility_data', $hook_data ); |
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 if we should preserve the original hook data instead of allowing it to be overwritten by the filter? that would reduce the ability for extensions to muck things up accidentally? It'd also mean the shape of the data can be validated before passing on to callers.
I'm on the fence about whether we should just provide a registration mechanism for these to make it easier for extensions to register additional items (especially given it'd be easy to mess up the array). What has me thinking to stick with the filter is the likelihood of it getting used much.
/** | ||
* Filter the hook data used to replace the default WooCommerce hooks. | ||
* | ||
* @param array $hook_data Hook data. | ||
*/ |
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.
Given the complexity of the hook data array, it'd be good to expand on the doc block a bit more about its shape.
In bccfa1a, I refactored the hook data structure to reduce the depth of the array as well as make it easier to manipulate the data inside the class. For the filter, I limited the data developer can pass to the filter to make it safer and easier to use. Instead of letting developer change the all hook data, now we only allow them to add new hooked functions to the supported hooks. Can you take another look at this @nerrad? Thank you. |
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.
Sorry for the back and forth but I have a couple more feedback pieces.
return; | ||
} | ||
|
||
foreach ( $additional_hook_data as $data ) { |
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.
Should make sure $additional_data
is an array before treating it as one here. Extensions could muck up the type so let's validate first.
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.
Should be fixed in 1cdcd5c.
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.
👍🏻 Code-wise things look good. I haven't tested.
Co-authored-by: Darren Ethier <[email protected]>
1cdcd5c
to
0765a73
Compare
I did a last round of testing and everything is looking good on my side. There are some e2e tests failing, but they are failing in |
Fixes #8065
This PR adds a new class that acts as the compatibility layer for blockified archive templates by:
The compatibility is building around Products block because loop is the main element of archive templates and hooks are placing inside and around the loop.
This PR skips these hooks:
woocommerce_show_page_title
woocommerce_archive_description
woocommerce_sidebar
Accessibility
prefers-reduced-motion
Other Checks
Testing
Automated Tests
User Facing Testing
composer dump-autoload
.Inherit query from template
.functions.php
file, add this snippet, then reload the shop page on the front end to see if the test content is displayed at the expected position:Repeat for other hooks:
woocommerce_before_main_content
woocommerce_after_main_content
woocommerce_before_shop_loop_item_title
woocommerce_shop_loop_item_title
woocommerce_after_shop_loop_item_title
woocommerce_before_shop_loop_item
woocommerce_after_shop_loop_item
woocommerce_before_shop_loop
woocommerce_after_shop_loop
woocommerce_no_products_found
WooCommerce Visibility
Performance Impact
Changelog