Just completing a V8 to V9 migration that is going really well thanks to all the good advise here. However there is one feature I can't find anywhere:
On V8 I was able to add custom actions on the members section tree using a composition and Umbraco.Web.Trees.TreeControllerBase to get hold of the MenuRendering event where an extra MenuItem could be injected, e.g.
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class MemberComposer : IUserComposer
{
public void Compose(Composition composition)
{
composition.Components().Append<MemberComponent>();
}
}
public class MemberComponent : IComponent
{
public void Initialize()
{
TreeControllerBase.MenuRendering += TreeControllerBase_MenuRendering;
}
public void Terminate()
{
TreeControllerBase.MenuRendering -= TreeControllerBase_MenuRendering;
}
private void TreeControllerBase_MenuRendering(TreeControllerBase sender, MenuRenderingEventArgs e)
{
if (sender.TreeAlias == "member")
{
var m = new MenuItem("approveUser", "Aprove User");
m.AdditionalData.Add("actionView", "/App_Plugins/MemberApproval/MemberApprovalView.html");
m.Icon = "umb-content";
e.Menu.Items.Add(m);
}
}
}
On V9, it seems like I have to replace the composition with this
public void Compose(IUmbracoBuilder builder)
{
builder.Services.AddSingleton<IMemberComponent, MemberComponent>();
}
However as the TreeControllerBase is not available anymore, I can't get hold of the tree events in any way.
I have checked the official docs for trees here but I can't quite see how to inject Umbraco.Cms.Web.BackOffice.Trees.TreeController on the composer:
I managed to add it as a composer so it works similarly to what we had for V8
public class MemberComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.AddNotificationHandler<MenuRenderingNotification, MemberComponent>();
}
}
public class MemberComponent : INotificationHandler<MenuRenderingNotification>
{
public void Handle(MenuRenderingNotification notification)
{
if (notification.TreeAlias.Equals("member")) {
var m = new MenuItem("approveUser", "Aprove User");
m.AdditionalData.Add("actionView", "/App_Plugins/MemberApproval/MemberApprovalView.html");
m.Icon = "umb-content";
notification.Menu.Items.Insert(5, m);
}
}
}
However, there is something odd going on: I usually manage all the code on a separate [client].Core project so the custom code is not affected when Umbraco is updated. And for some strange reason, on the separate project Umbraco.Cms.Core.Notifications doesn't seem to include MenuRenderingNotification which works perfectly if I add the composer directly on the Umbraco project.
I have a reference on the separate project to the same version of the package "Umbraco.Cms.Core 9.3.1" but something is not quite right. All the other notifications are there, just not the menu rendering one. Maybe security permissions?
Anyway, at least it works. Thanks again for the pointers.
Custom action on members tree
Just completing a V8 to V9 migration that is going really well thanks to all the good advise here. However there is one feature I can't find anywhere:
On V8 I was able to add custom actions on the members section tree using a composition and Umbraco.Web.Trees.TreeControllerBase to get hold of the MenuRendering event where an extra MenuItem could be injected, e.g.
On V9, it seems like I have to replace the composition with this
However as the TreeControllerBase is not available anymore, I can't get hold of the tree events in any way.
I have checked the official docs for trees here but I can't quite see how to inject Umbraco.Cms.Web.BackOffice.Trees.TreeController on the composer:
https://our.umbraco.com/documentation/Extending/Section-Trees/trees#menurendering
Any help more than welcome...
Hi Julio
What you are looking for is to register a notification handler using the
MenuRenderingNotification
: https://our.umbraco.com/Documentation/Extending/Section-Trees/trees#menurenderingnotificationYou can register this directly in the Startup class https://our.umbraco.com/documentation/reference/Notifications/#registering-notification-handlers-in-the-startup-class
or in a composer: https://our.umbraco.com/documentation/reference/Notifications/#registering-notification-handlers-in-a-composer
or via an extension method: https://our.umbraco.com/documentation/reference/Notifications/#registering-many-notification-handlers
Hi Bjarne, that's brilliant, thanks a lot.
I managed to add it as a composer so it works similarly to what we had for V8
However, there is something odd going on: I usually manage all the code on a separate [client].Core project so the custom code is not affected when Umbraco is updated. And for some strange reason, on the separate project Umbraco.Cms.Core.Notifications doesn't seem to include MenuRenderingNotification which works perfectly if I add the composer directly on the Umbraco project.
I have a reference on the separate project to the same version of the package "Umbraco.Cms.Core 9.3.1" but something is not quite right. All the other notifications are there, just not the menu rendering one. Maybe security permissions?
Anyway, at least it works. Thanks again for the pointers.
I noticed I was missing a reference to Umbraco.Cms.Web.BackOffice on my custom code library and now everythig works as expected.
is working on a reply...