Skip to content

Commit d438cac

Browse files
committed
Rename context to use_context when using inside REST API
1 parent c0855b6 commit d438cac

2 files changed

Lines changed: 30 additions & 27 deletions

File tree

lib/class-wp-rest-block-types-controller.php

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -239,30 +239,30 @@ public function prepare_item_for_response( $block_type, $request ) {
239239

240240
$schema = $this->get_item_schema();
241241
$extra_fields = array(
242-
'name',
243-
'title',
244-
'description',
245-
'icon',
246-
'category',
247-
'keywords',
248-
'parent',
249-
'supports',
250-
'styles',
251-
'textdomain',
252-
'example',
253-
'editor_script',
254-
'script',
255-
'editor_style',
256-
'style',
257-
'provides_context',
258-
'use_context',
242+
'name' => 'name',
243+
'title' => 'title',
244+
'description' => 'description',
245+
'icon' => 'icon',
246+
'category' => 'category',
247+
'keywords' => 'keywords',
248+
'parent' => 'parent',
249+
'supports' => 'supports',
250+
'styles' => 'styles',
251+
'textdomain' => 'textdomain',
252+
'example' => 'example',
253+
'editor_script' => 'editor_script',
254+
'script' => 'script',
255+
'editor_style' => 'editor_style',
256+
'style' => 'style',
257+
'provides_context' => 'providesContext',
258+
'use_context' => 'context',
259259
);
260-
foreach ( $extra_fields as $extra_field ) {
260+
foreach ( $extra_fields as $key => $extra_field ) {
261261
if ( rest_is_field_included( $key, $fields ) ) {
262262
if ( isset( $block_type->$extra_field ) ) {
263263
$field = $block_type->$extra_field;
264-
} elseif ( array_key_exists( 'default', $schema['properties'][ $extra_field ] ) ) {
265-
$field = $schema['properties'][ $extra_field ]['default'];
264+
} elseif ( array_key_exists( 'default', $schema['properties'][ $key ] ) ) {
265+
$field = $schema['properties'][ $key ]['default'];
266266
} else {
267267
$field = '';
268268
}
@@ -439,14 +439,14 @@ public function get_item_schema() {
439439
'context' => array( 'embed', 'view', 'edit' ),
440440
'readonly' => true,
441441
),
442-
'textdomain' => array(
442+
'textdomain' => array(
443443
'description' => __( 'Public text domain.', 'gutenberg' ),
444444
'type' => array( 'string', 'null' ),
445445
'default' => null,
446446
'context' => array( 'embed', 'view', 'edit' ),
447447
'readonly' => true,
448448
),
449-
'parent' => array(
449+
'parent' => array(
450450
'description' => __( 'Parent blocks.', 'gutenberg' ),
451451
'type' => array( 'array', 'null' ),
452452
'items' => array(
@@ -466,14 +466,16 @@ public function get_item_schema() {
466466
'context' => array( 'embed', 'view', 'edit' ),
467467
'readonly' => true,
468468
),
469-
'example' => array(
469+
'example' => array(
470470
'description' => __( 'Block example.', 'gutenberg' ),
471471
'type' => array( 'object', 'null' ),
472472
'default' => null,
473473
'properties' => array(),
474474
'additionalProperties' => array(
475475
'type' => 'object',
476476
),
477+
'context' => array( 'embed', 'view', 'edit' ),
478+
'readonly' => true,
477479
),
478480
'provides_context' => array(
479481
'description' => __( 'Context provided by blocks of this type.', 'gutenberg' ),
@@ -486,7 +488,7 @@ public function get_item_schema() {
486488
'context' => array( 'embed', 'view', 'edit' ),
487489
'readonly' => true,
488490
),
489-
'use_context' => array(
491+
'use_context' => array(
490492
'description' => __( 'Context values inherited by blocks of this type.', 'gutenberg' ),
491493
'type' => 'array',
492494
'default' => array(),

phpunit/class-wp-rest-block-types-controller-test.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,11 @@ public function check_block_type_object( $block_type, $data, $links ) {
347347
'description' => 'description',
348348
'keywords' => 'keywords',
349349
'parent' => 'parent',
350-
'styles' => 'styleVariations',
351-
'text_domain' => 'textDomain',
352-
'context' => 'context',
350+
'styles' => 'styles',
351+
'textdomain' => 'textdomain',
352+
'example' => 'example',
353353
'provides_context' => 'providesContext',
354+
'use_context' => 'context',
354355
);
355356

356357
foreach ( $extra_fields as $key => $extra_field ) {

0 commit comments

Comments
 (0)