+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Programatically updating admin menu and creating groups?

Programatically updating admin menu and creating groups?

2 posts, 0 answered
  1. AJ
    AJ avatar
    11 posts
    Registered:
    17 Sep 2012
    17 Jul 2012
    Link to this post
    I've created a custom pluggable module and added it to the administration menu using the following code (straight from an example) but one thing I cant seem to find out is how to programmatically update the menu once the module is installed.

    protected override void InstallPages(Telerik.Sitefinity.Abstractions.SiteInitializer initializer)
            {
     
                var pageManager = initializer.PageManager;
                var backendPagesNode = pageManager.GetPageNode(SiteInitializer.SitefinityNodeId);
     
                var landingPage = pageManager.GetPageNodes().SingleOrDefault(p => p.Id == this.LandingPageId);
                if (landingPage == null)
                {
                    var pageInfo = new PageDataElement()
                    {
                        PageId = this.LandingPageId,
                        IncludeScriptManager = true,
                        ShowInNavigation = true,
                        EnableViewState = false,
                        TemplateName = SiteInitializer.BackendTemplateName,
                        Name = "Contacts",
                        MenuName = "Contacts",
                        UrlName = "Contacts",
                        Description = "Contacts Module",
                        HtmlTitle = "Contacts Module"
                    };
     
                    pageInfo.Parameters["ModuleName"] = "Contacts";
     
                    var html = new Literal();
                    html.Text = "<h1>Contacts</h1>";
     
                    initializer.CreatePageFromConfiguration(pageInfo, backendPagesNode, html);
     
                }
     
            }

    It would also be nice to create a navigation group specific to this and other modules I want to create so as to separate them in the menus? 
    Is it a case that I have to remove the module and reinstall it every time or is there a programmatic way I can achieve these things?
  2. Ivan Georgiev | Sitefin1ty
    Ivan Georgiev | Sitefin1ty avatar
    33 posts
    Registered:
    24 Sep 2012
    25 Jul 2012
    Link to this post
    Hi,

     There is a way to edit the pages backend menu. Here is a code example how to do it:

    SiteInitializer siteInitializer = new SiteInitializer("myEdit");
     
    Guid landingPageId = new Guid("{19BCC56D-B04C-409C-847B-458F6A21BDB9}");
     
    PageManager pageManager = PageManager.GetManager(null, "myEdit");
    PageNode backendPagesNode = pageManager.GetPageNode(SiteInitializer.SitefinityNodeId);
     
    PageDataElement pageInfo = new PageDataElement()
    {
        PageId = landingPageId,
        IncludeScriptManager = true,
        ShowInNavigation = true,
        EnableViewState = false,
        TemplateName = SiteInitializer.BackendTemplateName,
        Name = "Contacts",
        MenuName = "Contacts",
        UrlName = "Contacts",
        Description = "Contacts Module",
        HtmlTitle = "Contacts Module"
    };
     
    pageInfo.Parameters["ModuleName"] = "Contacts";
     
    var html = new Literal();
    html.Text = "<h1>Contacts</h1>";
     
    siteInitializer.CreatePageFromConfiguration(pageInfo, backendPagesNode, html);
     
    siteInitializer.SaveChanges();

    Another way to edit this is on module upgrade like this:

    public override void Upgrade(SiteInitializer initializer, Version upgradeFrom)
    {
        if (upgradeFrom.Major == 10 && upgradeFrom.Minor < 2)
        {
              //your code goes here
        }
    }

    The best way to organize your pages is to create group and child pages. Here is an example how to do it on module install:

    protected override void InstallPages(SiteInitializer initializer)
    {
        initializer.Installer
            .CreateModuleGroupPage(MyModule.ModulePageGroupId, "MyGroup")
                .PlaceUnder(CommonNode.TypesOfContent)
                .SetOrdinal(1)
                .SetTitle("ModuleTitle")
                .AddChildPage(MyModule.HomePageId, "MyHomePage")
                    .SetTitle("MyHomePage")
                    .SetHtmlTitle("MyHomePage")
                    .Done()
    }



    All the best,
    Ivan Georgiev | Sitefin1ty
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered