https://discord.umbraco.com logo
#package-development
Title
# package-development
d

dandiplo

06/30/2022, 6:10 PM
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

kevinjump

07/01/2022, 9:10 AM
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

dandiplo

07/01/2022, 10:13 AM
@kevinjump 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

kevinjump

07/01/2022, 10:15 AM
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