Skip to content

List the block example as schema examples in bs_block_schema() - #203

Merged
dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:feat/block-schema-examples
Nov 11, 2026
Merged

dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:feat/block-schema-examples

Conversation

@Contributolo

Copy link
Copy Markdown
Collaborator

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: the example in block.json, written by the block author for the inserter preview. This adds it to the schema as the standard examples keyword when it fits.

Change

  • Block_Validator::schema() reads the example values with Render_Check::example(), the helper wp bs render-check already uses, so image placeholders ({"blockstudio": true, "type": "image"}) are left out the same way. The helper is now public instead of being duplicated.
  • The values are listed as examples: [ { ... } ] only when they pass rest_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, so examples never contradicts the schema. Empty examples ("example": {}) add nothing.
  • examples is set before the blockstudio/blocks/attributes/schema filter 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_matches in BlockValidatorTest: 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): BlockValidatorTest 78 tests and RenderCheckTest 13 tests pass. Removing the assignment or the schema check makes the new test fail. composer cs and PHPStan are clean for the two changed classes, npm run docs:check passes. No new translatable strings.

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.
@Contributolo Contributolo added the enhancement New feature or request label Nov 7, 2026
@dnnsjsk
dnnsjsk merged commit 1dd7fff into inline0:main Nov 11, 2026
@dnnsjsk

dnnsjsk commented Nov 11, 2026

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants