Navigation final readonly class
Minn\Blocks\Dynamic\Theme\Navigation · public/minn/src/Minn/Blocks/Dynamic/Theme/Navigation.php · 535 lines
navigation, navigation-link, page-list. A navigation block's items come from its inner blocks, the wp_navigation post it references, the newest published wp_navigation post, or (when none of those exist) the first classic nav_menu; a block naming a menu that is gone has none, and no list. A responsive menu wraps them in the overlay markup the reference emits. The nav is labelled by the block's aria label, or the menu's title, made unique in the request; the list carries the aria label as given (probe loose-classes).
Constants and properties
| private | LISTABLE = array ( 0 => 'core/site-title', 1 => 'core/site-logo', 2 => 'core/social-links', ) | The other blocks a navigation lists, each in an li (block_core_navigation_listable_blocks). |
| private | SUBMENU_CONTEXT = '{ "submenuOpenedBy": { "click": false, "hover": false, "focus": false }, "type": "submenu", "modal": null, "previousFocus": null }' | A submenu's interactivity context. |
| private | SUBMENU_TOGGLE = 'data-wp-bind--aria-expanded="state.isSubmenuOpen" data-wp-on--click="actions.toggleMenuOnClick"' | |
| const | CHEVRON = '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true" focusable="false"><path d="M1.50002 4L6.00002 8L10.5 4" stroke-width="1.5"></path></svg>' | The submenu toggle's chevron (block_core_navigation_link_render_submenu_icon). |
| private | CLOSE_ICON = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><path d="M13 11.8l6.1-6.3-1.1-1-6.1 6.2-6.1-6.2-1.1 1 6.1 6.3-6.5 6.7 1.1 1 6.5-6.6 6.5 6.6 1.1-1z" /></svg>' | |
| private | readonly Minn\Db $db | Promoted from the constructor. |
| private | readonly Minn\Content\Posts $posts | Promoted from the constructor. |
| private | readonly Minn\Front\Permalinks $permalinks | Promoted from the constructor. |
| private | readonly ?Minn\Content\Menus $menus | Promoted from the constructor. |
Public
| new | __construct(Minn\Db $db, Minn\Content\Posts $posts, Minn\Front\Permalinks $permalinks, ?Minn\Content\Menus $menus = NULL)# | |
| static | submenuDirectives(string $visibility): array# | The attributes an item with a submenu takes, in the reference's order: its context, the focus and key handlers, the hover ones for a submenu that opens on hover, the init watcher, and its tab index. @return array<string, string> |
| method | register(Minn\Blocks\Renderer $renderer): void# | Registers this family's blocks with the renderer. |
Internals 22
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | wiring(string $visibility): string# | The submenu directives as attribute markup, a space after them. | |||
| private | navigation(Minn\Blocks\Block $block, Minn\Blocks\Renderer $renderer): string# | ||||
| private | responsive(string $nav, string $label, string $list, int $id, bool $hasIcon, string $colors): string# | The overlay form of the menu: the open button, the modal container the interactivity runtime drives, the close button, and the list inside. Whitespace matches the reference's template byte for byte. | |||
| private | items(array $items, Minn\Blocks\Renderer $renderer): string# | The menu's items. Link-shaped blocks render as their own list items; any other block is wrapped in a plain item.
| |||
| private | groups(array $items, Minn\Blocks\Renderer $renderer, string $open): string# | The navigation's items as the reference lays them out (probe hook-inputs-2): the blocks block_core_navigation_listable_blocks names are wrapped in an li; each run of items whose markup holds an li (links, submenus, a page list, a plugin's own list items) is a list of its own; any other block stands between the runs as it renders, and an item that renders nothing ends a run.
| |||
| private | filteredItems(array $items): array# | The items as block_core_navigation_render_inner_blocks leaves them, handed to a plugin as the WP_Block_List the reference renders.
@return list<Block> | |||
| private | linkedPosts(array $items): array# | The posts the items link to, submenus' too, read in one query before each link asks for its own.
@return list<int> | |||
| private | weighLinks(array $items): void# |
| |||
| private | linkable(Minn\Blocks\Block $block, int $id): bool# | Whether a link to a post renders: the post is there with a status render_block_core_navigation_link_allowed_post_status allows (publish), asked with the link's attributes and its block. | |||
| private | presetClasses(Minn\Blocks\Block $block): array# | @return list<string> the colour and font-size preset classes the block's attributes declare | |||
| private | overlayColors(Minn\Blocks\Block $block): string# | The overlay's colour classes, from the overlay* attributes. | |||
| private | link(Minn\Blocks\Block $block, Minn\Blocks\Renderer $renderer): string# | ||||
| private | submenu(Minn\Blocks\Block $block, Minn\Blocks\Renderer $renderer): string# | A submenu: its link (a button, when the navigation opens submenus on click) and its items. Inside a navigation it carries the toggle and the Interactivity API wiring the navigation's settings ask for; on its own it is a plain item. | |||
| private | overlayClose(Minn\Blocks\Block $block): string# | The overlay's close button: an icon (named by aria-label), its text, or both. | |||
| private | classicItems(): array# | @return list<Block> | |||
| private | pageList(Minn\Blocks\Block $block, Minn\Blocks\Renderer $renderer): string# | ||||
| private | submenuColours(array $nav): array# | A page list's submenu items wear the navigation's overlay colours: a named one as its classes, a custom one as has-* and an inline style.
@return array{0: string, 1: string} the classes, each led by a space, and the style attribute | |||
| private | ancestorsOf(array $tree, int $currentId): array# | @return list<int> the ids of the current page's ancestors | |||
| private | pageItems(array $tree, int $parent, int $currentId, array $ancestors, array $submenuColors): string# | A page list dresses its items as navigation items only while it is rendering inside a navigation block: submenu toggles, the item classes, and the interactivity directives all belong to the nav. On its own (wp/v2/navigation serves one that way) the reference emits plain list items and a bare submenu list. Submenu items wear the navigation's overlay colours (submenuColours()).
| |||
| private | navParent(array $page, string $marker, string $home, string $link, string $children): string# |
| |||
| private | menuPost(int $ref): array# | The menu a navigation shows, and whether it is the one the block names. Only a published menu shows, as on the reference: a named menu that is not published (a draft, private or trashed one) gives way to the latest published menu, unlabelled; a named menu that does not exist shows nothing; with none named, the latest published menu. @return array{0: array<string, mixed>|null, 1: bool} | |||
| private | enqueueView(): void# | Interactive navigation markup brings the block's view module with it, as on the reference. |
Nothing matches.