API / Minn\Blocks / Bindings

Bindings final class

Minn\Blocks\Bindings · public/minn/src/Minn/Blocks/Bindings.php · 138 lines

Block bindings (probe block-bindings): a block attribute bound to a source registered with register_block_bindings_source takes the source's value as the block renders. Only the attributes a block supports bind (SUPPORTED, widened by block_bindings_supported_attributes and its per-block form); a "__default" pattern-overrides binding stands for every one of them. A static block's saved HTML takes the values (rich text, kses'd, inside the element its definition selects; plain values set as the selected element's attribute); a dynamic block renders with them.

Used by 1

Constants and properties

constSUPPORTED = array ( 'core/paragraph' => array ( 0 => 'content', ), 'core/heading' => array ( 0 => 'content', ), 'core/image' => array ( 0 => 'id', 1 => 'url', 2 => 'title', 3 => 'alt', 4 => 'caption', ), 'core/button' => array ( 0 => 'url', 1 => 'text', 2 => 'linkTarget', 3 => 'rel', ), 'core/post-date' => array ( 0 => 'datetime', ), 'core/navigation-link' => array ( 0 => 'url', ), 'core/navigation-submenu' => array ( 0 => 'url', ), )

Public

staticsupported(string $name): array#

The attributes a block may bind (get_block_bindings_supported_attributes). @return list<string>

@return list<string>
staticvalues(Minn\Blocks\Block $block, array $context): array#

The bound attributes' values for a block about to render, as the sources answer them for a WP_Block made with the context given (each source also seeing the context it uses); the expanded bindings ride along under metadata for a pattern-overrides default. Empty when nothing is bound or nothing answered.

$contextarray<string, mixed>
@return array<string, mixed>
statichtml(string $html, string $blockName, array $values): string#

A static block's HTML with the bound values in place, by its type's attribute definitions: rich text and html replace what the selected element holds; an attribute source sets the selected element's attribute; anything else is left alone.

$valuesarray<string, mixed>

Internals 4

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

privateinner(string $html, array $selectors, string $value): string#

What the first element matching a selector holds (the block's first element counts), replaced. @param list<string> $selectors

$selectorslist<string>
privateclosing(string $html, string $tag, int $from): ?int#

Where the element opened before $from closes: the offset of its "</tag", nested ones of the same name skipped.

privateopening(string $name): string#
privateattribute(string $html, string $selector, string $name, mixed $value): string#

The first element matching the selector, with an attribute set to the value.