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.
Constants and properties
| const | SUPPORTED = 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
| static | supported(string $name): array# | The attributes a block may bind (get_block_bindings_supported_attributes). @return list<string> @return list<string> | |||
| static | values(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.
@return array<string, mixed> | |||
| static | html(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.
|
Internals 4
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | inner(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
| |||
| private | closing(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. | |||
| private | opening(string $name): string# | ||||
| private | attribute(string $html, string $selector, string $name, mixed $value): string# | The first element matching the selector, with an attribute set to the value. |
Nothing matches.