API / Minn\Rest / RevisionsController

RevisionsController final readonly class

Minn\Rest\RevisionsController · public/minn/src/Minn/Rest/RevisionsController.php · 299 lines

wp/v2 revisions under posts, pages, patterns and navigation menus, and autosaves under those and menu items (probes rest-revisions, rest-autosaves). A revision carries the fields its parent's type supports: a navigation menu's its title and content, a menu item's its title alone.

Used by 1

Constants and properties

privateTYPES = array ( 'posts' => 'post', 'pages' => 'page', 'blocks' => 'wp_block', 'navigation' => 'wp_navigation', 'menu-items' => 'nav_menu_item', )

The parents' REST bases and their post types.

privateFIELDS = array ( 'wp_navigation' => array ( 0 => 'title', 1 => 'content', ), 'nav_menu_item' => array ( 0 => 'title', ), )

The fields a revision carries by its parent's type; any other carries title, content and excerpt.

privateDELETE_REFUSAL = 'Sorry, you are not allowed to delete revisions of this post.'
privatereadonly Minn\Content\Posts $posts

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.

privatereadonly ?Minn\Front\Permalinks $permalinks

Promoted from the constructor.

Public

new__construct(Minn\Content\Posts $posts, Minn\Content\Revisions $revisions, Minn\Rest\RestUrl $url, Minn\Rest\Caller $caller, ?Minn\Front\Permalinks $permalinks = NULL)#
methodrevisions(Minn\Http\Request $request, string $base, string $parent): Minn\Http\ResponseGET /wp/v2/{base:posts|pages|blocks|navigation}/{parent:[\d]+}/revisions (cap edit_post on {parent}; post parent {parent} must exist)#

Every revision of the parent, 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:posts|pages|blocks|navigation}/{parent:[\d]+}/revisions/{id:[\d]+} (cap edit_post on {parent}; post parent {parent} must exist)#

One revision of a post, page, or block.

methoddeleteRevision(Minn\Http\Request $request, string $base, string $parent, string $id): Minn\Http\ResponseDELETE /wp/v2/{base:posts|pages|blocks|navigation}/{parent:[\d]+}/revisions/{id:[\d]+} (cap delete_post on {parent}; post parent {parent} must exist)#

A revision deleted for good, answered as it was; never trashed. The reference grants deleting a revision to nobody by default, so a request that passes the parent's check is refused at the revision's.

methodautosaves(Minn\Http\Request $request, string $base, string $id): Minn\Http\ResponseGET /wp/v2/{base:posts|pages|blocks|navigation|menu-items}/{id:[\d]+}/autosaves (cap edit_post on {id}; post parent {id} must exist)#

The autosaves of a post, every author's, in the asked context; the edit view names each one's preview.

methodautosave(Minn\Http\Request $request, string $base, string $parent, string $id): Minn\Http\ResponseGET /wp/v2/{base:posts|pages|blocks|navigation|menu-items}/{parent:[\d]+}/autosaves/{id:[\d]+} (cap edit_post on {parent}; post parent {parent} must exist)#

The parent's newest autosave, whoever saved it and whichever autosave id is asked for; the edit view names its preview.

methodcreateAutosave(Minn\Http\Request $request, string $base, string $id): Minn\Http\ResponsePOST /wp/v2/{base:posts|pages|blocks|navigation|menu-items}/{id:[\d]+}/autosaves (cap edit_post on {id}; post {id} must exist)#

One autosave slot per author; the reply carries a preview link.

methodobject(Minn\Content\PostRecord|array $r, Minn\Rest\Context $context = Minn\Rest\Context::View): array#

One revision row as wp/v2 serves it (autosaves and revisions alike), in the view, edit or embed shape.

Internals 9

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

privateselected(array $object, ?Minn\Rest\Fields $fields): Minn\Http\Response#

One revision or autosave under the request's _fields: its links ride along exactly when the parent field is asked for, as the reference links one to its parent only then (and _links alone shows nothing).

privatedraftObject(Minn\Content\PostRecord $post): array#

A draft saved in place by its autosave, as the reference replies with it: a revision's fields with the post's own parent (linked only when there is one), its own guid, no dates while it floats, and its plain preview link.

privateclean(string $markup): string#
privateembedded(array $object, Minn\Content\PostRecord $record, string $parentType): array#

The embed view of a revision: who, when, which and whose, its title and excerpt; a navigation menu's carries its title and content with their raw halves instead.

$objectarray<string, mixed>
@return array<string, mixed>
privatewithPreviewLink(array $object, int $parent): array#

The autosave POST reply names where to preview the draft, just before its links; a revision never carries it.

privatepreviewLink(int $parent): string#

Where to preview the parent with its autosave: its permalink once published, its plain address before; none for a type that is never viewed (a navigation menu, a menu item).

privatemeta(int $id, string $parentType): array#

A revision's meta: the footnotes, and for a pattern the sync status core revisions too; none for a navigation menu or a menu item.

privaterequireParent(int $parentId, string $base): int#

The revision surfaces are gated on edit_post of the parent.

privateparentOf(int $parentId, string $base): Minn\Content\PostRecord#

The parent, of the type the route's base names, or rest_post_invalid_parent.