Add parsing and validation for block.json files#2
Conversation
| 'type' => 'string', | ||
| ), | ||
| ), | ||
| 'required' => array( 'name', 'title', 'category' ), |
There was a problem hiding this comment.
The category will become optional as of WordPress 5.5.
| "message": "This is a notice!" | ||
| } | ||
| }, | ||
| "editorScript": "build/editor.js", |
There was a problem hiding this comment.
I ended up with a more nuanced way of defining assets, for example:
https://github.com/WordPress/gutenberg/blob/master/docs/rfc/block-registration.md#editor-script
{ "script": "file:./build/script.js" }Full description here:
https://github.com/WordPress/gutenberg/blob/master/docs/rfc/block-registration.md#wpdefinedasset
Long story short, developers can provide a relative path as before or a script/style handle. For the Block Directory, you could say that file is the only option.
| "script": "build/main.js", | ||
| "editorStyle": "build/editor.css", | ||
| "style": "build/style.css" | ||
| } |
There was a problem hiding this comment.
There are going to be added two more fields:
context(name might change becausecontextis reserved in REST API)providesContext
Tracking ticket: https://core.trac.wordpress.org/ticket/49927
Documentation update: WordPress/gutenberg#22686
|
I opened a ticket in WordPress trac to start the discussion on how we could maintain a shared JSON schema in one place: https://core.trac.wordpress.org/ticket/50615. |
Similar to the readme parser, this adds a
Parserclass and aValidatorclass for block.json files. The parser attempts to capture helpful error messages if they arise while decoding JSON to a PHP object. The validator collects two levels of error messages during validation,errorandwarning, which are returned in a single WP_Error object so they can be handled according to the context.This also incorporates the parser and validator into the
find_blocks_in_filemethod in the Importer class.