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.
Uses 38 (show)
Constants and properties
| private | CLASSNAME_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()). |
| private | CLASSNAME_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). |
| private | array $dynamic | |
| private | array $native | |
| private | bool $unfiltered | Whether the next block renders without the block filters around it (renderNativeUnfiltered()). |
| private | bool $asCallback | Whether the next block renders as its render callback called alone would (renderNativeAsCallback()). |
| private | mixed $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()). |
| private | bool $made | Whether the next block is made as its parent's list makes it, without the block filters before it (renderMade()). |
| private | array $parents | |
| private | array $provided | |
| private | Minn\Blocks\Context $context | |
| private | Minn\Blocks\RenderState $state | |
| private | readonly Minn\Blocks\ImageTags $images | Promoted from the constructor. |
Public
| new | __construct(Minn\Blocks\ImageTags $images)# | |||||||
| static | numberedStyle(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. | ||||||
| method | state(): Minn\Blocks\RenderState# | The per-request rendering state: counters, containers, variations, the images seen. | ||||||
| method | context(): Minn\Blocks\Context# | What is being rendered. | ||||||
| method | withContext(Minn\Blocks\Context $context): void# | Sets what is being rendered. | ||||||
| method | images(): Minn\Blocks\ImageTags# | The image tag builder. | ||||||
| static | forDb(Minn\Db $db): self# | A renderer with every dynamic block wired over the database door. | ||||||
| method | registerDynamic(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.
| ||||||
| method | bridge(string $name, callable $render): void# | Hands a block to a plugin's render callback; the engine's own renderer for it stays for renderNative().
| ||||||
| method | renderNative(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. | ||||||
| method | render(string $markup): string# | Block markup as HTML, texturized: a document of its own (renderRoots()). | ||||||
| method | renderBlocks(array $blocks): string# | A tree of blocks as HTML.
| ||||||
| method | renderNativeUnfiltered(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. | ||||||
| method | renderNativeAsCallback(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). | ||||||
| method | finishImagesWith(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.
| ||||||
| method | handContext(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.
| ||||||
| method | ownInstance(): ?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. | ||||||
| method | renderRoots(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.
| ||||||
| method | under(?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). | ||||||
| method | renderItem(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).
| ||||||
| method | renderMade(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. | ||||||
| method | ownContext(): ?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 | ||||||
| method | renderBlock(Minn\Blocks\Block $block): string# | One block as HTML, with the filters around it (unless renderNativeUnfiltered() asked for this one without). | ||||||
| method | blockContext(): 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> | ||||||
| method | providing(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
| ||||||
| method | rendersNatively(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.
| private | renderWith(string $name, ?callable $render): void# | ||||
| private | freeform(Minn\Blocks\Block $block): string# | Text between blocks, through the block filters as do_blocks hands it them (probe block-instances). | |||
| private | parent(): ?Minn\Objects\RenderedBlock# | The WP_Block of the block the next one renders inside; null at a document's top. | |||
| private | generatedClass(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. | |||
| private | supportClasses(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} | |||
| private | renderNamed(Minn\Blocks\Block $block, array $bound = array ( )): string# |
| |||
| private | decorate(Minn\Blocks\Block $block, string $html, ?string $elements, ?string $numbered): string# | ||||
| private | gallery(): int# |
Nothing matches.