Bjarne Fyrstenborg
08/18/2024, 1:45 PMBusiness
.
However I can't seem to find details on this from querystring in notification besides on node id and looking it up in content cache obvious only work if node is published.
public class ExportNotificationHandler : INotificationHandler<MenuRenderingNotification>
{
private readonly IPublishedContentQuery _iPublishedContentQuery;
public ExportNotificationHandler(IPublishedContentQuery iPublishedContentQuery)
{
_iPublishedContentQuery = iPublishedContentQuery;
}
public void Handle(MenuRenderingNotification notification)
{
var test = notification.QueryString["nodeType"];
int.TryParse(notification.NodeId, out int nodeId);
if (_iPublishedContentQuery.Content(nodeId) is not Business)
return;
if (notification.TreeAlias.Equals(Umbraco.Cms.Core.Constants.Trees.Content))
//&& notification.QueryString["nodeType"] == Business.ModelTypeAlias)
{
var menuItem = new Umbraco.Cms.Core.Models.Trees.MenuItem("export", "Export");
menuItem.AdditionalData.Add("actionView", "/App_Plugins/MyPlugin/export.html");
menuItem.Icon = "icon-download-alt";
notification.Menu.Items.Add(menuItem);
}
}
}
I could handle this in Vendr Reviews, because Store
node is set a that spefic node type:
https://github.com/vendrcontrib/vendr-reviews/blob/0a3de6329f2a9f94cf15b626a1be9c80e67b8785/src/Vendr.Contrib.Reviews/Notifications/ReviewsTreeNodesNotification.cs#L58Bjarne Fyrstenborg
08/18/2024, 1:51 PMTreeNodesRenderingNotification
to set NodeType
and additional data, but it doesn't seem these are available in MenuRenderingNotification
.
public class TreeNotificationHandler : INotificationHandler<TreeNodesRenderingNotification>
{
public void Handle(TreeNodesRenderingNotification notification)
{
if (notification.TreeAlias.Equals(Umbraco.Cms.Core.Constants.Trees.Content))
{
foreach (var node in notification.Nodes)
{
if (node.AdditionalData.TryGetValue("contentType", out object? contentType) && contentType?.ToString() == Business.ModelTypeAlias)
{
node.NodeType = Business.ModelTypeAlias;
}
}
}
}
}
Ravi
08/18/2024, 7:42 PMBjarne Fyrstenborg
08/18/2024, 8:47 PMMenuRenderingNotification
but from that I can mainly decide if the node is in content tree, but not which node type.
In TreeNodesRenderingNotification
the tree nodes are available including the contentType
.
However this doesn't seem to be passed on MenuRenderingNotification
.
https://cdn.discordapp.com/attachments/1274725978215813212/1274832144912351292/image.png?ex=66c3af74&is=66c25df4&hm=35483a1ee1e3289cc751a8a46ce3fa0807ae9d86066ba97a1c181271d2ece8ce&Ravi
08/19/2024, 10:40 AM