Skip to content

Commit

Permalink
Rename context to use_context when using inside REST API
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Jun 15, 2020
1 parent c0855b6 commit d438cac
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
50 changes: 26 additions & 24 deletions lib/class-wp-rest-block-types-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
}
Expand Down Expand Up @@ -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(
Expand All @@ -466,14 +466,16 @@ 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,
'properties' => array(),
'additionalProperties' => array(
'type' => 'object',
),
'context' => array( 'embed', 'view', 'edit' ),
'readonly' => true,
),
'provides_context' => array(
'description' => __( 'Context provided by blocks of this type.', 'gutenberg' ),
Expand All @@ -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(),
Expand Down
7 changes: 4 additions & 3 deletions phpunit/class-wp-rest-block-types-controller-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down

0 comments on commit d438cac

Please sign in to comment.