API / Minn\Content / Menus

Menus final readonly class

Minn\Content\Menus · public/minn/src/Minn/Content/Menus.php · 511 lines

Classic nav_menu terms and nav_menu_item posts. The front uses these when a navigation block has no inner blocks and no wp_navigation post; REST serves the same rows as wp/v2/menus and menu-items.

Constants and properties

privatereadonly Minn\Db $db

Promoted from the constructor.

privatereadonly Minn\Content\Posts $posts

Promoted from the constructor.

privatereadonly Minn\Content\Terms $terms

Promoted from the constructor.

privatereadonly Minn\Front\Permalinks $permalinks

Promoted from the constructor.

privatereadonly ?Minn\Content\PostWriter $writer

Promoted from the constructor.

privatereadonly ?Minn\Content\Site $site

Promoted from the constructor.

Public

new__construct(Minn\Db $db, Minn\Content\Posts $posts, Minn\Content\Terms $terms, Minn\Front\Permalinks $permalinks, ?Minn\Content\PostWriter $writer = NULL, ?Minn\Content\Site $site = NULL)#
methodall(): array#

Every nav_menu term.

@return list<TermRecord>
methodfind(int $id): ?Minn\Content\TermRecord#

One menu by id, or null.

methodidByName(string $name): ?int#

The id of the menu with exactly this name, or null.

methoditems(?int $menuId = NULL): array#

The items of one menu, or of every menu, in menu order.

@return list<MenuItem>
methodfallbackBlocks(): array#

Navigation-link blocks for the first classic menu. Empty when the site has no nav_menu terms with items.

@return list<Block>
methodtoBlock(Minn\Content\MenuItem $item): Minn\Blocks\Block#

A menu item as the navigation block it renders through (its classes: its own, then the menu item ones).

staticlinkAttributes(array $item): array#

A menu item's navigation link attributes, as the reference writes them for a menu turned into blocks (probe navigation-blocks): its classes joined, its description, the object it links to (none for a custom link) and that object's kind, its title as the label, a new tab for a _blank target, its XFN as rel, its attribute title, its URL.

$itemarray<string, mixed>a menu item's fields, by their WordPress names
@return array<string, mixed>
methodautoAdd(int $menuId): bool#

Whether this menu auto-adds new top-level pages, from the nav_menu_options blob.

methodlocationsFor(int $menuId): array#

Location slugs from the active theme's theme_mods that point at this menu.

@return list<string>
methodthemeLocations(): array#

The theme's registered locations mapped to menu ids, from theme_mods.

@return array<string, int> location => menu term id
methodfindItem(int $id): ?Minn\Content\MenuItem#

One nav_menu_item by id, or null when it is missing or trashed.

methodrefuseName(string $name, int $keeping = 0): ?Minn\Runtime\Refusal#

Whether a name may be given to a menu. A menu keeps its own name; any other menu holding it refuses the write, and the refused id rides along so a caller can point at the menu in the way.

methodcreateItem(array $fields): int#

title: string, url: string, type: string, object: string, objectId: int, parent: int, menuOrder: int, target: string, status: string, menuId: int, attrTitle: string, description: string, authorId: int, classes?: list<string>, xfn?: string } $fields

methodupdateItem(int $id, array $fields): void#

Applies the given fields to one item, stored the way the reference stores them.

$fieldsarray<string, mixed>
methoditemsPointingAt(int $objectId, string $type): array#

The ids of the menu items, in any menu or none, that point at an object of a kind (post_type, taxonomy). @return list<int>

@return list<int>
methodappendPage(int $menuId, int $pageId, int $authorId): int#

Adds a page to the end of a menu, titled by the page itself, as a menu set to add new pages takes it.

Internals 10

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

privatehydrate(array $row, ?int $knownMenuId): Minn\Content\MenuItem#
$rowarray<string, mixed>
privatemeta(int $postId): array#
@return array<string, string>
privatemenuIdOf(int $itemId): int#
privateclassList(?string $blob): array#
@return list<string>
privatexfnList(?string $blob): array#
@return list<string>
privatewriteMeta(int $id, array $meta): void#

The item's _menu_item_* meta, as the reference keeps it (the classes a list; no title attribute, which is the excerpt).

$metaarray<string, string|list<string>>
privateoriginalParent(string $type, string $object, int $objectId): int#

What an item stores as its parent post: the parent of the post or term it points at.

privatecontent(string $type, string $title, string $description): string#

An item's content: its description, or a space for an item that names nothing of its own (as the reference keeps one).

privatewriter(): Minn\Content\PostWriter#
privatesite(): Minn\Content\Site#