-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Navigation block: Add an unstable location attribute #32491
Conversation
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.
This PR is pretty good like this. Left two nitpicks.
* @param array $attributes Navigation block attributes. | ||
* @return string HTML markup of a generated Navigation Block. | ||
*/ | ||
function get_classic_navigation_elements( $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 rename get_classic_navigation_elements
to render_classic_location_menu
because that is what the function does, and the getter aspect is not correct. I would also change the signature to include $location
as a parameter since it's a bit opaque otherwise => render_classic_navigation( $location, $attributes ) : mixed {}
; I'd make it return false
for an empty location.
@@ -133,7 +163,7 @@ function render_block_core_navigation( $attributes, $content, $block ) { | |||
} | |||
|
|||
if ( empty( $block->inner_blocks ) ) { | |||
return ''; | |||
return get_classic_navigation_elements( $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.
This code reads "if the block is empty render a classic menu", which is not correct. It should read "if the block is empty and there is an associated classic menu, render that". So, what about this as an option:
- rename
get_classic_navigation_elements
torender_classic_location_menu
- update
render_classic_location_menu
to return false if no location is set - change this to:
if ( empty( $block->inner_blocks ) ) {
$maybe_classic_navigation = render_classic_location_menu( $attributes );
if ( $maybe_classic_navigation ) {
return $maybe_classic_navigation;
}
return '';
}
566b7c3
to
de22b21
Compare
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.
I believe this is a minimal change and it's worth merging like this. We'll see how the location attribute evolves. Also giving the block the power to render a classic menu is a superpower useful for theme migration. 🚢 it.
Was the main problem of #30852 addressed (that it relies on |
@@ -42,6 +42,9 @@ | |||
"isResponsive": { | |||
"type": "boolean", | |||
"default": false | |||
}, | |||
"__unstable__location": { |
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.
It should be __unstableLocation
. Attributes are camel case.
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.
🤦🏻♂️ that's my bad. Will update.
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.
Added #32783 to fix this 🙏🏻
Yes, we're not checking on that anymore, if the location attribute is present we render the menu found in said location using |
return wp_nav_menu( | ||
array( | ||
'theme_location' => $location, | ||
'block_attributes' => $block_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.
This is not needed I think.
Great, thank you for addressing that. 👍 The
I don't think that's the case now, so maybe that could be updated too. |
* @param array $attributes Navigation block attributes. | ||
* @return string|false HTML markup of a generated Navigation Block or false if no location is specified. | ||
*/ | ||
function render_classic_location_menu( $location, $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.
Can we rename this to render_menu_from_location
or something to that effect?
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.
Ah, it should probably be prefixed with gutenberg_
too.
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.
Done here: #32918
Description
This is a simplified version of #30852.
All it does is add an
__unstable__location
attribute to the block and then, if that is set, render a classic menu in its place.This opens some questions about if/how this should be handled in the UI but these can be dealt with in followup PRs if necessary.
How has this been tested?
Screenshots
Types of changes
New feature (non-breaking change which adds functionality)
Checklist:
*.native.js
files for terms that need renaming or removal).