API / Minn\Rest / Embed

Embed final class

Minn\Rest\Embed · public/minn/src/Minn/Rest/Embed.php · 264 lines

The _embed decoration and the embed context. Every embeddable link in an object's _links is answered in-process as the same caller with context=embed and placed under _embedded[rel], an error as the error itself; a rel whose every embed came back empty is left out, while an empty list beside a full one stays (wp:term keeps its empty tags list next to the categories). Lists have _fields applied per item before the links are read, so a _fields value without _links embeds nothing there; a single object embeds first and is filtered afterwards. The embed context is the view object cut to the reference's key set for that kind of item.

Constants and properties

privateKEYS = array ( 'post' => array ( 0 => 'id', 1 => 'date', 2 => 'slug', 3 => 'type', 4 => 'link', 5 => 'title', 6 => 'excerpt', 7 => 'author', 8 => 'featured_media', 9 => '_links', ), 'media' => array ( 0 => 'id', 1 => 'date', 2 => 'slug', 3 => 'type', 4 => 'link', 5 => 'title', 6 => 'author', 7 => 'featured_media', 8 => 'caption', 9 => 'alt_text', 10 => 'media_type', 11 => 'mime_type', 12 => 'media_details', 13 => 'source_url', 14 => '_links', ), 'user' => array ( 0 => 'id', 1 => 'name', 2 => 'url', 3 => 'description', 4 => 'link', 5 => 'slug', 6 => 'avatar_urls', 7 => '_links', ), 'term' => array ( 0 => 'id', 1 => 'link', 2 => 'name', 3 => 'slug', 4 => 'taxonomy', 5 => '_links', ), 'comment' => array ( 0 => 'id', 1 => 'parent', 2 => 'author', 3 => 'author_name', 4 => 'author_url', 5 => 'date', 6 => 'content', 7 => 'link', 8 => 'type', 9 => 'author_avatar_urls', 10 => '_links', ), 'menu-item' => array ( 0 => 'id', 1 => 'title', 2 => 'status', 3 => 'url', 4 => 'attr_title', 5 => 'description', 6 => 'type', 7 => 'type_label', 8 => 'object', 9 => 'object_id', 10 => 'parent', 11 => 'menu_order', 12 => 'target', 13 => 'classes', 14 => 'xfn', 15 => 'invalid', 16 => '_links', ), )
privateTYPE_KEYS = array ( 'wp_navigation' => array ( 0 => 'status', 1 => 'content', ), 'wp_block' => array ( 0 => 'wp_pattern_sync_status', ), )

The keys a post type shows in embed beyond a post's (probe: each type's list in the embed context).

privatearray $cache
privatereadonly Minn\Http\Router $router

Promoted from the constructor.

privatereadonly Minn\Rest\Types $types

Promoted from the constructor.

privatereadonly Minn\Rest\Taxonomies $taxonomies

Promoted from the constructor.

Public

new__construct(Minn\Http\Router $router, Minn\Rest\Types $types, Minn\Rest\Taxonomies $taxonomies)#
staticrequested(array $query): ?array#

Null when _embed is absent; [] for every rel; otherwise the rels asked for. @return ?list<string>

@return ?list<string>
methoddecorate(Minn\Http\Request $request, Minn\Http\Response $response): Minn\Http\Response#

Decorates a finished response: the embed context, then _embedded, then the deferred _fields.

methodembedded(Minn\Http\Request $request, array $item, array $rels): array#

A response's data with its embeddable links answered (the runtime's WP_REST_Server::embed_links): every rel when none is named.

$itemarray<string, mixed>@param list<string> $rels
@return array<string, mixed>
statichalves(Minn\Content\PostRecord $p, array $object): array#

A post's view object with the nested halves its type's embed shows: a navigation post's title and content keep their raw halves and the content its block version, for any caller; a pattern's title, which has only a raw half, shows empty.

$objectarray<string, mixed>
@return array<string, mixed>
staticshape(string $type, array $item): array#

An item cut to the embed shape of its object type (a post type, a taxonomy, attachment, user or comment); any other kept whole. @param array<string, mixed> $item @return array<string, mixed>

$itemarray<string, mixed>@return array<string, mixed>

Internals 7

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

privatedecorateItem(Minn\Http\Request $request, array $item, ?array $rels, ?string $kind, ?string $type = NULL): array#
$rels?list<string>
privateanswer(Minn\Http\Request $request, string $href): ?array#

The linked object in embed context; an error answer as the error itself (probe rest-server-methods); null when nothing came back.

privatetarget(string $href): array#

A REST href in either URL form, as the route path and its query. @return array{0: string, 1: array<string, string>}

@return array{0: string, 1: array<string, string>}
privatekind(string $path): ?string#

Which key set a route's objects take in embed context; null for routes without one.

privatetypeAt(string $path): ?string#

The post type a wp/v2 path serves, so the embed shape holds when _fields leaves out the item's type.

privatetaxonomyBase(string $base): bool#
privatecontext(string $kind, array $object, ?string $pathType = NULL): array#

The embed shape, with the fields plugin code registered for the item's type to show in embed.