Copied to clipboard

Flag this post as spam?

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


  • Rich Green 2246 posts 4008 karma points
    Nov 13, 2010 @ 10:58
    Rich Green
    0

    Hiding specific DocTypes when rendering tree

    I'm trying to hide menu items for a certain DocType is in the tree, however the code below doesn't work as Node.NodeType returns "content" or "media"

    How can I get the DocTypeAlias?

    I'm using 4.5.2

    public class EnterprisePermissions : ApplicationBase
        {
            string donotdeletealias = "textpage";
            public EnterprisePermissions()
            {
                umbraco.cms.presentation.Trees.BaseTree.BeforeNodeRender += new umbraco.cms.presentation.Trees.BaseTree.BeforeNodeRenderEventHandler(BaseTree_BeforeNodeRender);
            }
    
    
            void BaseTree_BeforeNodeRender(ref umbraco.cms.presentation.Trees.XmlTree sender, ref umbraco.cms.presentation.Trees.XmlTreeNode node, EventArgs e)
            {
                if (node.NodeType == donotdeletealias)
                {
                    node.Menu.Actions.Remove(umbraco.BusinessLogic.Actions.ActionDelete.Instance);        
                }
    
             }
        }

    The code above is from here  http://our.umbraco.org/wiki/reference/api-cheatsheet/using-applicationbase-to-register-events/event-examples/remove-context-menu-items 

    Cheers

    Rich

  • Rich Green 2246 posts 4008 karma points
    Nov 13, 2010 @ 11:17
    Rich Green
    0

    I figured this out, however would be very interested to know if this the best way and also if  the Wiki page is incorrect?

     umbraco.presentation.nodeFactory.Node treeNode = new umbraco.presentation.nodeFactory.Node(Convert.ToInt32(node.NodeID));
     Log.Add(LogTypes.Custom, -1, "Node type Alias" + treeNode.NodeTypeAlias);
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies