Block Editor: Expose api_version in the block type and the REST endpoint.
The new block editor included in 5.6 introduces an api_version property that indicates which block API version the block is using. This commits makes this property available on the block type and the endpoint. Props TimothyBlynJacobs, gziolo. Fixes #51529. git-svn-id: https://develop.svn.wordpress.org/trunk@49224 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
af767035e7
commit
123a965c70
@ -207,6 +207,7 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {
|
||||
'supports' => 'supports',
|
||||
'styles' => 'styles',
|
||||
'example' => 'example',
|
||||
'apiVersion' => 'api_version',
|
||||
);
|
||||
|
||||
foreach ( $property_mappings as $key => $mapped_key ) {
|
||||
|
@ -16,6 +16,14 @@
|
||||
*/
|
||||
class WP_Block_Type {
|
||||
|
||||
/**
|
||||
* Block API version.
|
||||
*
|
||||
* @since 5.6.0
|
||||
* @var int
|
||||
*/
|
||||
public $api_version = 1;
|
||||
|
||||
/**
|
||||
* Block type key.
|
||||
*
|
||||
|
@ -256,6 +256,7 @@ class WP_REST_Block_Types_Controller extends WP_REST_Controller {
|
||||
|
||||
$schema = $this->get_item_schema();
|
||||
$extra_fields = array(
|
||||
'api_version',
|
||||
'name',
|
||||
'title',
|
||||
'description',
|
||||
@ -365,6 +366,13 @@ class WP_REST_Block_Types_Controller extends WP_REST_Controller {
|
||||
'title' => 'block-type',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'api_version' => array(
|
||||
'description' => __( 'Version of block API.' ),
|
||||
'type' => 'integer',
|
||||
'default' => 1,
|
||||
'context' => array( 'embed', 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'title' => array(
|
||||
'description' => __( 'Title of block type.' ),
|
||||
'type' => 'string',
|
||||
|
@ -1,4 +1,5 @@
|
||||
{
|
||||
"apiVersion": 2,
|
||||
"name": "my-plugin/notice",
|
||||
"title": "Notice",
|
||||
"category": "common",
|
||||
|
@ -285,6 +285,7 @@ class WP_Test_Block_Register extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
$this->assertInstanceOf( 'WP_Block_Type', $result );
|
||||
$this->assertSame( 2, $result->api_version );
|
||||
$this->assertSame( 'my-plugin/notice', $result->name );
|
||||
$this->assertSame( 'Notice', $result->title );
|
||||
$this->assertSame( 'common', $result->category );
|
||||
|
@ -312,7 +312,8 @@ class REST_Block_Type_Controller_Test extends WP_Test_REST_Controller_Testcase {
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$properties = $data['schema']['properties'];
|
||||
$this->assertCount( 19, $properties );
|
||||
$this->assertCount( 20, $properties );
|
||||
$this->assertArrayHasKey( 'api_version', $properties );
|
||||
$this->assertArrayHasKey( 'title', $properties );
|
||||
$this->assertArrayHasKey( 'icon', $properties );
|
||||
$this->assertArrayHasKey( 'description', $properties );
|
||||
@ -431,6 +432,7 @@ class REST_Block_Type_Controller_Test extends WP_Test_REST_Controller_Testcase {
|
||||
$this->assertSame( $data['is_dynamic'], $block_type->is_dynamic() );
|
||||
|
||||
$extra_fields = array(
|
||||
'api_version',
|
||||
'name',
|
||||
'category',
|
||||
'editor_script',
|
||||
|
Loading…
Reference in New Issue
Block a user