Copied to clipboard

Flag this post as spam?

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


  • Dan White 206 posts 510 karma points c-trib
    May 29, 2013 @ 06:59
    Dan White
    0

    Multiple Start Nodes -- Media Section

    I'm trying to extend Umbraco to allow for mutiple start nodes per user in the media section. I don't want to replace the default media tree, as that will likely cause other issues. 

    Taking ideas from Epiphany Custom Tree [ http://customcontenttree.codeplex.com/SourceControl/latest#Epiphany.CustomContentTree/Epiphany.CustomContentTree/CustomContentTree.cs ]

    and some code from BaseMediaTree.cs Render method
    http://umbraco.codeplex.com/SourceControl/latest#src/Umbraco.Web/umbraco.presentation/umbraco/Trees/BaseMediaTree.cs ]

    I kind of got the media section tree obeying. Basically tapping into the BaseMediaTree.AfterTreeRender event. Clearing the TreeCollection. Then readding my desired nodes to the TreeCollection. 

    Things like DAMP & FolderBrowser didn't obey. Looking at the code for FolderBrowser, I don't think it'd be possible to make it work without modifying its source, but that's neither here nor there.

    Obviously, this isn't very elegant nor fullproof. 

    I'm now trying to tap into the BaseMediaTree.BeforeTreeRender event and modify the sender object collection before the tree is generated. Thinking I'll have better luck getting DAMP to obey and not feeling so hacky. However, I'm not having any luck.

    Help/suggestions would be greatly appreciated.

    Dan

  • Dan White 206 posts 510 karma points c-trib
    May 29, 2013 @ 17:50
    Dan White
    1

    I found that the reason DAMP wasn't behaving is becuase I was looking only for e.Tree.treeCollection[0].NodeType == "media".

    Here's my code. It's really light with nothing fancy yet, as I'm still trying to figure this thing out.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using umbraco;
    using umbraco.cms.businesslogic.media;
    using umbraco.cms.presentation.Trees;
    
    /// <summary>
    /// Summary description for CustomMediaTree
    /// </summary>
    public class CustomMediaTree : umbraco.BusinessLogic.ApplicationBase
    {
        private BaseTree tree = null;
    
        public CustomMediaTree()
        {
            BaseMediaTree.AfterTreeRender += new EventHandler<TreeEventArgs>(setUpCustomMediaTree);
        }
    
        private void setUpCustomMediaTree(object sender, TreeEventArgs e)
        {
            if ((e.Tree.treeCollection[0].NodeType == "media" || e.Tree.treeCollection[0].NodeType == "DigibizMediaTree") && HttpContext.Current.Request.QueryString["id"] == "-1")
            {
                int[] startNodes = {2384, 2476};
    
                tree = TreeDefinitionCollection.Instance.FindTree<loadMedia>().CreateInstance();
                tree.IsDialog = false;
                tree.ShowContextMenu = false;
    
                e.Tree.treeCollection.Clear();
    
    
                foreach (var node in startNodes) {
                    Media item = new Media(node);
                    XmlTreeNode xNode = XmlTreeNode.Create(tree);
                    xNode.NodeID = item.Id.ToString();
                    xNode.Text = item.Text;
                    xNode.Menu = null;
                    xNode.Action = "javascript:openMedia(" + item.Id + ")";
                    xNode.Source = GetTreeServiceUrl(item.Id);
                    xNode.HasChildren = item.HasChildren;
    
    
    
                    if (item.ContentType != null)
                    {
                        xNode.Icon = item.ContentType.IconUrl;
                        xNode.OpenIcon = item.ContentType.IconUrl;
                    }
    
                    if (xNode != null)
                    {
                        e.Tree.Add(xNode);
                    }
                }
            }
        }
        public string GetTreeServiceUrl(int id)
        {
            // updated by NH to pass showcontextmenu, isdialog and dialogmode variables
            TreeService treeSvc = new TreeService(id, "media", true, false, TreeDialogModes.none, "");
            return treeSvc.GetServiceUrl();
        }
    }
  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    May 30, 2013 @ 15:01
    Morten Christensen
    0

    You are probably best off by removing the FolderBrowser from the Media dashboard, as it would always just list everything at the root of the media tree regardless of what is actually rendered in the tree (should you somehow manipulate it).

    I believe you will be able to use the BeforeTreeRender/AfterTreeRender events for what you want to archive. If you are only removing stuff then I would go for the BeforeTreeRender, but if you need to both add and remove items from the tree you are probably better off using the AfterTreeRender and clear out the tree as you wrote yourself.
    The code in your sample looks fine. There are nothing thats really better then what you have if that is what you were after. Depending on which version of Umbraco you are using there might be faster/other ways to load the media object, but thats about it.

    Not sure if this helps in any way, but it sounds like you are already on the right path. Otherwise feel free to ask.

    - Morten

  • Dan White 206 posts 510 karma points c-trib
    May 30, 2013 @ 16:01
    Dan White
    0

    Morten,

    Do you know of any working examples that modify the collection in BeforeTreeRender? I can modify the collection locally, but I can't get the changes to apply back to in the caller.

    Although I hate to modify core files, I did get FolderBrowser working by overriding some methods and changing the namespace in the usercontrol. 

    Thanks,

    Dan

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    May 30, 2013 @ 16:06
    Morten Christensen
    0

    Yes, I know of this one :)
    https://bitbucket.org/umbristol/page-state-icons/src/dcf93bbaddd67a6bf24a05af993bb469270345cf/Src/UmBristol.PageStateIcons/Application.cs?at=default

    From the Page-State-Icons package.

    Not sure if it does the same thing as what you are after, but maybe you can find some inspiration.

    - Morten

  • Dan White 206 posts 510 karma points c-trib
    May 30, 2013 @ 16:42
    Dan White
    0

    Ugh. Unfortunately, that package uses BeforeNodeRender instead of BeforeTreeRender. That'd be a good location for preventing nodes from going into the tree. Thanks though.

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    May 30, 2013 @ 21:28
    Morten Christensen
    0

    Ah, sorry. Misread the name of the event you wanted to use.

    Any particular reason why you want to modify the array of Media objects (BeforeTreeRender) over the XML (BeforeTreeRender used to create the tree?

    BTW. which version of Umbraco are you using?

     

    - Morten

  • Dan White 206 posts 510 karma points c-trib
    May 31, 2013 @ 05:34
    Dan White
    0

    The reason for using BeforeTreeRender is becuase on the intial tree load I want to manually choose which media objects are going to be put into the tree. Currently, with AfterTreeRender, I'm letting the default media tree load than clearing it. After that I load the desired media objects and rebuild the tree.

    It just seems like wasted processing to create a tree that won't be used. 

    Is there any reason I'm not able to modify the collection in BeforeTreeRender?

    Since the site is still in development, I'm keeping up with version releases. Just upgraded to 6.1 ( Really wanted the new routing and API stuff :) ).

Please Sign in or register to post replies

Write your reply to:

Draft