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.
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.
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.
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.
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.
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 :) ).
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
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.
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
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
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
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.
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
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 :) ).
is working on a reply...