API / Minn\Rest / RevisionsController

RevisionsController final readonly class

Minn\Rest\RevisionsController · public/minn/src/Minn/Rest/RevisionsController.php · 237 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)#

Real revisions, not autosaves.

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.

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 caller's autosave of the parent, 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).

Internals 6

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

privateclean(string $markup): string#
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.