Skip to content

Commit

Permalink
_gutenberg_add_template_part_area_info from the new templateParts f…
Browse files Browse the repository at this point in the history
…ormat.
  • Loading branch information
ntsekouras committed Mar 22, 2021
1 parent 07fcc58 commit e49900a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
17 changes: 13 additions & 4 deletions lib/full-site-editing/block-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,21 @@ function _gutenberg_add_template_part_area_info( $template_info ) {
$theme_data = WP_Theme_JSON_Resolver::get_theme_data()->get_template_parts();
}

if ( isset( $theme_data[ $template_info['slug'] ]['area'] ) ) {
$template_info['area'] = gutenberg_filter_template_part_area( $theme_data[ $template_info['slug'] ]['area'] );
} else {
$template_info['area'] = WP_TEMPLATE_PART_AREA_UNCATEGORIZED;
$found_area = null;
if ( isset( $template_info['slug'] ) && is_array( $theme_data ) ) {
foreach ( array_values( $theme_data ) as $value ) {
if ( ! ( isset( $value['name'] ) && isset( $value['area'] ) ) ) {
continue;
}
if ( $template_info['slug'] === $value['name'] ) {
$found_area = $value['area'];
break;
}
}
}

$template_info['area'] = $found_area ? gutenberg_filter_template_part_area( $found_area ) : WP_TEMPLATE_PART_AREA_UNCATEGORIZED;

return $template_info;
}

Expand Down
6 changes: 4 additions & 2 deletions phpunit/class-wp-theme-json-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,8 @@ function test_get_template_parts() {
$theme_json = new WP_Theme_JSON(
array(
'templateParts' => array(
'header' => array(
array(
'name' => 'header',
'area' => 'Some area',
),
),
Expand All @@ -813,7 +814,8 @@ function test_get_template_parts() {
$this->assertEqualSetsWithIndex(
$template_parts,
array(
'header' => array(
array(
'name' => 'header',
'area' => 'Some area',
),
)
Expand Down

0 comments on commit e49900a

Please sign in to comment.