Search code examples
umbracoumbraco7

Umbraco 7 - Custom Menu Items & Trees, How does navigation work?


I have a custom section, with a custom tree.

I'm having a bit of trouble understanding how you set the correct behavior when:

You click a node in your tree to edit it. You click a menu item on a node like "Create" In my solution I'm using the same view to edit and create a record.

In my tree this is how a node is generated.

var routeToView = "rewards/rewardsTree/editcampaign/campaign-" + campaign.Id.ToString();

var campaignNode = CreateTreeNode("campaign-" + campaign.Id.ToString(), id.Split('-')[1], queryStrings, campaign.CampaignName, "icon-folder color-yellow", true, routeToView);

This is producing the route I want: (the name of my html file is editcampaign.html) and it is also passing "campaign-6"

/umbraco#/rewards/rewardsTree/editcampaign/campaign-6

When a user clicks the create 'menu Item' on the node - I want to send them to the same URL but just with a diffrent Id for example:

umbraco#/rewards/rewardsTree/editcampaign/brand-1

and I don't want it to pop up out of the side

This is what I have tried so far:

//This finds the view, but it comes up in a dialog also how do I pass the Id (brand-1)
     MenuItem mi = new MenuItem("editcampaign", "Create Campaign");
                    menuItemCollection.Items.Add(mi);

//Also Tried this finds puts a whole another umbraco UI inside a dialog

mi.LaunchDialogView("#rewards/rewardsTree/editcampaign/brand-1", "TITLE GOES HERE");

Can anyone point me to the fullest documentation for Menu's trees and navigation around the back office in general?


Solution

  • I believe there is an option to set view path on the "Create" menu item, which makes it open normally? Also, wouldn't it make more sense to have your path like /view/path/here/id ? Then when you create a new item just send 0 as id. Umbrangular on Github is a project with great examples of custom sections and views.

    EDIT: Here's an example

    protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)
    {
        var menu = new MenuItemCollection();
    
        MenuItem createCategory = new MenuItem("createcategory", "Create Category");
    
        createCategory.AdditionalData.Add("ParentCategoryId", id);
    
        createCategory.NavigateToRoute("/path/to/view/category/0");
    
        createCategory.Icon = "add";
    
        menu.Items.Add(createCategory);
    
        return menu;
    }