IMenuProvider is not rendering after form post?

Vote:
 

Hi!

I have small plugin that displays a log. I have added a new section using the IMenuProvider.

[MenuProvider]
public class HandleProjectsMenuProvider : IMenuProvider
{
    private readonly LocalizationService _localizationService;
    public HandleProjectsMenuProvider(LocalizationService localizationService)
    {
        _localizationService = localizationService;
    }

    public IEnumerable<MenuItem> GetMenuItems()
    {
        var mainMenuItem =
            new SectionMenuItem("MyPlugin", MenuPaths.Global + "/myplugin")
            {
                SortIndex = SortIndex.Last + 100,
                AuthorizationPolicy = CmsPolicyNames.CmsAdmin
            };

        var logMenuItem =
            new UrlMenuItem(_localizationService.GetString("/MyPlugin/DisplayName"),
                MenuPaths.Global + "/myplugin/log", "/MyPlugin/Log/Index")
            {
                SortIndex = 100,
                AuthorizationPolicy = CmsPolicyNames.CmsAdmin
            };
       
        return new List<MenuItem>
        {
            mainMenuItem,
            logMenuItem
        };
    }

When entering /MyPlugin/Log/Index the menu renders just fine. But in my plugin I have button that clears the log by doing a post to /MyPlugin/Log/ClearLog and after the post the menu does not render?
I guess in some way it is because the logMenuItem points to /Log/Index and /Log/ClearLog is not that url.

How do I make sure the meny always renders for all urls that contains /MyPlugin/Log?

Thanks!

/Kristoffer

#269161
Dec 29, 2021 18:08
Vote:
 

I found the solution:

https://world.optimizely.com/documentation/developer-guides/CMS/user-interface/extending-the-navigation/how-to-highlight-parent-menu-items/

But AuthorizationPoliciy cannot be used then IsAvailble has no effect.

This does not work:

var clearLogMenuItem =
    new UrlMenuItem(string.Empty,
        MenuPaths.Global + "/myplugin/log/clearlog", "/MyPlugin/Log/ClearLog")
    {
        IsAvailable = context => false,
        SortIndex = 400,
        AuthorizationPolicy = CmsPolicyNames.CmsAdmin
    };

This does:

var clearLogMenuItem =
    new UrlMenuItem(string.Empty,
        MenuPaths.Global + "/myplugin/log/clearlog", "/MyPlugin/Log/ClearLog")
    {
        IsAvailable = context => false,
        SortIndex = 400
    };

The menu renders but I cannot get the top menu get underlinded after the post and url is /MyPlugin/Log/ClearLog, does anyone know why?

/Kristoffer

#269163
Dec 29, 2021 19:04
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.