API / Minn\Blocks\Dynamic\Theme / Navigation

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

privateLISTABLE = 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).

privateSUBMENU_CONTEXT = '{ "submenuOpenedBy": { "click": false, "hover": false, "focus": false }, "type": "submenu", "modal": null, "previousFocus": null }'

A submenu's interactivity context.

privateSUBMENU_TOGGLE = 'data-wp-bind--aria-expanded="state.isSubmenuOpen" data-wp-on--click="actions.toggleMenuOnClick"'
constCHEVRON = '<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).

privateCLOSE_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>'
privatereadonly Minn\Db $db

Promoted from the constructor.

privatereadonly Minn\Content\Posts $posts

Promoted from the constructor.

privatereadonly Minn\Front\Permalinks $permalinks

Promoted from the constructor.

privatereadonly ?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)#
staticsubmenuDirectives(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>
methodregister(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.

privatewiring(string $visibility): string#

The submenu directives as attribute markup, a space after them.

privatenavigation(Minn\Blocks\Block $block, Minn\Blocks\Renderer $renderer): string#
privateresponsive(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.

privateitems(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.

$itemslist<Block>
privategroups(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.

$itemslist<Block>
privatefilteredItems(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.

$itemslist<Block>
@return list<Block>
privatelinkedPosts(array $items): array#

The posts the items link to, submenus' too, read in one query before each link asks for its own.

$itemslist<Block>
@return list<int>
privateweighLinks(array $items): void#
$itemslist<Block>each link to a post among them, submenus' too, through linkable()
privatelinkable(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.

privatepresetClasses(Minn\Blocks\Block $block): array#
@return list<string> the colour and font-size preset classes the block's attributes declare
privateoverlayColors(Minn\Blocks\Block $block): string#

The overlay's colour classes, from the overlay* attributes.

privatelink(Minn\Blocks\Block $block, Minn\Blocks\Renderer $renderer): string#
privatesubmenu(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.

privateoverlayClose(Minn\Blocks\Block $block): string#

The overlay's close button: an icon (named by aria-label), its text, or both.

privateclassicItems(): array#
@return list<Block>
privatepageList(Minn\Blocks\Block $block, Minn\Blocks\Renderer $renderer): string#
privatesubmenuColours(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.

$navarray<string, mixed>the navigation's context
@return array{0: string, 1: string} the classes, each led by a space, and the style attribute
privateancestorsOf(array $tree, int $currentId): array#
@return list<int> the ids of the current page's ancestors
privatepageItems(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()).

$submenuColorsarray{0: string, 1: string}
privatenavParent(array $page, string $marker, string $home, string $link, string $children): string#
$pagearray<string, mixed>
privatemenuPost(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}
privateenqueueView(): void#

Interactive navigation markup brings the block's view module with it, as on the reference.