Repository navigation
List the block example as schema examples in bs_block_schema() - #203
Merged
Merged
Conversation
When a block's example attributes match its stored-value schema, the schema carries them as `examples`, so a tool that generates markup sees one complete value next to the field descriptions. Image placeholders are left out with the same helper Render_Check uses, and an example that does not match is not listed.
Contributor
|
Merged and released in Blockstudio 7.7.14, integration commit 1dd7fff. Added regression cases for invalid stored-value examples and removing examples through the schema filter. Documentation and bundled LLM context are updated; full CI and distribution checks pass. Thanks for the contribution. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
bs_block_schema()describes every field of a block, but a tool that generates markup from it still has to assemble a first value on its own. Most blocks already ship one: theexamplein block.json, written by the block author for the inserter preview. This adds it to the schema as the standardexampleskeyword when it fits.Change
Block_Validator::schema()reads the example values withRender_Check::example(), the helperwp bs render-checkalready uses, so image placeholders ({"blockstudio": true, "type": "image"}) are left out the same way. The helper is now public instead of being duplicated.examples: [ { ... } ]only when they passrest_validate_value_from_schema()against the schema itself. An example in an imported shape (an option object, a file object) or with an unknown key is not listed, soexamplesnever contradicts the schema. Empty examples ("example": {}) add nothing.examplesis set before theblockstudio/blocks/attributes/schemafilter runs, so sites can still adapt or drop it.rest_validate_value_from_schema()ignores the keyword, so the schema keeps working as a REST or ability input schema.Docs: a paragraph in "Describing stored values" (Rendering), one sentence under "Custom Data" in Preview, and the regenerated LLM files (only these two paragraphs change).
Tests
test_schema_lists_the_block_example_when_it_matchesinBlockValidatorTest: a matching example with an image placeholder is listed without the placeholder and validates against the schema, an example with an unknown option is not listed, and an empty example adds nothing.Run in WordPress Playground with PHPUnit started inside the request (no wp-env here):
BlockValidatorTest78 tests andRenderCheckTest13 tests pass. Removing the assignment or the schema check makes the new test fail.composer csand PHPStan are clean for the two changed classes,npm run docs:checkpasses. No new translatable strings.