From 92d5129b90e7ba4e15cf90339ea2ba1eb69a7f20 Mon Sep 17 00:00:00 2001 From: Lucio Giannotta Date: Mon, 27 Dec 2021 18:20:42 +0100 Subject: [PATCH] Align Woo Block template locations with the newest convention While we now support both the old and new conventions for the templates paths, our own repo should be aligned with the latest convention. See: #5455 Fixes: #5343 --- src/BlockTemplatesController.php | 19 +++++++------------ src/Utils/BlockTemplateUtils.php | 7 ------- .../mini-cart.html | 0 .../archive-product.html | 0 .../single-product.html | 0 .../taxonomy-product_cat.html | 0 .../taxonomy-product_tag.html | 0 7 files changed, 7 insertions(+), 19 deletions(-) rename templates/{block-templates-parts => parts}/mini-cart.html (100%) rename templates/{block-template => templates}/archive-product.html (100%) rename templates/{block-template => templates}/single-product.html (100%) rename templates/{block-template => templates}/taxonomy-product_cat.html (100%) rename templates/{block-template => templates}/taxonomy-product_tag.html (100%) diff --git a/src/BlockTemplatesController.php b/src/BlockTemplatesController.php index c8abf43ce5c..054a9577310 100644 --- a/src/BlockTemplatesController.php +++ b/src/BlockTemplatesController.php @@ -25,18 +25,11 @@ class BlockTemplatesController { private $template_parts_directory; /** - * Directory name of the block template directory. + * Directory which contains all templates * * @var string */ - const TEMPLATES_DIR_NAME = 'block-templates'; - - /** - * Directory name of the block template parts directory. - * - * @var string - */ - const TEMPLATE_PARTS_DIR_NAME = 'block-template-parts'; + const TEMPLATES_ROOT_DIR = 'templates'; /** * Constructor. @@ -44,8 +37,10 @@ class BlockTemplatesController { public function __construct() { // This feature is gated for WooCommerce versions 6.0.0 and above. if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '6.0.0', '>=' ) ) { - $this->templates_directory = plugin_dir_path( __DIR__ ) . 'templates/' . self::TEMPLATES_DIR_NAME; - $this->template_parts_directory = plugin_dir_path( __DIR__ ) . 'templates/' . self::TEMPLATE_PARTS_DIR_NAME; + $root_path = plugin_dir_path( __DIR__ ) . self::TEMPLATES_ROOT_DIR . DIRECTORY_SEPARATOR; + + $this->templates_directory = $root_path . BlockTemplateUtils::TEMPLATES_DIR_NAME; + $this->template_parts_directory = $root_path . BlockTemplateUtils::TEMPLATE_PARTS_DIR_NAME; $this->init(); } } @@ -343,7 +338,7 @@ function ( $template ) use ( $template_slug ) { // If the theme has an archive-product.html template, but not a taxonomy-product_cat.html template let's use the themes archive-product.html template. if ( BlockTemplateUtils::template_is_eligible_for_product_archive_fallback( $template_slug ) ) { - $template_file = get_stylesheet_directory() . '/' . self::TEMPLATES_DIR_NAME . '/archive-product.html'; + $template_file = BlockTemplateUtils::get_theme_template_path( 'archive-product' ); $templates[] = BlockTemplateUtils::create_new_block_template_object( $template_file, $template_type, $template_slug, true ); continue; } diff --git a/src/Utils/BlockTemplateUtils.php b/src/Utils/BlockTemplateUtils.php index 3ad4de3af45..786227f1402 100644 --- a/src/Utils/BlockTemplateUtils.php +++ b/src/Utils/BlockTemplateUtils.php @@ -6,13 +6,6 @@ * IMPORTANT: These methods have been duplicated from Gutenberg/lib/full-site-editing/block-templates.php as those functions are not for public usage. */ class BlockTemplateUtils { - /** - * Directory name of all the templates. - * - * @var string - */ - const TEMPLATES_ROOT_DIR = 'templates'; - /** * Old directory name of the block templates directory. * diff --git a/templates/block-templates-parts/mini-cart.html b/templates/parts/mini-cart.html similarity index 100% rename from templates/block-templates-parts/mini-cart.html rename to templates/parts/mini-cart.html diff --git a/templates/block-template/archive-product.html b/templates/templates/archive-product.html similarity index 100% rename from templates/block-template/archive-product.html rename to templates/templates/archive-product.html diff --git a/templates/block-template/single-product.html b/templates/templates/single-product.html similarity index 100% rename from templates/block-template/single-product.html rename to templates/templates/single-product.html diff --git a/templates/block-template/taxonomy-product_cat.html b/templates/templates/taxonomy-product_cat.html similarity index 100% rename from templates/block-template/taxonomy-product_cat.html rename to templates/templates/taxonomy-product_cat.html diff --git a/templates/block-template/taxonomy-product_tag.html b/templates/templates/taxonomy-product_tag.html similarity index 100% rename from templates/block-template/taxonomy-product_tag.html rename to templates/templates/taxonomy-product_tag.html