API / Minn\Rest / MenusController

MenusController final readonly class

Minn\Rest\MenusController · public/minn/src/Minn/Rest/MenusController.php · 305 lines

wp/v2/menus, menu-items, and menu-locations. Viewing needs edit_posts; writes need edit_theme_options. Anonymous callers get 401.

Used by 1

Constants and properties

privateNEW_ITEM = array ( 'menu-id' => 0, 'menu-item-db-id' => 0, 'menu-item-object-id' => 0, 'menu-item-object' => '', 'menu-item-parent-id' => 0, 'menu-item-position' => 1, 'menu-item-type' => 'custom', 'menu-item-title' => '', 'menu-item-url' => '', 'menu-item-description' => '', 'menu-item-attr-title' => '', 'menu-item-target' => '', 'menu-item-classes' => '', 'menu-item-xfn' => '', 'menu-item-status' => 'publish', )

The arguments a new item starts from, as the reference's REST controller prepares them.

privatereadonly Minn\Content\Menus $menus

Promoted from the constructor.

privatereadonly Minn\Rest\MenuObject $menuObject

Promoted from the constructor.

privatereadonly Minn\Rest\MenuItemObject $itemObject

Promoted from the constructor.

privatereadonly Minn\Rest\Caller $caller

Promoted from the constructor.

privatereadonly Minn\Rest\RestUrl $url

Promoted from the constructor.

Public

new__construct(Minn\Content\Menus $menus, Minn\Rest\MenuObject $menuObject, Minn\Rest\MenuItemObject $itemObject, Minn\Rest\Caller $caller, Minn\Rest\RestUrl $url)#
methodlistMenus(Minn\Http\Request $request): Minn\Http\ResponseGET /wp/v2/menus (cap edit_posts; or anyone, when rest_menu_read_access opens it)#

Every classic menu.

methodsingleMenu(Minn\Http\Request $request, string $id): Minn\Http\ResponseGET /wp/v2/menus/{id:[\d]+} (cap edit_posts; menu {id} must exist; or anyone, when rest_menu_read_access opens it)#

One menu.

methodcreateMenu(Minn\Http\Request $request): Minn\Http\ResponsePOST /wp/v2/menus (cap edit_theme_options)#

Creates a menu.

methodupdateMenu(Minn\Http\Request $request, string $id): Minn\Http\ResponsePOST /wp/v2/menus/{id:[\d]+} (cap edit_theme_options; menu {id} must exist)PUT /wp/v2/menus/{id:[\d]+} (cap edit_theme_options; menu {id} must exist)PATCH /wp/v2/menus/{id:[\d]+} (cap edit_theme_options; menu {id} must exist)#

Renames or re-describes a menu.

methoddeleteMenu(Minn\Http\Request $request, string $id): Minn\Http\ResponseDELETE /wp/v2/menus/{id:[\d]+} (cap edit_theme_options; menu {id} must exist)#

Deletes a menu and its items.

methodlistItems(Minn\Http\Request $request): Minn\Http\ResponseGET /wp/v2/menu-items (cap edit_posts; or anyone, when rest_menu_read_access opens it)#

The items of a menu.

methodsingleItem(Minn\Http\Request $request, string $id): Minn\Http\ResponseGET /wp/v2/menu-items/{id:[\d]+} (cap edit_posts; menu item {id} must exist; or anyone, when rest_menu_read_access opens it)#

One menu item.

methodcreateItem(Minn\Http\Request $request): Minn\Http\ResponsePOST /wp/v2/menu-items (cap edit_theme_options)#

Creates a menu item.

methodupdateItem(Minn\Http\Request $request, string $id): Minn\Http\ResponsePOST /wp/v2/menu-items/{id:[\d]+} (cap edit_theme_options; menu item {id} must exist)PUT /wp/v2/menu-items/{id:[\d]+} (cap edit_theme_options; menu item {id} must exist)PATCH /wp/v2/menu-items/{id:[\d]+} (cap edit_theme_options; menu item {id} must exist)#

Updates a menu item.

methoddeleteItem(Minn\Http\Request $request, string $id): Minn\Http\ResponseDELETE /wp/v2/menu-items/{id:[\d]+} (cap edit_theme_options; menu item {id} must exist)#

Deletes a menu item.

methodlocations(Minn\Http\Request $request): Minn\Http\ResponseGET /wp/v2/menu-locations (cap edit_theme_options; or anyone, when rest_menu_read_access opens it)#

The menu locations the theme and plugins register (none for a block theme without plugins), keyed by name; edit_theme_options to view.

methodoneLocation(Minn\Http\Request $request, string $location): Minn\Http\ResponseGET /wp/v2/menu-locations/{location:[\w-]+} (cap edit_theme_options; or anyone, when rest_menu_read_access opens it)#

One menu location.

Internals 6

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

privatelocationItem(string $name, string $description): array#

A location, the menu assigned to it (0 for none), and links to it and its menu when that exists. @return array<string, mixed>

@return array<string, mixed>
privateargsFrom(array $body, array $args): array#

The request's item fields as the reference's menu-item-* save arguments, over the ones given.

$bodyarray<string, mixed>
$argsarray<string, mixed>
@return array<string, mixed>
privatetitleFrom(array $body): string#
$bodyarray<string, mixed>
privateurlFrom(array $body): string#
$bodyarray<string, mixed>
privaterefuse(?Minn\Runtime\Refusal $refusal): void#

A refused menu name, in the shape the reference's REST error carries.

privateplain(string $value): string#