danwhite85
9/2/2011 - 11:24 AM

Hide Nodes in Umbraco Tree

Hide Nodes in Umbraco Tree

using System;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.web;
using umbraco.cms.presentation.Trees;
using umbraco.interfaces;


namespace Abbott.Corporate.Logic.Events
{
    public class HideGridNodeOnLoad : ApplicationBase
    {
        public HideGridNodeOnLoad()
        {
        // Event Handler - Tree Nodes
            BaseContentTree.BeforeNodeRender += new BaseTree.BeforeNodeRenderEventHandler(BeforeNodeRenderHandler);
        }

        private void BeforeNodeRenderHandler(ref XmlTree sender, ref XmlTreeNode node, EventArgs e)
        {
            // make sure we are dealing with a content node and not another type of node (like "media").
            if (node.NodeType.ToLower() == "content")
            {
                // let's make sure we are dealing with all users, apart from 'Administrators' before we do anything...
                if (umbraco.helper.GetCurrentUmbracoUser().UserType.Alias != "Administrator")
                {
                    // Lets Go!
                    // **********************************************************************
                    // Hide the Nodes which contain the Grid Layout data.
                    int docid = int.Parse(node.NodeID); // get the Node Id
                    Document doc = new Document(docid); // get the document
                    if (doc.ContentType.Alias == "layoutGridFolders")
                    {
                        node = null;
                    }
                }
            }
        }
    }
}