Changing the way menu-items are built

Topics: Customizing Orchard, Localization, Writing modules
May 23, 2013 at 3:15 PM
I noticed that the URLs of menu-items are created by the GetUrl() method of INavigationManager. For certain pages I have multiple aliases, but the default NavigationManager always 'picks' the first/default alias.

I need to create multiple 'sections' in my website (like mydomain.com/sectionX and mydomain.com/sectionY). Depending on which section I'm in, I also need to change the URLs of that section so that they use the alias for that section.

So far I'm doing this by creating my own implementation of INavigationManager. I only need to change the GetUrl() method, but that method is called by FinishMenu() and that is called by BuildMenu() and that also calls several other methods, which are private. So I basically have to copy the whole NavigationManager class just to change the GetUrl() method (otherwise it will call the GetUrl() method of the original NavigationManager instead of mine). This is, of course, not ideal.

Maybe the best way is to change the original NavigationManager, to make GetUrl() virtual (and maybe other methods as well?) so that I can override it in my own NavigationManager. Is this what I should do and if yes, should/can I commit that to Orchard, so that other people can use it as well and so that I won't have problems with Orchard updates in the future? If no, what should I do instead?
Developer
May 23, 2013 at 3:39 PM
Regarding your approach, perhaps there's a better way of doing things. To me it wouldn't feel right to rely on multiple aliases for a content item. Instead, maybe see if you could resolve the correct content item using a custom route, where the section is a route value, and everything after that is a unique alias pointing to a content item. I didn't think this through, so perhaps it won't work, but perhaps you could try it.

I don't see any problem with marking GetUrl and maybe others as being protected virtual, but I think there should be a good reason / common use case for it. Perhaps create an issue for us to triage and others to vote on. Or even better: come join us in Amsterdam at the Orchard Harvest conference and convince us! :)
May 23, 2013 at 3:49 PM
Thanks for your reply. The multiple aliases approach is the best solution I could think of, for the problem of my other topic. I didn't think of using a custom route though, I will give that a try, see how far I can come with that.

Actually, I am coming to join the Orchard Harvest together with a colleague. We bought our tickets yesterday :)
Developer
May 23, 2013 at 3:57 PM
Great! Looking forward to seeing you there then and see what you came up with. :)
May 27, 2013 at 1:03 PM
Sorry for my stupid question, I'm still an Orchard and MVC noob :P

Anyway, I'm not really sure how to implement your suggestion. I've been looking into routes of other modules, but they all work with area/controller/action and that's not what I need (I think?). Only the Alias module does it differently, it seems like I have to do it in a similar way and also create a class like the Orchard.Alias.Implementation.AliasRoute class or even override that class in my module.. but I might also be completely wrong...

So could you explain to me how I can make a part of a route point to a content item?