API / Minn\Blocks / Renderer

Renderer final class

Minn\Blocks\Renderer · public/minn/src/Minn/Blocks/Renderer.php · 553 lines

Renders a block tree the way the reference renders post_content: delimiters gone, each block's own HTML kept with inner blocks rendered in place, then the per-block render-time additions (layout classes, the paragraph class, image attributes, gallery ids, style-variation counters), and finally texturize over the whole.

Constants and properties

privateCLASSNAME_ALWAYS = array ( 0 => 'core/query-pagination-next', 1 => 'core/query-pagination-numbers', 2 => 'core/query-pagination-previous', )

The dynamic core blocks that ask block_default_classname even when they render nothing (generatedClass()).

privateCLASSNAME_NEVER = array ( 0 => 'core/rss', 1 => 'core/widget-group', 2 => 'core/tabs', 3 => 'core/tab-list', 4 => 'core/tab-panel', 5 => 'core/accordion', 6 => 'core/accordion-item', )

The dynamic core blocks that never ask it (the tabs and accordion blocks edit their saved markup instead).

privatearray $dynamic
privatearray $native
privatebool $unfiltered

Whether the next block renders without the block filters around it (renderNativeUnfiltered()).

privatebool $asCallback

Whether the next block renders as its render callback called alone would (renderNativeAsCallback()).

privatemixed $imageFinish
private?array $handed
private?array $own
private?Minn\Objects\RenderedBlock $handedInstance

The WP_Block the facade renders the next block as (handContext()).

private?Minn\Objects\RenderedBlock $ownInstance

The WP_Block the block that has just started to render began as (ownInstance()).

privatebool $made

Whether the next block is made as its parent's list makes it, without the block filters before it (renderMade()).

privatearray $parents
privatearray $provided
privateMinn\Blocks\Context $context
privateMinn\Blocks\RenderState $state
privatereadonly Minn\Blocks\ImageTags $images

Promoted from the constructor.

Public

new__construct(Minn\Blocks\ImageTags $images)#
staticnumberedStyle(string $blockName, string $className): ?string#

The numbered companion of a block style variation the block's class names (is-style-{name}--N), consuming the counter: a variation with styles of its own, the theme's or a registered style's (the facade answers the private minn_block_style_variation filter), whose CSS the facade prints once numbered (minn_block_style_variation_used). Null when none applies.

methodstate(): Minn\Blocks\RenderState#

The per-request rendering state: counters, containers, variations, the images seen.

methodcontext(): Minn\Blocks\Context#

What is being rendered.

methodwithContext(Minn\Blocks\Context $context): void#

Sets what is being rendered.

methodimages(): Minn\Blocks\ImageTags#

The image tag builder.

staticforDb(Minn\Db $db): self#

A renderer with every dynamic block wired over the database door.

methodregisterDynamic(string $name, callable $render): void#

Registers the engine's own renderer for a dynamic block. A plugin's callback that already took the block over (bridge()) keeps it, as a replaced render callback does on the reference.

$rendercallable(Block, Renderer): string
methodbridge(string $name, callable $render): void#

Hands a block to a plugin's render callback; the engine's own renderer for it stays for renderNative().

$rendercallable(Block, Renderer): string
methodrenderNative(Minn\Blocks\Block $block): string#

One block as HTML through the engine's own renderer for its name (its static markup when it has none), even where a plugin's callback took the block over: what a core render callback gives, so a plugin's callback that calls the one it replaced does not call itself.

methodrender(string $markup): string#

Block markup as HTML, texturized: a document of its own (renderRoots()).

methodrenderBlocks(array $blocks): string#

A tree of blocks as HTML.

$blockslist<Block>
methodrenderNativeUnfiltered(Minn\Blocks\Block $block): string#

A core block as renderNative() renders it, without the block filters around this one block (its inner blocks keep theirs): its caller, the facade's WP_Block::render, applies them once.

methodrenderNativeAsCallback(Minn\Blocks\Block $block): string#

A core block as its render callback called directly renders it: not a block being rendered, so enqueue_empty_block_content_assets is not asked for it (its inner blocks are), as the reference asks it only in a block's render (probe plugin-surface2).

methodfinishImagesWith(callable $finish): void#

What the runtime does to an image block's markup once the engine has rendered it: the lightbox, when the image's settings or the theme's ask for one.

$finishcallable(string, Block): string
methodhandContext(array $context, ?Minn\Objects\RenderedBlock $instance = NULL): void#

The context render_block_context already gave the next block, when render_block() or a WP_Block renders it: a block that provides its own context (a tabs block's id) reads it with ownContext() rather than asking again. The WP_Block is the parent its inner blocks are begun with.

$contextarray<string, mixed>
methodownInstance(): ?Minn\Objects\RenderedBlock#

The WP_Block the block that has just begun to render was made as; null when the block filters did not begin it.

methodrenderRoots(array $blocks): string#

Blocks that begin a document of their own (a pattern's, a part's, a post's content), as do_blocks renders them: no parent block.

$blockslist<Block>
methodunder(?Minn\Objects\RenderedBlock $parent, Closure $render): string#

Renders with a WP_Block of the renderer's making as the parent of the blocks inside (a synced pattern's, a post template's item).

methodrenderItem(array $parsed, array $context, Closure $render): string#

One item of a loop rendered as the reference renders it (a post template's post, a comment template's comment): inside a WP_Block of its own, made from the parsed block given with the context given as all it has, which goes through render_block itself (probe block-instances).

$parsedarray<string, mixed>
$contextarray<string, mixed>
methodrenderMade(Minn\Blocks\Block $block): string#

A block as the reference renders an item of a block list its parent walks itself (a navigation's own items): made from what the parent gives its inner blocks, without pre_render_block, render_block_data or render_block_context before it.

methodownContext(): ?array#

The context render_block_context gave the block that has just begun to render; null when nothing did. A block's renderer reads it first, before its inner blocks begin.

@return array<string, mixed>|null
methodrenderBlock(Minn\Blocks\Block $block): string#

One block as HTML, with the filters around it (unless renderNativeUnfiltered() asked for this one without).

methodblockContext(): array#

The context a block's bindings read: the post being rendered (postId, postType) and what enclosing blocks provide (a synced pattern's overrides).

@return array<string, mixed>
methodproviding(array $context, Closure $render): string#

Renders with context provided to the blocks inside (render_block_context's job on the reference). @param array<string, mixed> $context

$contextarray<string, mixed>
methodrendersNatively(string $name): bool#

Whether the engine's own renderer answers for a block: a core block no plugin's callback took over. It applies the block supports it knows itself (layout, element styles); the facade's render_block filters do the rest, and all of them for any other block.

Internals 8

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

privaterenderWith(string $name, ?callable $render): void#
privatefreeform(Minn\Blocks\Block $block): string#

Text between blocks, through the block filters as do_blocks hands it them (probe block-instances).

privateparent(): ?Minn\Objects\RenderedBlock#

The WP_Block of the block the next one renders inside; null at a document's top.

privategeneratedClass(Minn\Blocks\Block $block, string $html): string#

A dynamic core block's own class through block_default_classname, as the reference asks it while the block takes its wrapper attributes: for a block that renders something (the query pagination links even when they do not; the RSS and widget-group blocks never), and a class a plugin changes replaces the block's on its wrapper.

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

A core block's wp-elements-N class (rules recorded) and numbered style variation, with no block filters about to add them (probe block-class-stages). @return array{0: ?string, 1: ?string}

@return array{0: ?string, 1: ?string}
privaterenderNamed(Minn\Blocks\Block $block, array $bound = array ( )): string#
$boundarray<string, mixed>the bound attributes' values, put into a static block's HTML
privatedecorate(Minn\Blocks\Block $block, string $html, ?string $elements, ?string $numbered): string#
privategallery(): int#