diff --git a/plugins/woocommerce-blocks/assets/js/blocks/legacy-template/index.tsx b/plugins/woocommerce-blocks/assets/js/blocks/legacy-template/index.tsx new file mode 100644 index 00000000000..97539c8ae37 --- /dev/null +++ b/plugins/woocommerce-blocks/assets/js/blocks/legacy-template/index.tsx @@ -0,0 +1,71 @@ +/** + * External dependencies + */ +import { registerExperimentalBlockType } from '@woocommerce/block-settings'; +import { useBlockProps } from '@wordpress/block-editor'; +import { Placeholder } from '@wordpress/components'; +import { __, sprintf } from '@wordpress/i18n'; + +interface Props { + attributes: { + template: string; + }; +} + +const Edit = ( { attributes }: Props ) => { + const blockProps = useBlockProps(); + return ( +
+ +
+ ); +}; + +registerExperimentalBlockType( 'woocommerce/legacy-template', { + title: __( 'WooCommerce Legacy Template', 'woo-gutenberg-products-block' ), + category: 'woocommerce', + apiVersion: 2, + keywords: [ __( 'WooCommerce', 'woo-gutenberg-products-block' ) ], + description: __( + 'Renders legacy WooCommerce PHP templates.', + 'woo-gutenberg-products-block' + ), + supports: { + align: false, + html: false, + multiple: false, + reusable: false, + inserter: false, + }, + example: { + attributes: { + isPreview: true, + }, + }, + attributes: { + /** + * Template attribute is used to determine which core PHP template gets rendered. + */ + template: { + type: 'string', + default: 'any', + }, + lock: { + type: 'object', + default: { + remove: true, + }, + }, + }, + edit: Edit, + save: () => null, +} ); diff --git a/plugins/woocommerce-blocks/bin/webpack-entries.js b/plugins/woocommerce-blocks/bin/webpack-entries.js index 8ed530d7043..d6c69e35110 100644 --- a/plugins/woocommerce-blocks/bin/webpack-entries.js +++ b/plugins/woocommerce-blocks/bin/webpack-entries.js @@ -53,6 +53,7 @@ const blocks = { 'single-product': { isExperimental: true, }, + 'legacy-template': {}, }; // Returns the entries for each block given a relative path (ie: `index.js`, diff --git a/plugins/woocommerce-blocks/src/BlockTypes/AbstractBlock.php b/plugins/woocommerce-blocks/src/BlockTypes/AbstractBlock.php index 2ef3c90824c..f8dc6a77fd7 100644 --- a/plugins/woocommerce-blocks/src/BlockTypes/AbstractBlock.php +++ b/plugins/woocommerce-blocks/src/BlockTypes/AbstractBlock.php @@ -176,16 +176,22 @@ abstract class AbstractBlock { * Registers the block type with WordPress. */ protected function register_block_type() { + $block_settings = [ + 'render_callback' => $this->get_block_type_render_callback(), + 'editor_script' => $this->get_block_type_editor_script( 'handle' ), + 'editor_style' => $this->get_block_type_editor_style(), + 'style' => $this->get_block_type_style(), + 'attributes' => $this->get_block_type_attributes(), + 'supports' => $this->get_block_type_supports(), + ]; + + if ( isset( $this->api_version ) && '2' === $this->api_version ) { + $block_settings['api_version'] = 2; + } + register_block_type( $this->get_block_type(), - array( - 'render_callback' => $this->get_block_type_render_callback(), - 'editor_script' => $this->get_block_type_editor_script( 'handle' ), - 'editor_style' => $this->get_block_type_editor_style(), - 'style' => $this->get_block_type_style(), - 'attributes' => $this->get_block_type_attributes(), - 'supports' => $this->get_block_type_supports(), - ) + $block_settings ); } diff --git a/plugins/woocommerce-blocks/src/BlockTypes/LegacyTemplate.php b/plugins/woocommerce-blocks/src/BlockTypes/LegacyTemplate.php new file mode 100644 index 00000000000..4b2029897ff --- /dev/null +++ b/plugins/woocommerce-blocks/src/BlockTypes/LegacyTemplate.php @@ -0,0 +1,62 @@ +render_single_product(); + } else { + ob_start(); + + echo "You're using the LegacyTemplate block"; + + wp_reset_postdata(); + return ob_get_clean(); + } + } + + /** + * Render method for the single product template and parts. + * + * @return string Rendered block type output. + */ + protected function render_single_product() { + ob_start(); + + echo 'This method will render the single product template'; + + wp_reset_postdata(); + return ob_get_clean(); + } +} diff --git a/plugins/woocommerce-blocks/src/BlockTypesController.php b/plugins/woocommerce-blocks/src/BlockTypesController.php index 1ae5757ddca..d36c9d4cb4c 100644 --- a/plugins/woocommerce-blocks/src/BlockTypesController.php +++ b/plugins/woocommerce-blocks/src/BlockTypesController.php @@ -174,6 +174,7 @@ final class BlockTypesController { 'AttributeFilter', 'StockFilter', 'ActiveFilters', + 'LegacyTemplate', ]; if ( Package::feature()->is_feature_plugin_build() ) {