function gutenberg_build_navigation_menu_html in Gutenberg 8
Walks the inner block structure and returns an HTML list for it.
Parameters
array $block The block.:
array $colors Contains inline styles and CSS classes to apply to menu item.:
Return value
string Returns an HTML list from innerBlocks.
1 call to gutenberg_build_navigation_menu_html()
- gutenberg_render_block_navigation_menu in vendor/
gutenberg/ block-library/ blocks/ navigation-menu.php - Renders the `core/navigation-menu` block on server.
File
- vendor/
gutenberg/ block-library/ blocks/ navigation-menu.php, line 96
Code
function gutenberg_build_navigation_menu_html($block, $colors) {
$html = '';
foreach ((array) $block['innerBlocks'] as $key => $menu_item) {
$html .= '<li class="wp-block-navigation-menu-item ' . $colors['bg_css_classes'] . '"' . $colors['bg_inline_styles'] . '>' . '<a
class="wp-block-navigation-menu-item__link ' . $colors['text_css_classes'] . '"
' . $colors['text_inline_styles'];
// Start appending HTML attributes to anchor tag.
if (isset($menu_item['attrs']['url'])) {
$html .= ' href="' . $menu_item['attrs']['url'] . '"';
}
if (isset($menu_item['attrs']['title'])) {
$html .= ' title="' . $menu_item['attrs']['title'] . '"';
}
if (isset($menu_item['attrs']['opensInNewTab']) && true === $menu_item['attrs']['opensInNewTab']) {
$html .= ' target="_blank" ';
}
// End appending HTML attributes to anchor tag.
// Start anchor tag content.
$html .= '>';
if (isset($menu_item['attrs']['label'])) {
$html .= $menu_item['attrs']['label'];
}
$html .= '</a>';
// End anchor tag content.
if (count((array) $menu_item['innerBlocks']) > 0) {
$html .= gutenberg_build_navigation_menu_html($menu_item, $colors);
}
$html .= '</li>';
}
return '<ul>' . $html . '</ul>';
}