Repository navigation
Add bs_block_extension_fields() for the fields extensions add to a block - #121
Merged
Merged
Conversation
An extension whose name list contains several patterns that match a block, such as ["core/*", "core/paragraph"], was returned once per matching pattern. The editor matches with some() and shows the extension once. Stop after the first matching name so the server side agrees.
bs_block_fields() returns a block's own field definitions, but fields that extensions add are stored in the same attrs.blockstudio.attributes and were only reachable through Build::extensions(). The new helper returns the field definitions of every extension matching a block name, using Extensions::get_matches(), so it also covers core and third-party blocks.
dnnsjsk
approved these changes
Oct 15, 2026
dnnsjsk
left a comment
Contributor
There was a problem hiding this comment.
Verified the helper against the registry and both extension render paths. The separate array-returning API correctly covers core/third-party targets without changing bs_block_fields() null semantics. The matching fix preserves registration order while removing duplicate matches of the same extension, and the unit tests cover the lookup and later-extension precedence. Including this in 7.7.2; the since annotation and changelog will be adjusted in the release follow-up.
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.
Related to #115.
Problem
bs_block_fields()returns a block's own field definitions. Fields that extensions add to a block (blockstudio.extend) are saved in the sameattrs.blockstudio.attributesof the extended block, but their definitions are only reachable through the internalBuild::extensions()plusExtensions::get_matches(). A tool that validates saved markup, as described in #115, needs both. Extensions also apply to core and third-party blocks, for whichbs_block_fields()returnsnull.API
Returns the field definitions of every extension whose
namematches the block (exact name, list, or prefix wildcard), usingExtensions::get_matches(). It reads$extension->blockstudio['attributes'], so the structure is the same asbs_block_fields(), and the two can be combined:Design choices:
bs_block_fields().bs_block_fields()usesnullto mean "unknown or not a Blockstudio block", which would not fit core blocks with extension fields. Matching is by name only, like on render, so a block no extension matches returns[].attrs.blockstudio.attributesobject, next to the block's own values, so ids share one namespace. A flat list can be walked likebs_block_fields(). Panel group and priority only affect the editor UI.Block::render()andExtensions::render_blocks()resolve extension definitions in: if two extensions define the same id, both definitions are returned, they edit the same value, and on render the definition of the extension registered later applies. The editor sorts panels bypriority, which is presentation only.The PR also makes
Extensions::get_matches()return an extension once when several of its names match (for example["core/*", "core/paragraph"]), as the editor already does withsome(). Without that, the new helper would list such fields twice. Rendering is unaffected because both callers key the result by attribute id.Docs: a paragraph in "Inspecting Blocks" (
blocks/rendering.md) and a short "Inspecting Extension Fields" section inextensions.md. The LLM context is rebuilt withnpm run build:llm, nothing else changed in it. No changelog entry, since the 7.7.2 notes are already prepared. A possible line:New: public bs_block_extension_fields() helper exposes the field definitions extensions add to a block.@since 7.7.3assumes the next release; please adjust if needed.Tests
ExtensionsTest: an extension with several matching names is returned once.BlockMetadataTest(registers its own extensions and restores the registry afterwards):unit-meta/*, exact nameunit-meta/card, a name list, andcore/paragraph; blocks matched by none (core/heading,unit-metadata/card, unknown) return[]bs_block_fields()and gets extension fields only from the new helperExtensions::render_blocks()applies the later onecore/*,core/heading, theblockstudio/type-textlist) are reported for the expected blockscomposer cs, PHPStan andnpm run checkpass. The unit tests ran in WordPress Playground with the test theme active (no Docker here):tests/unit/block,extensions,render,register,attribute-builder,block-discovery,admin-pageandcanvaspass. Without theget_matches()change, the new duplicate test and the matching test inBlockMetadataTestfail.