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
| private | readonly Minn\Db $db | Promoted from the constructor. |
| private | readonly Minn\Content\Posts $posts | Promoted from the constructor. |
| private | readonly Minn\Content\Terms $terms | Promoted from the constructor. |
| private | readonly Minn\Front\Permalinks $permalinks | Promoted from the constructor. |
| private | readonly ?Minn\Content\PostWriter $writer | Promoted from the constructor. |
| private | readonly ?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)# | ||||
| method | all(): array# | Every nav_menu term. @return list<TermRecord> | |||
| method | find(int $id): ?Minn\Content\TermRecord# | One menu by id, or null. | |||
| method | idByName(string $name): ?int# | The id of the menu with exactly this name, or null. | |||
| method | items(?int $menuId = NULL): array# | The items of one menu, or of every menu, in menu order. @return list<MenuItem> | |||
| method | fallbackBlocks(): array# | Navigation-link blocks for the first classic menu. Empty when the site has no nav_menu terms with items. @return list<Block> | |||
| method | toBlock(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). | |||
| static | linkAttributes(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.
@return array<string, mixed> | |||
| method | autoAdd(int $menuId): bool# | Whether this menu auto-adds new top-level pages, from the nav_menu_options blob. | |||
| method | locationsFor(int $menuId): array# | Location slugs from the active theme's theme_mods that point at this menu. @return list<string> | |||
| method | themeLocations(): array# | The theme's registered locations mapped to menu ids, from theme_mods. @return array<string, int> location => menu term id | |||
| method | findItem(int $id): ?Minn\Content\MenuItem# | One nav_menu_item by id, or null when it is missing or trashed. | |||
| method | refuseName(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. | |||
| method | createItem(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 | |||
| method | updateItem(int $id, array $fields): void# | Applies the given fields to one item, stored the way the reference stores them.
| |||
| method | itemsPointingAt(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> | |||
| method | appendPage(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.
| private | hydrate(array $row, ?int $knownMenuId): Minn\Content\MenuItem# |
| |||
| private | meta(int $postId): array# | @return array<string, string> | |||
| private | menuIdOf(int $itemId): int# | ||||
| private | classList(?string $blob): array# | @return list<string> | |||
| private | xfnList(?string $blob): array# | @return list<string> | |||
| private | writeMeta(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).
| |||
| private | originalParent(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. | |||
| private | content(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). | |||
| private | writer(): Minn\Content\PostWriter# | ||||
| private | site(): Minn\Content\Site# |
Nothing matches.