API / Minn\Rest / BlockRendererController

BlockRendererController final readonly class

Minn\Rest\BlockRendererController · public/minn/src/Minn/Rest/BlockRendererController.php · 89 lines

wp/v2/block-renderer as the reference answers it (probe rest-block-renderer), the route the editor's ServerSideRender asks: a dynamic block rendered from the attributes sent (query or body), checked against the block's own attributes and filled in with their defaults, inside the post named by post_id when there is one (it becomes the global post, and the block's postId and postType context). Only the edit context is accepted, and asking for none is asking for the view context, which is refused, as on the reference. Arguments are judged before the caller: someone who can edit posts may render, or edit the post named.

Used by 1

Constants and properties

privateARGS = array ( 'context' => array ( 'description' => 'Scope under which the request is made; determines fields present in response.', 'type' => 'string', 'enum' => array ( 0 => 'edit', ), 'default' => 'view', 'required' => false, 'handler_validates' => true, ), 'attributes' => array ( 'description' => 'Attributes for the block.', 'type' => 'object', 'default' => array ( ), 'required' => false, 'handler_validates' => true, ), 'post_id' => array ( 'description' => 'ID of the post context.', 'type' => 'integer', 'required' => false, ), )
privatereadonly Minn\Rest\Schema $schema

Promoted from the constructor.

privatereadonly Minn\Rest\Caller $caller

Promoted from the constructor.

Public

new__construct(Minn\Rest\Schema $schema, Minn\Rest\Caller $caller)#
methodrender(Minn\Http\Request $request, string $name): Minn\Http\ResponseGET /wp/v2/block-renderer/{name:[a-z0-9-]+/[a-z0-9-]+} (public)POST /wp/v2/block-renderer/{name:[a-z0-9-]+/[a-z0-9-]+} (public)#

The block's markup, as {"rendered": "..."}.

Internals 3

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

privaterefuseInvalid(array $args): void#
$argsarray<string, array{0: mixed, 1: array<string, mixed>}>value and schema by name
privatepermit(int $postId): void#

Someone who can edit posts may render; with a post named, someone who can edit that post.

privaterendered(Minn\Objects\BlockType $type, array $attributes, int $postId): string#

The block rendered on its own, inside the post when one is named (the global post put back after). @param array<string, mixed> $attributes

$attributesarray<string, mixed>