From 68a576b906f5a5af9e64d1dcb1e0165c18471708 Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Mon, 22 Feb 2021 10:57:58 -0800 Subject: [PATCH] Fix existing test and add remaining variation fields to schema --- .../class-wp-rest-block-types-controller.php | 79 ++++++++++++++++++- tests/phpunit/tests/admin/includesPost.php | 1 + 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php index eb52307ea8d5f..0b959891e10cf 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php @@ -544,7 +544,7 @@ public function get_item_schema() { 'required' => false, ), 'isDefault' => array( - 'description' => __( 'Indicates whether the current variation is the default one. Defaults to `false`' ), + 'description' => __( 'Indicates whether the current variation is the default one.' ), 'type' => 'boolean', 'required' => false, 'default' => false, @@ -558,7 +558,82 @@ public function get_item_schema() { 'type' => 'object', ), ), - //TODO: innerBlocks, example, scope, keywords, isActive + 'innerBlocks' => array( + 'description' => __( 'Initial configuration of nested blocks.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'object', + 'properties' => array( + 'name' => array( + 'description' => __( 'The name of the inner block.' ), + 'type' => 'string', + ), + 'attributes' => array( + 'description' => __( 'The attributes of the inner block.' ), + 'type' => 'object', + ), + 'innerBlocks' => array( + 'description' => __( "A list of the inner block's own inner blocks. This is a recursive definition following the parent innerBlocks schema." ), + 'type' => 'array', + ), + ), + ), + ), + 'example' => array( + 'description' => __( 'Example provides structured data for the block preview. Set this to `null` to disable the preview shown for the block type.' ), + 'type' => array( 'object', 'null' ), + 'default' => null, + 'properties' => array( + 'attributes' => array( + 'description' => __( 'The attributes used in the example.' ), + 'type' => 'object', + ), + 'innerBlocks' => array( + 'description' => __( 'The list of inner blocks used in the example.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'object', + 'properties' => array( + 'name' => array( + 'description' => __( 'The name of the inner block.' ), + 'type' => 'string', + ), + 'attributes' => array( + 'description' => __( 'The attributes of the inner block.' ), + 'type' => 'object', + ), + 'innerBlocks' => array( + 'description' => __( "A list of the inner block's own inner blocks. This is a recursive definition following the parent innerBlocks schema." ), + 'type' => 'array', + ), + ), + ), + ), + ), + ), + 'scope' => array( + 'description' => __( 'The list of scopes where the variation is applicable. When not provided, it assumes all available scopes.' ), + 'type' => array( 'array', 'null' ), + 'default' => null, + 'items' => array( + 'type' => 'string', + 'enum' => array( 'block', 'inserter', 'transform' ), + ), + 'readonly' => true, + ), + 'keywords' => array( + 'description' => __( 'An array of terms (which can be translated) that help users discover the variation while searching' ), + 'type' => 'array', + 'items' => array( + 'type' => 'string', + ), + 'default' => array(), + ), + 'icon' => array( + 'description' => __( 'An icon helping to visualize the variation.' ), + 'type' => array( 'string', 'null' ), + 'default' => null, + ), ), ), 'readonly' => true, diff --git a/tests/phpunit/tests/admin/includesPost.php b/tests/phpunit/tests/admin/includesPost.php index 4dffffd0d0ac3..915f1fbd04bdb 100644 --- a/tests/phpunit/tests/admin/includesPost.php +++ b/tests/phpunit/tests/admin/includesPost.php @@ -847,6 +847,7 @@ function test_get_block_editor_server_block_settings() { 'category' => 'common', 'styles' => array(), 'keywords' => array(), + 'variations' => array(), ), $blocks[ $name ] );