How to add items to the Document Types context menu.

I am currently working on an extension to Umbraco that needed an extra menu item on the Document Types menu in the Settings section, my first thought was to use the BeforeNodeRender event to add the menu item, but this event only fires on the Content and Media menu trees.See: Codeplex Issue 21623The "temporary" solution has been to extend the "loadNodeTypes" class, I say temporary because I assume that the core team may well extend the event functionality to the entire menu tree in the future which would be much better and would prevent you from having to complete override the menu items.This was suggested by Slace on my "is it possible to add an item to the context menu in tree's other than media content" post on theour.umbraco.org site.There are three things you need to do:1) Override the loadNodeTypes

usingSystem.Collections.Generic;
using umbraco.interfaces;
using umbraco.BusinessLogic.Actions;namespaceVizioz.xMind2Umbraco
{
// Note: Remember these menu's might change in future versions of Umbracopublicclass loadNodeTypesMenu : umbraco.loadNodeTypes
{
public loadNodeTypesMenu(string application):base(application){}protectedoverridevoidCreateRootNodeActions(refList<IAction> actions)
{
actions.Clear();
actions.Add(ActionNew.Instance);
actions.Add(xMindImportAction.Instance);
actions.Add(ContextMenuSeperator.Instance);
actions.Add(ActionImport.Instance);
actions.Add(ContextMenuSeperator.Instance);
actions.Add(ActionRefresh.Instance);
}
protectedoverridevoidCreateAllowedActions(refList<IAction> actions)
{
actions.Clear();
actions.Add(ActionCopy.Instance);
actions.Add(xMindImportAction.Instance);
actions.Add(ContextMenuSeperator.Instance);
actions.Add(ActionExport.Instance);
actions.Add(ContextMenuSeperator.Instance);
actions.Add(ActionDelete.Instance);
}
}
}

2) Create a new Action to be used on the menu

using umbraco.interfaces;namespaceVizioz.xMind2Umbraco
{
publicclass xMindImportAction :IAction
{
#region Implementation of IActionpublicstatic xMindImportAction Instance
{
get{return umbraco.Singleton<xMindImportAction>.Instance;}
}publiccharLetter
{
get{return'p';}
}publicboolShowInNotifier
{
get{returntrue;}
}publicboolCanBePermissionAssigned
{
get{returntrue;}
}publicstringIcon
{
get{return"editor/OPEN.gif";}
}publicstringAlias
{
get{return"Import from xMind";}
}publicstringJsFunctionName
{
get
{
return"openModal('dialogs/xMindImport.aspx?id=' + nodeID,
'Publish Management', 550, 480);";
}
}publicstringJsSource
{
get{returnstring.Empty;}
}#endregion
}
}

3) Update the UmbracoAppTree table, my case I changed the following:TreeHandlerType
From: loadNodeTypes
To: loadNodeTypesMenuTreeHandlerAssembly
From: umbraco
To: Vizioz.xMind2UmbracoAnd the result is:

 


Author

Chris Houston

Chris is the founder of Vizioz and has been working in the field of website development for over 20 years. Chris has been working with Umbraco since 1998 and now spends his time running both Vizioz and QV Offices.


comments powered by Disqus