-
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: Explore using Walker_Nav_Menu #18071
Conversation
Have we considered saving navigation block data in the proper post types? Is that something Gutenberg is even capable of? It seems like re-using Core's built-in menu post types would alleviate many of these workarounds. |
Without using Core's |
bbef080
to
0d2d0e0
Compare
'text_css_classes' => '', | ||
'text_inline_styles' => '', | ||
'classes' => array(), | ||
'style' => '', | ||
); | ||
|
||
// Background color. | ||
// Background color - has text color. |
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.
super minor: can you change that trash that I left there?
// Background color - has background color CSS class.
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 need to define the name of the attribute used to store the menu item link.
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.
hi :) could you make this PR or another strictly about the walker without the beautification of the customisation code? :)
Would it be possible to add a class to the top-level menu items when they have children? For the Frontend default styles suggested by Shaun (see #18094) we need it for the indicator arrows that show to the right of the menu. In the reference theme Varia the class |
There's no beautification, the data format needs adjustment to fit with
Sure, but really what we should be doing is use
Is there a record of this discussion somewhere that I can read, so I can better understand the rationale behind that decision? |
Props @frontdevde.
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.
The current implementation doesn't respect the menu hierarchy, doesn't pay attention to the nesting.
The following pictures show how the same menu is rendered on master (correct) and how it is done on this PR.
If I'm not mistaken, it's done through a recursive call.
@obenland sorry about the beautification comment I didn't pay attention to the effect of the changes 💯 👍 |
On using a WP_Walker for the navigation menuOne of the roles of the WP_Walker is to allow themes to customise the HTML and classes for the WordPress menus. Is this navigation menu block going to be used to replace the current admin menu building page? If so, then a WP_Walker will be needed to maintain compatibility to old themes. If not, then in a FSE environment there is no reason to have a Walker for anything, as the HTML structure that the block outputs is something that the FSE environment needs to count on, and not be available for change by themes at run time. Just to be very clear, I don't think using a walker to render the navigation menu block is bad. In fact that is how I originally implemented the server side rendering of the navigation block. But then I realised that it is only needed if we'll use it to replace how all the menus are created in WordPress, which might not be the case at all. Also, for FSE ready themes, I believe bringing in CSS frameworks won't be a possibility (another reason for the ability to customize the block's HTML), as both the FSE system and the CSS framework expect a certain HTML structure, and they will conflict. Plus, the navigation block would be the only block that allows interference with its HTML because of rendering with a walker. So just checking what is the right path here, @mtias |
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.
Yeah, unfortunately In my testing I've not experienced any padding/margin changes, could those come from #18094? |
Adding |
I think this experiment is as close as it gets without using Core's menu item post type. That is what we should really be exploring, though. I'm not sure using the Walker makes too much sense without it. I'm going to close this for now, hoping we'll get a chance to add an enhancement layer for WordPress uses of Gutenberg, to better integrate with the existing system. |
Description
Exploratory PR to see what's needed in order to be able to use
Walker_Nav_Menu
to render site navigation menu blocks.See #17194.
How has this been tested?
So far only locally, by setting up a menu block and loading it in the front-end.
Types of changes
New feature.
Checklist: