Skip to content

Commit 39ca6a7

Browse files
committed
Block JSON schema: Add autoRegister support
1 parent fbb3525 commit 39ca6a7

4 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎phpunit/fixtures/block.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
}
2222
},
2323
"supports": {
24-
"align": true
24+
"align": true,
25+
"autoRegister": true
2526
},
2627
"styles": [
2728
{

‎schemas/json/block.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@
226226
"type": "boolean",
227227
"default": false
228228
},
229+
"autoRegister": {
230+
"description": "Allows PHP-only blocks with a `render_callback` to appear in the block editor without JavaScript registration. The editor renders them with `ServerSideRender`. If a block uses an API version older than 3, or does not specify one, the editor uses version 3.",
231+
"type": "boolean",
232+
"default": false
233+
},
229234
"align": {
230235
"description": "This property adds block controls which allow to change block’s alignment.",
231236
"oneOf": [

‎test/integration/blocks-schema.test.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ describe( 'block.json schema', () => {
1414
[ 'packages/*/src/**/block.json', '{lib,phpunit,test}/**/block.json' ],
1515
{ onlyFiles: true }
1616
);
17+
const invalidFiles = glob.sync(
18+
[ 'test/integration/fixtures/block-schemas/*.json' ],
19+
{ onlyFiles: true }
20+
);
1721
const ajv = new Ajv();
1822

1923
test( 'strictly adheres to the draft-07 meta schema', () => {
@@ -40,4 +44,15 @@ describe( 'block.json schema', () => {
4044

4145
expect( result ).toBe( true );
4246
} );
47+
48+
test.each( invalidFiles )(
49+
'rejects invalid block metadata in `%s`',
50+
( filepath ) => {
51+
const { $schema, ...blockMetadata } = require( filepath );
52+
53+
const result = ajv.validate( blockSchema, blockMetadata );
54+
55+
expect( result ).toBe( false );
56+
}
57+
);
4358
} );
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "../../../../schemas/json/block.json",
3+
"apiVersion": 3,
4+
"name": "my-plugin/invalid-auto-register",
5+
"title": "Invalid auto-registration",
6+
"supports": {
7+
"autoRegister": "yes"
8+
}
9+
}

0 commit comments

Comments
 (0)