Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Martin 4 posts 74 karma points
    Sep 06, 2024 @ 11:56
    Martin
    0

    Implementing Context Menu Item for Content Types in Umbraco 14

    I need to upgrade an existing Umbraco 13 website to Umbraco 14. One of the significant changes in Umbraco 14 is the introduction of a new backoffice, which requires modifications to existing backoffice extensions.

    In my project, I use custom menu items that are tied to specific content types in the content section. In Umbraco 13, I implemented this functionality using the code below. However, the registration of these menu items has changed in Umbraco 14.

    Based on the official documentation, it appears I need to register a "Sidebar Context Menu" in Umbraco 14. Unfortunately, I haven't found a clear example that demonstrates how to replicate the functionality I had in Umbraco 13 using the new approach.

    I’m looking for a complete example or guidance on how to achieve this in Umbraco 14. Any help or suggestions would be greatly appreciated!

    Here is the code I used in Umbraco 13:

    public class BackofficeMenu : IComposer
    {
        public void Compose(IUmbracoBuilder builder)
        {
            builder.AddNotificationHandler<MenuRenderingNotification, MenuRenderingNotificationHandler>();
        }
    }
    
    public class MenuRenderingNotificationHandler : INotificationHandler<MenuRenderingNotification>
    {
        private readonly IPublishedContentQueryAccessor _publishedContentQueryAccessor;
    
        public MenuRenderingNotificationHandler(IPublishedContentQueryAccessor publishedContentQueryAccessor)
        {
            _publishedContentQueryAccessor = publishedContentQueryAccessor;
        }
    
        public void Handle(MenuRenderingNotification notification)
        {
            if (notification.TreeAlias == "content")
            {
                _publishedContentQueryAccessor.TryGetValue(out var publishedContentQuery);
                var content = publishedContentQuery?.Content(notification.NodeId);
    
                if (content != null && content.ContentType.Alias == "frontpage")
                {
                    var smsMessageMenuItem = new MenuItem("smsMessageMenuItem", "SMS messages");
                    smsMessageMenuItem.AdditionalData.Add("actionView", "/path/to/my/custom/view");
                    notification.Menu.Items.Add(smsMessageMenuItem);
                }
            }
        }
    }
    

    enter image description here

  • Alexander Tkacuk 21 posts 122 karma points
    Nov 12, 2024 @ 12:01
    Alexander Tkacuk
    0

    With Umbraco 14, the implementation can be done using "Entity Actions". You can find an example on this feature and more information about it in documentation: https://docs.umbraco.com/umbraco-cms/customize-the-backoffice/extending-overview/extension-types/entity-actions.

Please Sign in or register to post replies

Write your reply to:

Draft