-
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
Navigation block - preserve navigation block data on theme switching #35750
Comments
One problem is that the current implementations of #34612 all associate an instance of a navigation block directly with an instance of a navigation post. That is, the block has a Instead, maybe something more like the current menu system is needed. A theme defines locations (potentially the template part 'areas' are re-used), and the theme developer, when adding a Navigation Block in a template assigns that block to a location. When a user then edits the Navigation Block, the resultant post isn't associated with the instance of the block itself (the block doesn't have a I think this is what #31971 tries to do for template parts, but I'm still trying to understand some of the technical details of that PR. |
Yes, and that attribute should only be used for migration, right? Otherwise it would cramp users of the block editor from putting a navigation block wherever they want, I think. Or would this be a free text attribute? But even so, moving the block from header to footer but leaving the location to "top menu" would be very confusing. There are at least two things about navigation persistence that I try to figure out:
Location discovery: everything in @talldan 's #35750 (comment) for classic to block, plus the block to block problems because we don't have a way to see where a certain Using theme mods (#31971) would allow us to store a relationship between Data migration: when moving from a classic to a block theme, we'll need to copy the classic menu to a block menu and write a Navigation post. But this process is not fully implemented yet as there are classic menu features that are unclear if they can be migrated to blocks (custom fields and custom menu item types). I think an initial path is to discard what is not representable as blocks yet, considering the original classic menu remains untouched? |
Going to start documenting what I'm learning about this topic. Will update this post as I go: Current Menus BehaviourTL;DR
Registration and Rendering
register_nav_menus(
array(
'primary' => 'Primary menu',
'footer' => 'Flibble Wibble menu', // can be anything...see?
)
);
wp_nav_menu(
array(
'theme_location' => 'primary',
)
); This relies on logic for retrieving a menu by its location. Data Storage
Here "primary" is associated with Menu ID Theme Switching Behaviour
Template Areas
|
Desired Behaviour / User StoriesI'm going to document below what I believe are the behaviours we want from navigations when switching Themes. I'm trying to represent these as user stories ( User StoriesUser: website Admin
User: Theme Developer
Terminology
|
Would you elaborate on this one? I don't quite follow.
At the risk of sounding controversial: What are the downsides of migrating and assigning the old menus at "random"? Random could mean that the menu with most items goes to the |
Certainly. What I'm trying to convey is that if it isn't possible to map a Menu Location from the Classic Theme to any of the navigation areas in the new Block Theme, then we need to avoid a completely "broken" experience on the front end of the site. What I'm suggesting is rather than render an empty navigation, we simply render the top 6 Pages on the website as a fallback. We would also surface warning (as described in the other Stories) to the user to alert them to the need to manually configure this Menu.
I feel like heuristics around this could be troubling. I don't think we could extrapolate that because Menu A has more items than Menu B then it deserves to be in location A or B. My idea was that we can consider the two scenarios somewhat differently:
In the former we can start to actively codify new best practices by providing the tools to do so (e.g. standardised default navigation areas plus ability to assign navigations to navigation areas via the UI). This helps to smooth cross Theme transitions. In the later case, we can look to provide the best possible experience (i.e. "best fit" mapping of Menu Locations to navigation areas) whilst still acknowledging we cannot provide the perfect solution given the disparate nature of the existing Menus system. Indeed, in order to mitigate the impact of transition, we should be sure to provide excellent fallback experiences and actively surface potential Menu problems to users via the UI. |
Template parts do already have an 'area' concept of their own (the gutenberg/lib/full-site-editing/template-parts.php Lines 170 to 210 in fd5d963
So maybe when a nav block is within a template part that defines the header, the nav block could automatically assume the 'header' location. There are some problems to think through:
Still a good avenue to explore, I think. |
@getdave this looks like a great summary. Thanks for documenting the classic navigation preservation mechanism 👏🏻 In terms of userstories, maybe they're a little too detailed to start with? The exploration goal is split in two right now:
Then we can dive into how theme building implements this and so on. |
As an initial exploration let's proceed with the following:
|
@adamziel @talldan @getdave: How do you feel about punting this from WP 5.9? Given both #36002 and #36117 are a work in progress, I’m not sure how feasible it is to get this in by Friday. It seems that there's still some exploration to do? I think exploration and iteration is generally best done in the Gutenberg plugin where things aren't rushed. |
@noisysocks I think it's an important feature and I'd say let's keep fighting :-) there's #36178 now that could be it. It misses a few things but @talldan will take it for a spin while I sleep. Let's see how far we can get. |
What problem does this address?
This issue is a follow-up to #34612. Currently, that issue has two PRs exploring solutions, one using template part post types (#35418) and another using a separate
wp_navigation
post type (#35746).When switching themes, it'd be good to try to preserve navigation block menu data. The previously mentioned issue explores saving navigation block data to a post. This would make it possible to retain that data when a user switches themes.
There are some different permutations
a) migrating from a classic menu (associated with a location) to a navigation block in a block-based theme (associated with a template part)
b) migrating between block-based themes
One of the challenges is that in a block-based theme the Nav Block is just rendered in a template part as HTML. It doesn't have the concept of a 'location'. This might be something we need to implement.
The text was updated successfully, but these errors were encountered: