Overriding main menu provider

Developer
Jan 9, 2011 at 3:02 PM
Edited Jan 9, 2011 at 3:42 PM

Hi!

I created a custom, hierarchical menu in my module, by creating a class implementing INavigationProvider for menu "main". Unfortunately, the default MainMenuNavigationProvider is still called which causes items duplication in the top level. It seems like top level menu items from both providers are merged:/

Is there a way to completely override the default provider, turning off the default?

[EDIT] And one suggestion. After struggling with building hierarchy by NavigationItemBuilder I think it would be great to have ChildBuilder exposed as a property. It would make building hierarchy much easier and straightforward (by simple iteration). Currently we need to recurrently build an Action which would be called on top-level NavigationBuilder, what makes code really unclear and hard to debug (especially when dealing with nested lambdas...).

And guys, please - add XML comments:)

- Piotr

Coordinator
Jan 9, 2011 at 4:15 PM

Did you add a dependency (in Module.txt) on the module containing the implementation you want to override ?

Developer
Jan 9, 2011 at 6:31 PM
Edited Jan 9, 2011 at 10:49 PM

Yes, I added dependency on Navigation module, and it's still the same - items in top level are merged from both providers:/ I checked maybe it's something with my code - I commented the internals of MainMenuProvider.GetNavigation() method and everything is right then - so it's definitely not my fault:)

- Piotr

Developer
Jan 14, 2011 at 3:04 AM

Anybody has a clue how to get rid of the default menu provider in custom module? I have a nice hierarchical menu module I'd be happy to contribute, but first have to get rid of duplicating elements:)

- Piotr

Coordinator
Jan 14, 2011 at 3:13 AM

Does it work if the user disables the "Navigation" feature?

Developer
Jan 14, 2011 at 11:28 AM

Have to check it, but isn't the Navigation a core feature, so the user cannot disable it?

- Piotr

Developer
Jan 14, 2011 at 5:24 PM

Yes, the user cannot disable Navigation feature:/ Maybe is there a way to disable it manually when my module loads?

But doesn't it mean that in such case I'd have to rewrite (copy-paste from Navigation) the whole admin functionality for navigation in my module? For now my module consists of just a custom navigation provider for main menu...

Developer
Jan 15, 2011 at 2:42 AM
Edited Jan 15, 2011 at 5:00 AM

Ok, I looked deeper into the code and it looks like everything is by design. NavigationManager merges items it gets from all providers for given menu name ("main" for main menu). The problem is that the NavigationManager.Merge method merges only the root menu level - it doesn't traverse the tree structure of the menu (and omits the child items). And in the result I receive all lower-level menu items duplicated at the root level... It looks like an issue to me.

By the way - I'll try a different approach - give my menu a different name and create a separate zone (not Navigation, as MenuFilter sets the menu automatically) for holding it.

Update: Found a much cleaner solution - I'll wrap it up in Autofac.Module and replace the default main menu provider with mine.

- Piotr

Jan 18, 2011 at 8:57 AM

Hi pszmyd

   Have you resolved the navigation feature on your project? Would you mind share your navigation module to us as we don't know how to start to create or modify the default navigation menu feature?

Thanks.

Developer
Jan 20, 2011 at 12:26 AM

Hi!

I've just contributed multi-level menu module to the gallery. It overrides the default menu provider (which was a really tricky part) and builds hierarchy based on Position property (dot-notation).

I'll try to write a docs article about it soon so to share my experiences about Orchard navigation:)

Cheers, Piotr

Feb 1, 2011 at 4:45 PM

@pszmyd, thanks for writing this module. it is a great help. the only problem i'm having is the order of the items doesn't respect the position settings. i'm not sure how the navigation items are ordered, as it is also not in the order in which they appear in the database.

thanks for any help you may offer in advance.

Developer
Feb 1, 2011 at 10:51 PM

Hi!

Thanks for the info. The items should be ordered by Position property (eg. 1, 1.1, 1.2, 1.2.1, 2, 2.1 and so on). Could you confirm that when using the default menu everything is fine?

If it is ok it means that I'd have to look into my prefix tree implementation on which the hierarchy is based.

Cheers, Piotr

Developer
Feb 5, 2011 at 2:41 AM

Hi!

I just aired my blog and the post about building this hierarchical menu is finally ready. Check it out:)

More articles coming soon.

Cheers, Piotr

Feb 7, 2011 at 1:02 AM

HI,

I have the same problem, can't set the order of the items, i'm trying to set the items using the Position Property (eg. 1, 1.1, 1.2, 1.3) for each item as described above but than in my page the items are in totally different position.