From d438cac053eced176593111503633c88ef2e2742 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Mon, 15 Jun 2020 17:56:14 +0200 Subject: [PATCH] Rename context to use_context when using inside REST API --- lib/class-wp-rest-block-types-controller.php | 50 ++++++++++--------- ...ss-wp-rest-block-types-controller-test.php | 7 +-- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/lib/class-wp-rest-block-types-controller.php b/lib/class-wp-rest-block-types-controller.php index cde37ae875ac57..2473ee3dd76b4d 100644 --- a/lib/class-wp-rest-block-types-controller.php +++ b/lib/class-wp-rest-block-types-controller.php @@ -239,30 +239,30 @@ public function prepare_item_for_response( $block_type, $request ) { $schema = $this->get_item_schema(); $extra_fields = array( - 'name', - 'title', - 'description', - 'icon', - 'category', - 'keywords', - 'parent', - 'supports', - 'styles', - 'textdomain', - 'example', - 'editor_script', - 'script', - 'editor_style', - 'style', - 'provides_context', - 'use_context', + 'name' => 'name', + 'title' => 'title', + 'description' => 'description', + 'icon' => 'icon', + 'category' => 'category', + 'keywords' => 'keywords', + 'parent' => 'parent', + 'supports' => 'supports', + 'styles' => 'styles', + 'textdomain' => 'textdomain', + 'example' => 'example', + 'editor_script' => 'editor_script', + 'script' => 'script', + 'editor_style' => 'editor_style', + 'style' => 'style', + 'provides_context' => 'providesContext', + 'use_context' => 'context', ); - foreach ( $extra_fields as $extra_field ) { + foreach ( $extra_fields as $key => $extra_field ) { if ( rest_is_field_included( $key, $fields ) ) { if ( isset( $block_type->$extra_field ) ) { $field = $block_type->$extra_field; - } elseif ( array_key_exists( 'default', $schema['properties'][ $extra_field ] ) ) { - $field = $schema['properties'][ $extra_field ]['default']; + } elseif ( array_key_exists( 'default', $schema['properties'][ $key ] ) ) { + $field = $schema['properties'][ $key ]['default']; } else { $field = ''; } @@ -439,14 +439,14 @@ public function get_item_schema() { 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), - 'textdomain' => array( + 'textdomain' => array( 'description' => __( 'Public text domain.', 'gutenberg' ), 'type' => array( 'string', 'null' ), 'default' => null, 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), - 'parent' => array( + 'parent' => array( 'description' => __( 'Parent blocks.', 'gutenberg' ), 'type' => array( 'array', 'null' ), 'items' => array( @@ -466,7 +466,7 @@ public function get_item_schema() { 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), - 'example' => array( + 'example' => array( 'description' => __( 'Block example.', 'gutenberg' ), 'type' => array( 'object', 'null' ), 'default' => null, @@ -474,6 +474,8 @@ public function get_item_schema() { 'additionalProperties' => array( 'type' => 'object', ), + 'context' => array( 'embed', 'view', 'edit' ), + 'readonly' => true, ), 'provides_context' => array( 'description' => __( 'Context provided by blocks of this type.', 'gutenberg' ), @@ -486,7 +488,7 @@ public function get_item_schema() { 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), - 'use_context' => array( + 'use_context' => array( 'description' => __( 'Context values inherited by blocks of this type.', 'gutenberg' ), 'type' => 'array', 'default' => array(), diff --git a/phpunit/class-wp-rest-block-types-controller-test.php b/phpunit/class-wp-rest-block-types-controller-test.php index 615217e4ba470a..b14242a93332cc 100644 --- a/phpunit/class-wp-rest-block-types-controller-test.php +++ b/phpunit/class-wp-rest-block-types-controller-test.php @@ -347,10 +347,11 @@ public function check_block_type_object( $block_type, $data, $links ) { 'description' => 'description', 'keywords' => 'keywords', 'parent' => 'parent', - 'styles' => 'styleVariations', - 'text_domain' => 'textDomain', - 'context' => 'context', + 'styles' => 'styles', + 'textdomain' => 'textdomain', + 'example' => 'example', 'provides_context' => 'providesContext', + 'use_context' => 'context', ); foreach ( $extra_fields as $key => $extra_field ) {