API / Minn\Rest / TemplateRevisionsController

TemplateRevisionsController final readonly class

Minn\Rest\TemplateRevisionsController · public/minn/src/Minn/Rest/TemplateRevisionsController.php · 197 lines

wp/v2/templates and wp/v2/template-parts revisions and autosaves: the revision rows of a template the site saved, each shown as the template it once was (the template's own shape, its parent's id, a self link and a parent link). The template is judged before the caller, as on the reference: one nobody saved is no parent, one only a theme file holds cannot have revisions; then the caller must be signed in and able to edit the saved row. The routes are listed ahead of the templates' own, whose id pattern would take these paths too.

Used by 1

Constants and properties

privateID = '([^\\/:<>\\*\\?"\\|]+(?:\\/[^\\/:<>\\*\\?"\\|]+)?)[\\/\\w%-]+'
privateREAD_REFUSAL = 'Sorry, you are not allowed to view revisions of this post.'
privateAUTOSAVES_REFUSAL = 'Sorry, you are not allowed to view autosaves of this post.'
privateDELETE_REFUSAL = 'Sorry, you are not allowed to delete revisions of this post.'
privateMANAGE_REFUSAL = 'Sorry, you are not allowed to access the templates on this site.'
privatereadonly Minn\Theme\TemplateIndex $index

Promoted from the constructor.

privatereadonly Minn\Rest\TemplateObject $object

Promoted from the constructor.

privatereadonly Minn\Content\Revisions $revisions

Promoted from the constructor.

privatereadonly Minn\Rest\RestUrl $url

Promoted from the constructor.

privatereadonly Minn\Rest\Caller $caller

Promoted from the constructor.

Public

new__construct(Minn\Theme\TemplateIndex $index, Minn\Rest\TemplateObject $object, Minn\Content\Revisions $revisions, Minn\Rest\RestUrl $url, Minn\Rest\Caller $caller)#
methodrevisions(Minn\Http\Request $request, string $base, string $parent): Minn\Http\ResponseGET /wp/v2/{base:templates|template-parts}/{parent:([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+}/revisions (public)#

Every revision of a saved template, its autosaves among them, filtered, ordered and paged as the request asks (RevisionCollection).

methodrevision(Minn\Http\Request $request, string $base, string $parent, string $id): Minn\Http\ResponseGET /wp/v2/{base:templates|template-parts}/{parent:([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+}/revisions/{id:[\d]+} (public)#

One revision of a saved template; a revision of another post is a mismatch.

methoddeleteRevision(Minn\Http\Request $request, string $base, string $parent, string $id): Minn\Http\ResponseDELETE /wp/v2/{base:templates|template-parts}/{parent:([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+}/revisions/{id:[\d]+} (public)#

A template's revision deleted for good, answered as it was; never trashed, so without force it is refused. One of another post is not this template's to delete.

methodautosaves(Minn\Http\Request $request, string $base, string $id): Minn\Http\ResponseGET /wp/v2/{base:templates|template-parts}/{id:([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+}/autosaves (public)#

The autosaves of a saved template, every author's, newest first.

methodautosave(Minn\Http\Request $request, string $base, string $parent, string $id): Minn\Http\ResponseGET /wp/v2/{base:templates|template-parts}/{parent:([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+}/autosaves/{id:[\d]+} (public)#

The template's newest autosave, whoever saved it and whichever autosave id is asked for.

methodcreateAutosave(Minn\Http\Request $request, string $base, string $id): Minn\Http\ResponsePOST /wp/v2/{base:templates|template-parts}/{id:([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+}/autosaves (cap edit_posts + edit_theme_options)#

An autosave of a saved template (probe rest-template-autosave): the caller's own draft is saved in place, and published; any other keeps one autosave per author, holding only what the body sends (a field it leaves out is stored empty). The caller is judged before the template. The reply is what was saved, shown as the template, in the edit context.

Internals 3

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

privatereadable(string $base, string $id, string $refusal): Minn\Theme\TemplateRecord#

The saved template, then the caller judged: signed in, and able to edit it.

privatesaved(string $base, string $id): Minn\Theme\TemplateRecord#

The template the id names, refused when there is none or when only a file (or a plugin) provides it.

privateshaped(string $base, Minn\Theme\TemplateRecord $template, Minn\Content\PostRecord $revision, Minn\Rest\Context $context, string $kind): array#

A revision row shown as the template it held: the template's own shape with the revision's content, title, description, author and dates, its parent's id, and links to itself and its template. The embed view has no dates and an empty content.

@return array<string, mixed>