API / Minn\Blocks / Renderer

Renderer final class

Minn\Blocks\Renderer · public/minn/src/Minn/Blocks/Renderer.php · 449 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
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.

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): 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.

$contextarray<string, mixed>
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 6

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#
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.

privateelementsClass(Minn\Blocks\Block $block): ?string#

A core block's wp-elements-N class, its rules recorded, when the engine renders it itself.

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#