Skip to content

Commit

Permalink
Templates Controller: Add missing 'is_custom' prop (#36911)
Browse files Browse the repository at this point in the history
* Templates Controller: Add missing 'is_custom' prop

* Add prop only for wp_template
  • Loading branch information
Mamaduka committed Nov 26, 2021
1 parent 513ff93 commit 6466208
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,10 @@ public function prepare_item_for_response( $template, $request ) { // phpcs:igno
'has_theme_file' => $template->has_theme_file,
);

if ( 'wp_template' === $template->type ) {
$result['is_custom'] = $template->is_custom;
}

if ( 'wp_template_part' === $template->type ) {
$result['area'] = $template->area;
}
Expand Down Expand Up @@ -613,6 +617,15 @@ public function get_item_schema() {
),
);

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' ),
Expand Down
3 changes: 3 additions & 0 deletions phpunit/class-gutenberg-rest-template-controller-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' )
);
Expand Down Expand Up @@ -129,6 +130,7 @@ public function test_get_item() {
'type' => 'wp_template',
'wp_id' => null,
'has_theme_file' => true,
'is_custom' => false,
),
$data
);
Expand Down Expand Up @@ -263,6 +265,7 @@ public function test_create_item() {
'raw' => 'Content',
),
'has_theme_file' => false,
'is_custom' => true,
),
$data
);
Expand Down

0 comments on commit 6466208

Please sign in to comment.