-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add parsing and validation for block.json files #2
Add parsing and validation for block.json files #2
Conversation
block-json/class-validator.php
Outdated
'type' => 'string', | ||
), | ||
), | ||
'required' => array( 'name', 'title', 'category' ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are going to be added two more fields:
context
(name might change becausecontext
is 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
Parser
class and aValidator
class 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,error
andwarning
, 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_file
method in the Importer class.