API / Minn\Runtime / BlockFilters

BlockFilters final class

Minn\Runtime\BlockFilters · public/minn/src/Minn/Runtime/BlockFilters.php · 188 lines

The block-level filters plugin code hooks (pre_render_block, render_block_data, render_block, render_block_{name}), applied around the engine's own renderer so a plugin sees every block the page renders, not only the ones it registered.

Constants and properties

constNATIVE_DATA_DONE = array ( 'block_core_gallery_data_id_backcompatibility' => 10, )

The data filters the engine's renderer does itself for a block it renders natively: a gallery's image ids. Element styles and style variations are left to their own filters, which name the classes in the block's className as plugins' later filters read it (probe block-class-stages).

constNATIVE_RENDER_DONE = array ( )

The render filters it does itself: none. The element, layout, style variation and paragraph classes reach the markup at their own filters, as a plugin's earlier filters see it without them (probe block-class-stages).

privatestatic array $parsedFor
privatestatic array $begun

Public

staticactive(): bool#

Whether any block filter is registered.

statictoArray(Minn\Blocks\Block $block): array#

A block as the parsed array plugins receive.

@return array<string, mixed> the parsed-array shape plugin code reads
staticfromArray(array $parsed): Minn\Blocks\Block#

A block from the parsed array plugins hand back.

staticdata(array $parsed, ?object $parent, array $done = array ( )): mixed#

A parsed block through render_block_data, without the callbacks done already (NATIVE_DATA_DONE for a block the engine's renderer renders).

$parsedarray<string, mixed>
$parentobject|nullthe WP_Block rendering it, when there is one
$donearray<string, int|array{0: int, 1: string}>
staticrendered(string $html, array $parsed, ?object $instance, array $done = array ( )): string#

A rendered block through render_block and its per-name filter, without the callbacks done already (NATIVE_RENDER_DONE, with its stand-ins, for a block the engine's renderer renders).

$parsedarray<string, mixed>
$instanceobject|nullthe WP_Block the filters receive
$donearray<string, int|array{0: int, 1: string}>
staticbefore(Minn\Blocks\Block $block, ?Minn\Objects\RenderedBlock $parent, array $done = array ( )): Minn\Blocks\Block|string#

A block about to render, begun as the reference begins it (probe block-instances): one with no parent block (a document's, a part's, a pattern's) is asked pre_render_block, render_block_data and render_block_context with none, then made a WP_Block with the post's context; an inner one is made a WP_Block from what its parent gives its inner blocks first (its type asked get_block_type_uses_context), then asked the three with its parent (the context filter handed the context its type uses), and adopts what they made of it. A short-circuit from pre_render_block, or the block as render_block_data left it.

$donearray<string, int|array{0: int, 1: string}>the data filters done already
staticmade(Minn\Blocks\Block $block, ?Minn\Objects\RenderedBlock $parent): Minn\Blocks\Block#

A block begun as the reference's block list makes one its parent renders without asking the block filters first (a navigation's own items): its WP_Block, with what the parent gives its inner blocks.

staticbegun(Minn\Blocks\Block $block): array#

The WP_Block a block began as and the context render_block_context gave it.

@return array{0: RenderedBlock|null, 1: array<string, mixed>|null}
staticafter(Minn\Blocks\Block $block, string $html, array $done = array ( )): string#

A rendered block through render_block and its per-name filter, with the WP_Block it began as.

$donearray<string, int|array{0: int, 1: string}>the render filters done already

Internals 2

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

privatebegin(Minn\Blocks\Block $block, array $parsed, ?Minn\Objects\RenderedBlock $instance, ?array $context): Minn\Blocks\Block#
$parsedarray<string, mixed>
$contextarray<string, mixed>|null
privatecontext(): array#
@return array<string, mixed> the context render_block() gives a document's top block: the global post's, as get_post() reads it