Copied to clipboard

Flag this post as spam?

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


  • Cedric 15 posts 86 karma points
    Feb 27, 2019 @ 08:05
    Cedric
    0

    Custom Section Umb 8

    Hello, I created a plugin under umbraco 7 with a custom section using trees.config but now I would like to migrate it under Umb 8 but can not find or I have to create my custom section in the new version the documentation on the subject is not not good Thank you for your help. C├ędric

  • Kevin Jump 1834 posts 11757 karma points MVP 4x c-trib
    Feb 27, 2019 @ 08:56
    Kevin Jump
    3

    Hi Cedric,

    you can create a custom section in two ways with v8

    via the package.manifest (in an app_plugin folder for your plugin): so you can add the following

      "sections": [
        {
          "alias": "mySection",
          "name": "Custom Section"
        }
      ],
    

    via code : you need to impliment ISection and append it to the Sections() collection in a Composition.

    public class DashboardComposer : IUserComposer
    {
        public void Compose(Composition composition)
        {
            composition.Sections().Append<MyCustomSection>();
        }
    }
    
    public class MyCustomSection : ISection
    {
        public string Alias => "mySection";
    
        public string Name => "My Section Name";
    }
    
  • Cedric 15 posts 86 karma points
    Feb 27, 2019 @ 09:02
    Cedric
    0

    thank you very much I will try

  • Cedric 15 posts 86 karma points
    Feb 27, 2019 @ 11:32
    Cedric
    0

    hello I still have a question about the creation of my tree. in V7 I had this code: but I have errors on

    [Umbraco.Web.Trees.Tree("content", "KeziaAlias", "Kezia Parametres", sortOrder: 0)]
    

    And :

    menu.Items.Add<CreateChildEntity, ActionNew>(ui.Text("actions", ActionNew.Instance.Alias));
    

    my code :

    [PluginController("KeziaApp")]
    //[Umbraco.Web.Trees.Tree("KeziaApp", "KeziaAlias", "Kezia Parametres", sortOrder: 0)]
    [Umbraco.Web.Trees.Tree("content", "KeziaAlias", "Kezia Parametres", sortOrder: 0)]
    public class KeziaAppTreeController : TreeController
    {
        protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)
        {
            // create a Menu Item Collection to return so people can interact with the nodes in your tree
            var menu = new MenuItemCollection();
    
            if (id == Constants.System.Root.ToInvariantString())
            {
                // root actions, perhaps users can create new items in this tree, or perhaps it's not a content tree, it might be a read only tree, or each node item might represent something entirely different...
                // add your menu items here following the pattern of <Umbraco.Web.Models.Trees.ActionMenuItem,umbraco.interfaces.IAction>
                menu.Items.Add<CreateChildEntity, ActionNew>(ui.Text("actions", ActionNew.Instance.Alias));
                // add refresh menu item            
                menu.Items.Add<RefreshNode, ActionRefresh>(ui.Text("actions", ActionRefresh.Instance.Alias), true);
                return menu;
            }
            // add a delete action to each individual item
            menu.Items.Add<ActionDelete>(ui.Text("actions", ActionDelete.Instance.Alias));
    
            return menu;
        }
    
        protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
        {
            // check if we're rendering the root node's children
            if (id == Constants.System.Root.ToInvariantString())
            {
                // you can get your custom nodes from anywhere, and they can represent anything... 
                Dictionary<int, string> favouriteThings = new Dictionary<int, string>();
                favouriteThings.Add(1, "Import des produits de Kezia");
                // create our node collection
                var nodes = new TreeNodeCollection();
    
                // loop through our favourite things and create a tree item for each one
                foreach (var thing in favouriteThings)
                {
                    // add each node to the tree collection using the base CreateTreeNode method
                    // it has several overloads, using here unique Id of tree item, -1 is the Id of the parent node to create, eg the root of this tree is -1 by convention - the querystring collection passed into this route - the name of the tree node -  css class of icon to display for the node - and whether the item has child nodes
                    var node = CreateTreeNode(thing.Key.ToString(), "-1", queryStrings, thing.Value, "icon-presentation", false);
                    nodes.Add(node);
    
                }
                return nodes;
            }
    
            // this tree doesn't support rendering more than 1 level
            throw new NotSupportedException();
        }
    }
    
  • Kevin Jump 1834 posts 11757 karma points MVP 4x c-trib
    Feb 27, 2019 @ 11:42
    Kevin Jump
    1

    Hi

    the Tree Attribute has been updated a little.

    [Tree("Section", "treeAlias", TreeGroup = "Group (optional)", 
    TreeTitle = "tree title", SortOrder = 1)]
    

    Should work

    the Actions have moved about a bit.

            menu.Items.Add(new RefreshNode(Services.TextService, true));
    

    will get you a refresh node (built in from the Umbraco core).

    my create action ended up looking like this

                var createMenuItem = new MenuItem(ActionNew.ActionAlias, Services.TextService)
                {
                    Icon = "add",
                    OpensDialog = true
                };
                menu.Items.Add(createMenuItem);
    

    but that is partly because i am also setting a custom route for my create action.

    and a for me delete looks like this :

                menu.Items.Add<ActionDelete>(
                        Services.TextService.Localize($"actions/{ActionDelete.ActionAlias}"), true);
    
  • Cedric 15 posts 86 karma points
    Feb 27, 2019 @ 11:48
    Cedric
    0

    thank you very much it works

  • Chris Spanellis 29 posts 140 karma points
    5 days ago
    Chris Spanellis
    0

    Thanks for this, but then how do you close the dialog that gets openened? I tried the editorService.close() with no luck. Any ideas?

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft