Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tim Brooks 27 posts 79 karma points
    Sep 10, 2014 @ 05:03
    Tim Brooks
    0

    Adding a new section in Umbraco v7

    I attempted to create a new section in the umbraco backoffice based of this blog post: 

    http://www.enkelmedia.se/blogg/2013/11/22/creating-custom-sections-in-umbraco-7-part-1.aspx

    When I run the project I can confirm that an entry has been created in both the applications.config and trees.config. I placed all my code into one file. I know that's not great programing style but I'm just trying to do a proof of concept and I'll refactor later. Here is my code: 

        [Application("reviewsection", "reviewsection", "icon-car", 15)]

        public class ReviewSection : IApplication

        {

        }

     

        [PluginController("ReviewSection")]

        [Umbraco.Web.Trees.Tree("reviewsection", "reviewsectiontree", "Moderate Reviews", iconClosed: "icon-doc")]

        public class ReviewSectionTreeController : TreeController

        {

            protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)

            {

                var nodes = new TreeNodeCollection();

                var item = this.CreateTreeNode("dashboard", id, queryStrings, "My item", "icon-truck", true);

                nodes.Add(item);

                return nodes;

            }

     

            protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)

            {

                var menu = new MenuItemCollection();

                menu.DefaultMenuAlias = ActionNew.Instance.Alias;

                menu.Items.Add<ActionNew>("Create");

                return menu;

            }

        }

     

    The resulting entries in both applications and trees.config respectively: 

    <add alias="reviewsection" name="reviewsection" icon="icon-car" sortOrder="15" />

    <add initialize="true" sortOrder="0" alias="reviewsectiontree" application="reviewsection" title="Moderate Reviews" iconClosed="icon-doc" iconOpen="icon-folder-open" type="MagnaFlow.Web.ReviewSectionTreeController, MagnaFlow.Web" />

     

    The article mentions that under user you have to select the new section before it shows but when I go to the user's area the new section doesn't show. What I'm I missing? Is there anything that needs to done to the dashboard.config? There is icon-truck and icon-car. I don't know the source of these icons, is it possible this fails because they don't exists? Do I need to do an IIS Reset or any other refresh to make these appear? Any help is greatly appreciated. Thanks

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Sep 10, 2014 @ 16:45
    David Brendel
    0

    Think is is propably caused by the backoffice caching.

    Try to delete the cache and maybe restart the website.

    Also i recommend to add the section with the new SectionService and also directly add the section to the current user with the UserService.

    Sample:

    var sectionService = ApplicationContext.Current.Services.SectionService;
    //Try & find a section with the alias of "demoSection"
    var demoSection = sectionService.GetSections().SingleOrDefault(x => x.Alias == "demoSection");
    //If we can't find the section - doesn't exist
    if (demoSection == null)
    {
    //So let's create the section
            sectionService.MakeNew("DemoSection", "demoSection", "icon-calendar-alt");
    }
    //Add the section to the allowed once for the admin
    var us = ApplicationContext.Current.Services.UserService;
    var admin = us.GetByProviderKey(0);
    if(!admin.AllowedSections.Any(x => x == "demoSection")) {
    admin.AddAllowedSection("demoSection");
          us.Save(admin);
    }
  • Tim Brooks 27 posts 79 karma points
    Sep 10, 2014 @ 21:08
    Tim Brooks
    0

    I can confirm the code sample above is working fine by stepping through. It creates the section if needed and the admin user is allowed. Still nothing shows up on screen (in the users section area or the left hand sections toolbar). I did however notice when stepping through my tree and menu code is not being hit at all. I will attempt to resolve that next. Does the tree controller have to be placed in a particular directory where umbraco is expecting to find it? I assume that is the case. 

    NOTE: to step through this code, I start debugging, no debug points will be hit in the application startup. If I make a change to the web.config, then refresh the umbraco page, the application will restart and your debug points will be hit. 

     

  • Steve Morgan 1349 posts 4459 karma points c-trib
    Sep 13, 2014 @ 14:01
    Steve Morgan
    0

    Tim - Markus's post is useful but a few bits and pieces have changed since he wrote it - take a look at Tim Geyssens blog post (works with Umbraco 7.1.4 - 7.1.6+) he's created a sample project here.

    https://github.com/TimGeyssens/UmbracoAngularBackofficePages

    Tim has two separate projects in his solution but I put my code inside the main Umbraco project with the backoffice angular stuff under a folder in App_plugins - ensure you use a package.manifest file for flexibility (basically Tim G's structure is good but I just create these extra folders in the main project). 

    HTH. 

  • Tim Brooks 27 posts 79 karma points
    Nov 25, 2014 @ 01:10
    Tim Brooks
    0

    Using the original article, the project by Tim Geyssens and the following article I was able to build out this new section from scratch.

    http://siempresolutions.co.uk/blog/ExtendingUmbracoCustomTreeandMVCAPIPart1

    The only note is that there was something wrong with the original project I was working on. Since I was early enough along in development I just opened a test project, got the section working, then moved over all my code from the original project.

  • Steve Morgan 1349 posts 4459 karma points c-trib
    Nov 25, 2014 @ 10:11
    Steve Morgan
    0

    Glad my blog post was useful :) - I'd still recommend following Tim's for anyone else trying to do this. Dave Woestenborghs presented how to do this at the UK Umbraco Festival and had a nice, clean Umbraco content editor style section which would be a great starter point - look for the talks to be uploaded soon!

    The reason why you probably had a problem in your original project (guessing a bit..) is that you created the section - spun Umbraco up and this automatically added it to the \config\trees.config and then, as you were still developing, you changed the name of the controller. 

    This causes a bit of confusion as it won't recreate / update the section in the trees.config (as one with the same name seems to exist in the config) but also won't work as it can't find the controller. 

    This would explain why it works in a new project - when you copied it over it spun up and created the correct config entry. 

    HTH 

    Steve

Please Sign in or register to post replies

Write your reply to:

Draft