Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Add checkout-header template to the correct area in site editor #11528

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/Utils/BlockTemplateUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ public static function build_template_result_from_post( $post ) {

/**
* Build a unified template object based on a theme file.
* Important: This method is an almost identical duplicate from wp-includes/block-template-utils.php as it was not intended for public use. It has been modified to build templates from plugins rather than themes.
*
* @internal Important: This method is an almost identical duplicate from wp-includes/block-template-utils.php as it was not intended for public use. It has been modified to build templates from plugins rather than themes.
*
* @param array|object $template_file Theme file.
* @param string $template_type wp_template or wp_template_part.
Expand Down Expand Up @@ -223,8 +224,16 @@ public static function build_template_result_from_file( $template_file, $templat
$template->area = 'uncategorized';

// Force the Mini-Cart template part to be in the Mini-Cart template part area.
if ( 'wp_template_part' === $template_type && 'mini-cart' === $template_file->slug ) {
$template->area = 'mini-cart';
// @todo When this class is refactored, move title, description, and area definition to the template classes (CheckoutHeaderTemplate, MiniCartTemplate, etc).
Copy link

@tarunvijwani tarunvijwani Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering if we can refactor the code into a function, allowing us to reuse it for other templates.

function getTemplateAreaBySlug($slug) {
    $areas = [
        'mini-cart' => 'mini-cart',
        'checkout-header' => 'header'
    ];
    return $areas[$slug] ?? 'uncategorized';
}

if ('wp_template_part' === $template_type) {
    $template->area = getTemplateAreaBySlug($template_file->slug);
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but origami are going to be refactoring all of this soon so best we don't touch it at this point.

if ( 'wp_template_part' === $template_type ) {
switch ( $template_file->slug ) {
case 'mini-cart':
$template->area = 'mini-cart';
break;
case 'checkout-header':
$template->area = 'header';
break;
}
}
return $template;
}
Expand Down
Loading