From 060515b7de624cfb64c8ada38d0b1b91e5a4d316 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Fri, 26 Nov 2021 16:19:54 +0400 Subject: [PATCH 1/2] Templates Controller: Add missing 'is_custom' prop --- .../class-gutenberg-rest-templates-controller.php | 7 +++++++ phpunit/class-gutenberg-rest-template-controller-test.php | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/lib/compat/wordpress-5.9/class-gutenberg-rest-templates-controller.php b/lib/compat/wordpress-5.9/class-gutenberg-rest-templates-controller.php index eb7f047a8e98df..109759d63d493f 100644 --- a/lib/compat/wordpress-5.9/class-gutenberg-rest-templates-controller.php +++ b/lib/compat/wordpress-5.9/class-gutenberg-rest-templates-controller.php @@ -412,6 +412,7 @@ public function prepare_item_for_response( $template, $request ) { // phpcs:igno 'status' => $template->status, 'wp_id' => $template->wp_id, 'has_theme_file' => $template->has_theme_file, + 'is_custom' => $template->is_custom, ); if ( 'wp_template_part' === $template->type ) { @@ -579,6 +580,12 @@ public function get_item_schema() { 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), + 'is_custom' => array( + 'description' => __( 'Whether a template is a custom template.', 'gutenberg' ), + 'type' => 'bool', + 'context' => array( 'embed', 'view', 'edit' ), + 'readonly' => true, + ), ), ); diff --git a/phpunit/class-gutenberg-rest-template-controller-test.php b/phpunit/class-gutenberg-rest-template-controller-test.php index 4fc3b5407e06e9..38c6de1b9c9a5b 100644 --- a/phpunit/class-gutenberg-rest-template-controller-test.php +++ b/phpunit/class-gutenberg-rest-template-controller-test.php @@ -76,6 +76,7 @@ function find_and_normalize_template_by_id( $templates, $id ) { 'type' => 'wp_template', 'wp_id' => null, 'has_theme_file' => true, + 'is_custom' => false, ), find_and_normalize_template_by_id( $data, 'tt1-blocks//index' ) ); @@ -101,6 +102,7 @@ function find_and_normalize_template_by_id( $templates, $id ) { 'wp_id' => null, 'area' => WP_TEMPLATE_PART_AREA_HEADER, 'has_theme_file' => true, + 'is_custom' => true, ), find_and_normalize_template_by_id( $data, 'tt1-blocks//header' ) ); @@ -129,6 +131,7 @@ public function test_get_item() { 'type' => 'wp_template', 'wp_id' => null, 'has_theme_file' => true, + 'is_custom' => false, ), $data ); @@ -155,6 +158,7 @@ public function test_get_item() { 'wp_id' => null, 'area' => WP_TEMPLATE_PART_AREA_HEADER, 'has_theme_file' => true, + 'is_custom' => true, ), $data ); @@ -193,6 +197,7 @@ public function test_create_item() { 'raw' => 'Content', ), 'has_theme_file' => false, + 'is_custom' => true, ), $data ); @@ -231,6 +236,7 @@ public function test_create_item() { ), 'area' => 'header', 'has_theme_file' => false, + 'is_custom' => true, ), $data ); From aff6095d38baf59461668862cead1c8357b23e97 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Fri, 26 Nov 2021 19:04:27 +0400 Subject: [PATCH 2/2] Add prop only for wp_template --- ...ss-gutenberg-rest-templates-controller.php | 20 ++++++++++++------- ...utenberg-rest-template-controller-test.php | 3 --- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/compat/wordpress-5.9/class-gutenberg-rest-templates-controller.php b/lib/compat/wordpress-5.9/class-gutenberg-rest-templates-controller.php index 109759d63d493f..12aa2124da3731 100644 --- a/lib/compat/wordpress-5.9/class-gutenberg-rest-templates-controller.php +++ b/lib/compat/wordpress-5.9/class-gutenberg-rest-templates-controller.php @@ -412,9 +412,12 @@ public function prepare_item_for_response( $template, $request ) { // phpcs:igno 'status' => $template->status, 'wp_id' => $template->wp_id, 'has_theme_file' => $template->has_theme_file, - 'is_custom' => $template->is_custom, ); + if ( 'wp_template' === $template->type ) { + $result['is_custom'] = $template->is_custom; + } + if ( 'wp_template_part' === $template->type ) { $result['area'] = $template->area; } @@ -580,15 +583,18 @@ public function get_item_schema() { 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), - 'is_custom' => array( - 'description' => __( 'Whether a template is a custom template.', 'gutenberg' ), - 'type' => 'bool', - 'context' => array( 'embed', 'view', 'edit' ), - 'readonly' => true, - ), ), ); + if ( 'wp_template' === $this->post_type ) { + $schema['properties']['is_custom'] = array( + 'description' => __( 'Whether a template is a custom template.', 'gutenberg' ), + 'type' => 'bool', + 'context' => array( 'embed', 'view', 'edit' ), + 'readonly' => true, + ); + } + if ( 'wp_template_part' === $this->post_type ) { $schema['properties']['area'] = array( 'description' => __( 'Where the template part is intended for use (header, footer, etc.)', 'gutenberg' ), diff --git a/phpunit/class-gutenberg-rest-template-controller-test.php b/phpunit/class-gutenberg-rest-template-controller-test.php index 38c6de1b9c9a5b..6c6d62be1b417d 100644 --- a/phpunit/class-gutenberg-rest-template-controller-test.php +++ b/phpunit/class-gutenberg-rest-template-controller-test.php @@ -102,7 +102,6 @@ function find_and_normalize_template_by_id( $templates, $id ) { 'wp_id' => null, 'area' => WP_TEMPLATE_PART_AREA_HEADER, 'has_theme_file' => true, - 'is_custom' => true, ), find_and_normalize_template_by_id( $data, 'tt1-blocks//header' ) ); @@ -158,7 +157,6 @@ public function test_get_item() { 'wp_id' => null, 'area' => WP_TEMPLATE_PART_AREA_HEADER, 'has_theme_file' => true, - 'is_custom' => true, ), $data ); @@ -236,7 +234,6 @@ public function test_create_item() { ), 'area' => 'header', 'has_theme_file' => false, - 'is_custom' => true, ), $data );