API / Minn\Blocks / RenderState

RenderState final class

Minn\Blocks\RenderState · public/minn/src/Minn/Blocks/RenderState.php · 350 lines

Per-request rendering state, owned by the renderer. The reference numbers galleries, style variations, and search inputs from ONE counter that runs across every block rendered in the request (a list response keeps counting from post to post), so the counter lives here, not on any block. Leaf helpers with no renderer in hand reach it through current().

Constants and properties

constMAX_DEPTH = 64
privateint $counter
privateint $images
privatebool $priorityClaimed
privatearray $blocks
privatearray $galleries
privateint $elements
privatearray $active
privateint $depth
privateint $navigation
privatebool $rootPaddingAware

Whether the theme's layout puts root padding in custom properties; render configuration, so reset() leaves it.

privatebool $blockGap

Whether the theme writes block gaps (settings.spacing.blockGap); render configuration too.

privatebool $directives

What interactivity_process_directives last answered, for the block rendering now.

privatestatic ?self $offRequest

The state for code that renders with no request behind it: the command line and the unit suite.

private?string $pendingElements

the element class claimed for the dynamic block being rendered, until its wrapper takes it

private?string $pendingVariation

the numbered style variation class claimed for the dynamic block being rendered, until its wrapper takes it

privatearray $labels
privatearray $contentImages

Public

staticcurrent(): self#

The state of the request being rendered, which its runtime holds, so a request cannot count on from the one before it. Rendering with no runtime (the command line, the unit suite) shares one off-request state instead, since the counters have to survive between calls.

methodadopt(): void#

Makes this the state current() answers with, for the renderer that brought its own.

methodrootPaddingAware(): bool#

Whether the theme puts root padding in custom properties, which decides the constrained layout's classes.

methoduseRootPadding(bool $aware): void#

Records what the active theme's layout settings say about root padding.

methodblockGap(): bool#

Whether the theme writes block gaps, which decides whether a layout's gap makes CSS.

methoduseBlockGap(bool $writes): void#

Records whether the active theme's spacing settings write block gaps.

methodnextId(): int#

The next per-request counter value.

methodcountImages(int $amount): int#

Adds to the page's count of content images (wp_increase_content_media_count) and returns the new count.

methodnextImage(): int#

Content images seen so far in this page, for the loading rules.

methodrefundImages(int $count, bool $priority): void#

Images a plugin's block filter removed from the page give their budget back, so the next image still counts as if the hidden ones never rendered.

methodaside(Closure $render): mixed#

Runs rendering whose images do not count toward the page's loading budget (an excerpt's): the reference fits no image while it makes one, so whatever was seen meanwhile is given back.

$render\Closure(): T
methodfilteringContent(string $content, Closure $filter): mixed#

$filter run while the_content filters content the engine rendered: the images it already holds count as fitted out, so only what the filter's other callbacks add is fitted (fittedImage()).

methodfittedImage(string $tag): bool#

Whether an image tag is one the content being filtered held when the filter began.

methodclaimPriority(): bool#

True once, for the image that gets fetchpriority="high".

methodpriorityAvailable(): bool#

Whether no element has taken high fetch priority yet on this page.

methodclosePriority(): void#

Takes high fetch priority off the table for the rest of the page; a plugin prioritising its own element does this.

methodreopenPriority(): void#

Puts high fetch priority back on offer, so the next large enough image takes it.

methodrecordBlock(string $blockName): void#

Every block name the page rendered; the stylesheet prints block styles for these only.

methodblocks(): array#

The block names rendering met.

@return array<string, true>
methodnextElements(): int#

The next wp-elements-N class; the reference numbers these apart from the shared counter.

methoduniqueLabel(string $label): string#

A navigation's aria-label: the label itself the first time, then "label N" for repeats.

methodenterNavigation(): void#

A page list renders plain on its own and takes the navigation block's item classes, submenu toggles, and interactivity only while it sits inside one, so the navigation block marks the span it owns.

methodleaveNavigation(): void#

Leaves a navigation block.

methodprocessesDirectives(?bool $answer = NULL): bool#

Whether the block rendering now has its Interactivity API directives processed, as interactivity_process_directives answered for it.

methodinNavigation(): bool#

Whether rendering is inside a navigation block.

methodenter(string $key): bool#

Marks a nested source as being rendered; false when it is already open (a cycle).

methodleave(string $key): void#

Leaves a cycle-guarded key.

methodinside(string $key): bool#

Whether a key is open: a source being rendered, or the page template ("template").

methoddescend(): bool#

True while the block tree is shallower than the cap; deeper blocks render as nothing.

methodascend(): void#

Leaves one nesting level.

methoddepth(): int#

How deep the block tree is right now; zero outside any block render.

methodsetPendingElements(?string $class): ?string#

A dynamic block claims its element class before rendering, so a block that renders nothing still counts.

methodtakePendingElements(): ?string#

The pending elements class, cleared.

methodsetPendingVariation(?string $class): ?string#

Holds the numbered style variation class a dynamic block claimed before rendering; returns the one it replaces.

methodtakePendingVariation(): ?string#

The numbered style variation class the dynamic block being rendered claimed, once: its wrapper takes it.

methodrecordGallery(int $instance): void#

Notes a gallery instance.

methodgalleries(): array#

The gallery instances rendering met.

@return list<int>
methodreset(): void#

Clears every per-request counter.