Menu Builder Service

The `UmbNavMenuBuilderService` is the core service that processes menu items. Extend it to customize filtering, content resolution, and item transformation.

Basic Extension

using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Cms.Core.Web;
using Umbraco.Community.UmbNav.Core.Models;
using Umbraco.Community.UmbNav.Core.Services;

public class CustomMenuBuilderService : UmbNavMenuBuilderService
{
    public CustomMenuBuilderService(
        IPublishedContentCache publishedContentCache,
        ILogger<UmbNavMenuBuilderService> logger,
        IHttpContextAccessor httpContextAccessor,
        IUmbracoContextAccessor umbracoContextAccessor,
        IPublishedMediaCache publishedMediaCache)
        : base(publishedContentCache, logger, httpContextAccessor,
               umbracoContextAccessor, publishedMediaCache)
    {
    }
}

Registering Your Service

Override Points

BuildMenu

The main entry point. Override for complete control:

ShouldIncludeItem

Control which items are included in the output:

ResolveContent

Customize how content is resolved from Umbraco:

ResolveImage

Customize image resolution:

ApplyOptions

Modify how build options are applied:

ProcessChildren

Customize child processing:

GetAutoExpandedChildren

Customize how child nodes are auto-expanded:

IsUserLoggedIn

Customize authentication detection:

GetCurrentContentKey

Customize current page detection for active states:

Complete Example: Analytics Integration

Complete Example: Multi-Site Support

Complete Example: Caching Layer

Protected Properties

Access these in your overrides:

Property
Type
Description

PublishedContentCache

IPublishedContentCache

Content cache

PublishedMediaCache

IPublishedMediaCache

Media cache

Logger

ILogger

Logging

HttpContextAccessor

IHttpContextAccessor

HTTP context

UmbracoContextAccessor

IUmbracoContextAccessor

Umbraco context

Testing Your Extension

Last updated

Was this helpful?