Yeah you should be able to do this with the following code:
public class YourTreeEvent : ApplicationBase { public YourTreeEvent() { umbraco.cms.presentation.Trees.BaseTree.BeforeNodeRender += new umbraco.cms.presentation.Trees.BaseTree.BeforeNodeRenderEventHandler(BaseTree_BeforeNodeRender); }
YourAction will be inserted as the first action in the context menu within the users-Tree.
NodeType would/could be "users", "userPermissions" or "userTypes" depending on where you want your action to appear. These are the TreeAlias(es) for the users-app (the Users-section).
I assumed it worked as I have used in it in the content and media sections. I never used it with:
node.NodeType=="users"
but assumed it worked, since it has worked for me with:
node.NodeType=="media"
I can do a quick test for the users-section and post my result. Otherwise I quess you would have to override the loadUsers-class, which is the class that loads the tree and adds actions.
The weard thing is that the loadUsers class inherits from BaseTree, so you would think it has to work. Thanks for the quick test, then I'm sure its not just me :)
Yeah, your right. It doesn't hit the Event in the Users section.
But I think I would out why! If you look in the loadMedia and BaseContent classes, you'll find this piece of code in public override void Render(ref XmlTree Tree):
Yeah, your right. It doesn't hit the Event in the Users section.
But I think I would out why! If you look in the loadMedia and BaseContent classes, you'll find this piece of code in public override void Render(ref XmlTree Tree):
Yeah, your right. It doesn't hit the Event in the Users section.
But I think I would out why! If you look in the loadMedia and BaseContent classes, you'll find this piece of code in public override void Render(ref XmlTree Tree):
The easiest thing would probably be to copy the code from the loadUsers.cs and create a new one called i.e. RonsUsersTree and then change the entry in the umbracoAppTree table of your db to use your new class and assembly.
Currently the entry that loads the users-section tree looks like this:
You just need to update "treeHandlerAssembly" and "treeHandlerType" to your assembly and class.
If you want to reuse the loadUsers class you could inheirent the class and override the CreateNodeActions etc. (public class RonsUsersTree : loadUsers), but you will still have to update the entry in the db to use your class instead of the original one.
I agree, and maybe we should ask some of the core developers if there is any particular reason why the Users-section tree isn't firing the event. ...Or simply add it as an issue on Codeplex.
Adding an IAction to Contextmenu of the User section
Hi,
Is it possible to add a custom action to the tree in the users section?
And if so is it possible using the BaseTree.BeforeNodeRender?
Thanks,
Ron
Hi Ron,
Never done that, check if the even gets hit when you open a user tree, if that event gets hit, you can use custom actions in the tree.
Cheers,
Richard
Hi Ron,
Yeah you should be able to do this with the following code:
YourAction will be inserted as the first action in the context menu within the users-Tree.
NodeType would/could be "users", "userPermissions" or "userTypes" depending on where you want your action to appear. These are the TreeAlias(es) for the users-app (the Users-section).
- Morten
Thanks @Richard and @Morten
I already tried that and the event only gets hit in the content section.
Any suggestions?
Ron
File a bug report at codeplex, the event really should fire on all trees, right?
@Morton
Have you used that code before or did you assume it would work?
Ron
@Ron
I assumed it worked as I have used in it in the content and media sections. I never used it with:
but assumed it worked, since it has worked for me with:
I can do a quick test for the users-section and post my result.
Otherwise I quess you would have to override the loadUsers-class, which is the class that loads the tree and adds actions.
- Morten
@Morton
The weard thing is that the loadUsers class inherits from BaseTree, so you would think it has to work.
Thanks for the quick test, then I'm sure its not just me :)
Ron
Yeah, your right. It doesn't hit the Event in the Users section.
But I think I would out why! If you look in the loadMedia and BaseContent classes, you'll find this piece of code in public override void Render(ref XmlTree Tree):
So the events are only fired before and after the node has been added to the Tree.
So if you want it to work right now you have to override the loadUsers class or create a new tree loader for the users section.
- Morten
Yeah, your right. It doesn't hit the Event in the Users section.
But I think I would out why! If you look in the loadMedia and BaseContent classes, you'll find this piece of code in public override void Render(ref XmlTree Tree):
So the events are only fired before and after the node has been added to the Tree.
So if you want it to work right now you have to override the loadUsers class or create a new tree loader for the users section.
- Morten
Yeah, your right. It doesn't hit the Event in the Users section.
But I think I would out why! If you look in the loadMedia and BaseContent classes, you'll find this piece of code in public override void Render(ref XmlTree Tree):
So the events are only fired before and after the node has been added to the Tree.
So if you want it to work right now you have to override the loadUsers class or create a new tree loader for the users section.
- Morten
Damnit! Sorry about the triple posting :-S The post wasn't updating after hitting submit.
- Morten
But how can I make Umbraco use my new loadUsers after I override the event?
(Sorry I don't have much experience in that area.)
Ron
The easiest thing would probably be to copy the code from the loadUsers.cs and create a new one called i.e. RonsUsersTree and then change the entry in the umbracoAppTree table of your db to use your new class and assembly.
Currently the entry that loads the users-section tree looks like this:
You just need to update "treeHandlerAssembly" and "treeHandlerType" to your assembly and class.
If you want to reuse the loadUsers class you could inheirent the class and override the CreateNodeActions etc. (public class RonsUsersTree : loadUsers), but you will still have to update the entry in the db to use your class instead of the original one.
Hope this makes sense.
- Morten
Yes it makes sence.
Don't like it tho. It's a shame that I need to change the core in order to get it working.
However it seems to be the only way to go.
Thanks a lot!
Ron
I agree, and maybe we should ask some of the core developers if there is any particular reason why the Users-section tree isn't firing the event.
...Or simply add it as an issue on Codeplex.
- Morten
HI Ron,
Great that it worked for you. There is a package Action that helps you update the apptree values when you need to create a package out of this. Check out http://packageactioncontrib.codeplex.com/ and http://www.prolificnotion.co.uk/update-application-tree-package-action-for-umbraco
Cheers,
Richard
Thanks Richard,
I choose not to change the tree. I just added an additional one.
That way I don't need to change Umbraco.
Ron
is working on a reply...