-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(Optionally) rendering classic navigation data source in Navigation B… #30852
Changes from all commits
9567968
1d0e4c6
7f4d146
8decddd
0cb51ac
26d665a
2046285
c96541d
e56e59b
a4cdf72
30b12aa
b9147cb
71be90c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,41 @@ function block_core_navigation_build_css_font_sizes( $attributes ) { | |
return $font_sizes; | ||
} | ||
|
||
/** | ||
* Renders a Navigation Block derived from data from the theme_location assigned | ||
* via the block attribute 'location'. | ||
* | ||
* If the theme doesn't explicity support 'block-nav-menus' or no location was provided | ||
* as a block attribute then an empty string is returned. | ||
* | ||
* @param array $attributes Navigation block attributes. | ||
* @return string HTML markup of a generated Navigation Block. | ||
*/ | ||
function get_classic_navigation_elements( $attributes ) { | ||
|
||
if ( ! current_theme_supports( 'block-nav-menus' ) ) { | ||
return ''; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the role of checking for this here? The expected use of this supports is kind of the opposite, as here the result is rendering a classic menu, while the supports is meant to enable rendering of a block menu. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The purpose isn't to render a classic menu, the purpose is to render a BLOCK menu with a classic data source. That flag ensures that what comes out of the call to render the menu is navigation block markup. Ideally it would be preferred to not require that theme supports and simply (in this situation) ALWAYS render block markup. But this was the cleanest path to done at the moment. |
||
|
||
if ( ! array_key_exists( 'location', $attributes ) ) { | ||
return ''; | ||
} | ||
|
||
$block_attributes = $attributes; | ||
unset( $block_attributes['location'] ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't follow the swapping values and the unset. It's probably related to the updates in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When crafting a Navigation Block that leverages a classic navigation data source you will still be able to apply stylistic attributes (justification, font size, etc). These attributes should be passed in when it actually renders. HOWEVER if the 'location' attribute is set when the rendering is attempted, and there are no menu items to be rendered, the block enters a loop. This ensures that the attributes passed to actually be rendered exclude the 'location' attribute preventing the loop. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like a problem to be fixed in the block then :) |
||
|
||
return wp_nav_menu( | ||
array( | ||
'theme_location' => $attributes['location'], | ||
'block_attributes' => $block_attributes, | ||
'container' => '', | ||
'items_wrap' => '%3$s', | ||
'fallback_cb' => false, | ||
'echo' => false, | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Returns the top-level submenu SVG chevron icon. | ||
* | ||
|
@@ -122,7 +157,7 @@ function render_block_core_navigation( $attributes, $content, $block ) { | |
unset( $attributes['rgbTextColor'], $attributes['rgbBackgroundColor'] ); | ||
|
||
if ( empty( $block->inner_blocks ) ) { | ||
return ''; | ||
return get_classic_navigation_elements( $attributes ); | ||
} | ||
|
||
$colors = block_core_navigation_build_css_colors( $attributes ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could probably just do this inline with the array below?