How to get from a MenuItem or MenuPart to the content item it links to (if any)

Topics: Writing modules
Oct 28, 2013 at 8:34 PM
Is there any orchard-magic way to determine what content item a MenuItem/MenuPart is associated with?

The MenuPart is associated with another part (i.e. like a ContentMenuItemPart) which is then (possibly) linked to a content item. To do this I'm pretty sure I need to specifically handle each part that is a stereotype of MenuItem but I can't figure out a nice way to get from the MenuPart to its associated type of MenuItem stereotype.
Oct 28, 2013 at 8:39 PM
Well, you are only ever going to be able to do this when it is a ContentMenuItem, no? So in that case, just test if it has the part, then As<>() into it.
Oct 28, 2013 at 8:47 PM
Should mention I am trying to do this in a handler that gets the MenuPart when published. From there I can build the menu and get the set of menuItems. I want to get the stereotyped instance of each menuItem.
Oct 28, 2013 at 8:49 PM
Sorry threw in that last reply before seeing your reply.

Ok I'll try going that route. Was thinking maybe there was a more specific way of doing it.
Oct 29, 2013 at 9:16 AM
Ok figured out what I was looking for. Missed it a million times in the debugger.

menuItem.Content gets the MenuPart.

menuItem.Content.ContentItem gets the ContentMenuItem (or whatever is associated with that particular menu item ).

Type can be checked with menuItem.Content.ContentItem.ContentType