API / Minn\Runtime / BlockMetadata

BlockMetadata final class

Minn\Runtime\BlockMetadata · public/minn/src/Minn/Runtime/BlockMetadata.php · 138 lines

block.json to the settings a block type registers with: the property renames, the script and style handles (registered through the closures, one per entry), the view script modules, the block hooks positions, and the render template as a callback. Behaviour pinned by contracts/fixtures/api/blocks.json.

Constants and properties

privatePROPERTIES = array ( 'apiVersion' => 'api_version', 'name' => 'name', 'title' => 'title', 'category' => 'category', 'parent' => 'parent', 'ancestor' => 'ancestor', 'icon' => 'icon', 'description' => 'description', 'keywords' => 'keywords', 'attributes' => 'attributes', 'providesContext' => 'provides_context', 'usesContext' => 'uses_context', 'selectors' => 'selectors', 'supports' => 'supports', 'styles' => 'styles', 'variations' => 'variations', 'example' => 'example', 'allowedBlocks' => 'allowed_blocks', )
privateSCRIPTS = array ( 'editorScript' => 'editor_script_handles', 'script' => 'script_handles', 'viewScript' => 'view_script_handles', )
privateSTYLES = array ( 'editorStyle' => 'editor_style_handles', 'style' => 'style_handles', 'viewStyle' => 'view_style_handles', )
privatePOSITIONS = array ( 'before' => 'before', 'after' => 'after', 'firstChild' => 'first_child', 'lastChild' => 'last_child', )
privateI18N = array ( 'title' => 'block title', 'description' => 'block description', 'keywords' => array ( 0 => 'block keyword', ), 'styles' => array ( 0 => array ( 'label' => 'block style label', ), ), 'variations' => array ( 0 => array ( 'title' => 'block variation title', 'description' => 'block variation description', 'keywords' => array ( 0 => 'block variation keyword', ), ), ), )

The block.json strings a text domain translates, each with its context (get_block_metadata_i18n_schema).

privateFIELD_HANDLES = array ( 'editorScript' => 'editor-script', 'editorStyle' => 'editor-style', 'script' => 'script', 'style' => 'style', 'viewScript' => 'view-script', 'viewScriptModule' => 'view-script-module', 'viewStyle' => 'view-style', )

Public

statictranslated(array $metadata): array#

A block.json's strings in its text domain, each asked in its context (title as "block title", keywords as "block keyword"...); a block without a text domain is left as it is (probe taxonomy-blocks-user-doubts).

$metadataarray<string, mixed>
@return array<string, mixed>
staticsettings(array $metadata, Closure $scriptHandle, Closure $styleHandle, Closure $moduleId, Closure $render): array#

Block settings from a block.json, the way the reference maps its properties.

$scriptHandleClosure(array, string, int): (string|false)registers one script entry, answering its handle
$styleHandleClosure(array, string, int): (string|false)registers one style entry
$moduleIdClosure(array, string, int): (string|false)registers one view script module entry
$renderClosure(string): ?Closurethe render callback for a template path, or null when the file is missing
@return array<string, mixed>
staticassetHandle(string $block, string $field, int $index = 0): string#

The script or style handle a block.json field registers under; core blocks keep the `wp-block-` spelling.

Internals 2

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatetranslatedValue(mixed $value, mixed $schema, string $domain): mixed#

One value by its piece of the schema: a string in its context, a list item by item, an object key by key.

privatehandles(array $metadata, string $field, Closure $register): ?array#

The registered handles for one asset field: every entry when the field lists several; null when the field is absent. @return list<string>|null

@return list<string>|null