Navigation: Fallback to a classic menu if one is available#44173
Navigation: Fallback to a classic menu if one is available#44173
Conversation
|
Size Change: +3.02 kB (0%) Total Size: 1.27 MB
ℹ️ View Unchanged
|
I don't think this is a problem, as the classic menu would already be showing in the frontend, as the conditions are the same:
|
I completely agree with this too 😄 |
|
I think we should try and only address the most basic use case:
If the website has multiple classic menus we should not do anything. We can come back later with some implementation that matches classic "location" to block template part "slug", but I think this would be more complex. |
|
I've made some changes to this. Now, if there's no wp_navigation CPTs and one classic menu, we convert the classic menu to a wp_navigation CPT, and this becomes the fallback. This happens in both the editor and the frontend. |
There was a problem hiding this comment.
Awesome! The code looks almost there, I left some tweaks. Requesting changes mostly about making sure we maintain the fallback behavior of not dirtying the post on fallback.
Did not test visually yet.
Later edit:, visual testing results:
- The template part ends up dirty upon fallback. As mentioned in code, we should not assign the ref, but allow the fallback to set it marked as
__unstableMarkNextChangeAsNotPersistent. - The import happens multiple times:
- The menu is imported as
draft. Considering this is the only classic menu that exists it's fine to import it aspublished.
| } | ||
| }; | ||
|
|
||
| onSelectClassicMenu( classicMenus[ 0 ] ); |
There was a problem hiding this comment.
I think here we should use the same process that we use for the block menus, that is avoid calling handleUpdateMenu. This call sets the ref and the use sees a dirty post. We should instead just create the block menu, then because it's the latest created it will be handled by the later code.
packages/block-library/src/navigation/edit/use-convert-classic-menu-to-block-menu.js
Show resolved
Hide resolved
|
Thanks for testing @draganescu, I have addressed all the feedback here, so it's ready for another look. |
draganescu
left a comment
There was a problem hiding this comment.
Tested this again after e5f8fb5 and it worked pretty smooth:
- one classic menu resulted in auto importing it and the block theme's empty navigation block used it as a fallback.
3c4e9ea to
5fcf224
Compare
|
I found a bug with this. When you have two navigation blocks on the page they will both try to create a classic navigation, and do so successfully. |
Co-authored-by: Dave Smith <getdavemail@gmail.com>
Co-authored-by: Dave Smith <getdavemail@gmail.com>
77dafd0 to
6249285
Compare
|
@draganescu and I created a solution to prevent menus from importing twice. We'd be grateful for a review. We tried creating a store and then saving state of the import in the store, but the store didn't seem to update fast enough so we still experienced the problem of the import happening twice. This module level variable seems to solve it though... |
packages/block-library/src/navigation/edit/use-convert-classic-menu-to-block-menu.js
Outdated
Show resolved
Hide resolved
packages/block-library/src/navigation/edit/use-convert-classic-menu-to-block-menu.js
Outdated
Show resolved
Hide resolved
packages/block-library/src/navigation/edit/use-convert-classic-menu-to-block-menu.js
Show resolved
Hide resolved
packages/block-library/src/navigation/edit/use-convert-classic-menu-to-block-menu.js
Show resolved
Hide resolved
packages/block-library/src/navigation/edit/use-convert-classic-menu-to-block-menu.js
Show resolved
Hide resolved
draganescu
left a comment
There was a problem hiding this comment.
Tested and did what it says. The code is pretty streamlined and LGTM.
|
@draganescu Just confirming that this won't now make it into 6.1 right? |
|
I believe that is the case |
|
I think it would benefit from waiting in the plugin more. What navigation building experience gained for 6.1 is definitely good, this would work best once the other work on slug based menu migration is also complete. |



What?
If a site has a classic navigation menu, but no wp_navigation CPTs then we should fallback to the classic navigation block. If there's a primary location then we should use the navigation assigned to it, if not then we could use the latest one.
Why?
For users who have set up classic menus this will be better than just showing them a list of pages.
How?
In the frontend we just fetch the correct navigation menu and convert it to blocks
In the editor we actually convert the navigation menu to a wp_navigation CPT. This creates some issues - at the moment it's created as a draft. Also it gets created multiple times. Perhaps the best way round this is to create it as a published menu, so that the fallbacks will continue to work as they do right now.
Testing Instructions