-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MenuRenderingNotification Example
- Loading branch information
1 parent
e641c96
commit 5efc908
Showing
2 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
Umbraco.Docs.Samples.Web/Notifications/TreeNotificationHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Umbraco.Cms.Core.Events; | ||
using Umbraco.Cms.Core.Notifications; | ||
using Umbraco.Cms.Core.Security; | ||
|
||
namespace Umbraco.Docs.Samples.Web.Notifications; | ||
|
||
// https://docs.umbraco.com/umbraco-cms/extending/section-trees/trees#menurenderingnotification | ||
internal class TreeNotificationHandler : INotificationHandler<MenuRenderingNotification> | ||
{ | ||
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; | ||
public TreeNotificationHandler(IBackOfficeSecurityAccessor backOfficeSecurityAccessor) | ||
{ | ||
_backOfficeSecurityAccessor = backOfficeSecurityAccessor; | ||
} | ||
|
||
public void Handle(MenuRenderingNotification notification) | ||
{ | ||
// this example will add a custom menu item for all admin users | ||
// for all content tree nodes | ||
if (notification.TreeAlias.Equals("content") && _backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser != null && _backOfficeSecurityAccessor.BackOfficeSecurity.CurrentUser.IsAdmin()) | ||
{ | ||
// Creates a menu action that will open /umbraco/currentSection/itemAlias.html | ||
var menuItem = new Umbraco.Cms.Core.Models.Trees.MenuItem("itemAlias", "Item name"); | ||
|
||
// optional, if you don't want to follow the naming conventions, but do want to use a angular view | ||
// you can also use a direct path "../App_Plugins/my/long/url/to/view.html" | ||
menuItem.AdditionalData.Add("actionView", "my/long/url/to/view.html"); | ||
|
||
// sets the icon to icon-wine-glass | ||
menuItem.Icon = "wine-glass"; | ||
// insert at index 5 | ||
notification.Menu.Items.Insert(5, menuItem); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters