Manually init template registry and controller for non-block themes (#50507)

* Manually init template registry and cotnroller when get_query_template returns nothing

* Add changefile(s) from automation for the following project(s): woocommerce

* Validate template before including it

* Move class registration to init method

* Remove container registration from coming soon handler

* Lint

* Moved registration to register_dependencies

* Change blocks init condition to only when it's not initialized

---------

Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Adrian Duffell <9312929+adrianduffell@users.noreply.github.com>
Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com>
This commit is contained in:
Moon 2024-08-09 03:08:02 -07:00 committed by GitHub
parent 5047182efd
commit c406f1991e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 16 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Comment: Manually initialize block template registry and controller for non-block themes.

View File

@ -132,18 +132,6 @@ class Bootstrap {
$is_store_api_request = wc()->is_store_api_request(); $is_store_api_request = wc()->is_store_api_request();
if ( ! $is_store_api_request && ( wc_current_theme_is_fse_theme() || current_theme_supports( 'block-template-parts' ) ) ) { if ( ! $is_store_api_request && ( wc_current_theme_is_fse_theme() || current_theme_supports( 'block-template-parts' ) ) ) {
$this->container->register(
BlockTemplatesRegistry::class,
function () {
return new BlockTemplatesRegistry();
}
);
$this->container->register(
BlockTemplatesController::class,
function () {
return new BlockTemplatesController();
}
);
$this->container->get( BlockTemplatesRegistry::class )->init(); $this->container->get( BlockTemplatesRegistry::class )->init();
$this->container->get( BlockTemplatesController::class )->init(); $this->container->get( BlockTemplatesController::class )->init();
} }
@ -448,6 +436,18 @@ class Bootstrap {
return new QueryFilters(); return new QueryFilters();
} }
); );
$this->container->register(
BlockTemplatesRegistry::class,
function () {
return new BlockTemplatesRegistry();
}
);
$this->container->register(
BlockTemplatesController::class,
function () {
return new BlockTemplatesController();
}
);
} }
/** /**

View File

@ -2,6 +2,9 @@
namespace Automattic\WooCommerce\Internal\ComingSoon; namespace Automattic\WooCommerce\Internal\ComingSoon;
use Automattic\WooCommerce\Admin\Features\Features; use Automattic\WooCommerce\Admin\Features\Features;
use Automattic\WooCommerce\Blocks\BlockTemplatesController;
use Automattic\WooCommerce\Blocks\BlockTemplatesRegistry;
use Automattic\WooCommerce\Blocks\Package as BlocksPackage;
/** /**
* Handles the template_include hook to determine whether the current page needs * Handles the template_include hook to determine whether the current page needs
@ -48,13 +51,21 @@ class ComingSoonRequestHandler {
// A coming soon page needs to be displayed. Don't cache this response. // A coming soon page needs to be displayed. Don't cache this response.
nocache_headers(); nocache_headers();
$is_fse_theme = wc_current_theme_is_fse_theme();
$is_store_coming_soon = $this->coming_soon_helper->is_store_coming_soon();
if ( ! $is_fse_theme && ! current_theme_supports( 'block-template-parts' ) ) {
// Initialize block templates for use in classic theme.
BlocksPackage::init();
$container = BlocksPackage::container();
$container->get( BlockTemplatesRegistry::class )->init();
$container->get( BlockTemplatesController::class )->init();
}
add_theme_support( 'block-templates' ); add_theme_support( 'block-templates' );
$coming_soon_template = get_query_template( 'coming-soon' ); $coming_soon_template = get_query_template( 'coming-soon' );
$is_fse_theme = wc_current_theme_is_fse_theme();
$is_store_coming_soon = $this->coming_soon_helper->is_store_coming_soon();
if ( ! $is_fse_theme && $is_store_coming_soon ) { if ( ! $is_fse_theme && $is_store_coming_soon ) {
get_header(); get_header();
} }
@ -66,7 +77,9 @@ class ComingSoonRequestHandler {
} }
); );
if ( ! empty( $coming_soon_template ) && file_exists( $coming_soon_template ) ) {
include $coming_soon_template; include $coming_soon_template;
}
if ( ! $is_fse_theme && $is_store_coming_soon ) { if ( ! $is_fse_theme && $is_store_coming_soon ) {
get_footer(); get_footer();