-
Notifications
You must be signed in to change notification settings - Fork 219
All Products block: Migrate to block.json #6754
Conversation
The release ZIP for this PR is accessible via:
|
|
||
/** | ||
* Register and run the "All Products" block. | ||
*/ | ||
registerBlockType( 'woocommerce/all-products', { | ||
...blockSettings, | ||
/** | ||
* Deprecation rule to handle the previous default rows which was 1 instead of 3. | ||
*/ | ||
deprecated: [ | ||
{ | ||
attributes: Object.assign( {}, blockSettings.attributes, { | ||
rows: { type: 'number', default: 1 }, | ||
} ), | ||
save( { attributes } ) { | ||
const data = { | ||
'data-attributes': JSON.stringify( attributes ), | ||
}; | ||
return ( | ||
<div | ||
className={ getBlockClassName( | ||
'wc-block-all-products', | ||
attributes | ||
) } | ||
{ ...data } | ||
> | ||
<InnerBlocks.Content /> | ||
</div> | ||
); | ||
}, | ||
}, | ||
], | ||
} ); |
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 believe that this is no longer needed -- see PR description:
( [...] rely on server-side registration via
register_block_type_from_metadata
here) thanks to the existingAllProducts.php
file and class
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.
You still need to register client-specific settings with registerBlockType
. I don't think you need to export anything from this file. Depending on the lowest supported WP version you only need to call:
import metadata from './block.json';
registerBlockType( metadata.name, settings );
or
import metadata from './block.json';
registerBlockType( metadata, settings );
In case some settings aren't handled in older versions of WP.
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.
The release ZIP for this PR is accessible via:
|
Size Change: +179 B (0%) Total Size: 878 kB
ℹ️ View Unchanged
|
The release ZIP for this PR is accessible via:
|
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 left a comment about the block.json
file, the rest looks good to me 👌
28561d3
to
ae38915
Compare
Looking at the difference between "Content generated by |
I think the solution is to set Since we're not doing that (yet), the block parser mis-interprets this wrapping By setting the |
It seems that JS unit tests are still failing, but that seems unrelated: #6780. |
630deee
to
9c5c24c
Compare
I can't seem to merge this. Could someone else (with sufficient privileges) please do that on my behalf? 🙌 |
By-product of this experiment.
This shouldn't have any user-facing changes; it's merely a refactor to use
block.json
(and rely on server-side registration viaregister_block_type_from_metadata
here) thanks to the existingAllProducts.php
file and class).Testing
Verify that the "All Products" block still works as before, both in the editor and on the frontend.
Make sure that both existing instances of the block continue to work (and respect their attributes), and that newly inserting an "All Products" block also works.
Changelog
All Products block: Migrate to block.json