In v10 I'm using `MenuRenderingNotification` to ad...
# package-development
d
In v10 I'm using
MenuRenderingNotification
to add a menu item (in this case to the DataTypes tree). This all works. But I only want to add my menu item when the item is actually a DataType and not a Folder (Container). The
Notification
object has stuff like
NodeId
and the tree alias, but how do I tell if the node being clicked on is a folder so I can avoid?
k
I don't think there is anything directly in the notification, I do this :
Copy code
if (int.TryParse(notification.NodeId, out int nodeId))
{
   var container = _entityService.Get(nodeId);
   if (container != null && containerTypes.Contains(container.NodeObjectType))
where containerTypes is an array of the 'container type values'
Copy code
private Guid[] containerTypes = new Guid[]
{
    UmbracoObjectTypes.DocumentTypeContainer.GetGuid(),
    UmbracoObjectTypes.DataTypeContainer.GetGuid(),
    UmbracoObjectTypes.MediaTypeContainer.GetGuid()
};
d
@Kevin Jump Thanks! I should have guessed you'd have worked it out. Though it does seem like something that should be a part of the existing
Notification
metadata.
k
yeah - it probably should include at least the nodeObjectType so you can work it out.
Just looked at the source, and that's how Umbraco is doing it . 😄
Copy code
var container = _entityService.Get(int.Parse(id, CultureInfo.InvariantCulture), UmbracoObjectTypes.DocumentTypeContainer);
if (container != null)
{
  // .... container stuff 
}
else
{
   var ct = _contentTypeService.Get(int.Parse(id, CultureInfo.InvariantCulture));
   // content type stuff