Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply permissions to menu items #13

Open
fzadrazil opened this issue Sep 7, 2020 · 1 comment
Open

Apply permissions to menu items #13

fzadrazil opened this issue Sep 7, 2020 · 1 comment

Comments

@fzadrazil
Copy link

The module currently applies only to pages. When I try to add the Content Permissions Part to menu item (CustomLink or ContentLink), it doesn't affect rendering of the menu. I've tried to find some way how to implement this and extend the module, but can't get to it. Use some filter maybe?

@FrancoisCamus
Copy link

Hi!

I had the same concern and had to override the default MenuItem.cshtml view to modify its behaviour.

@inject Etch.OrchardCore.ContentPermissions.Services.IContentPermissionsService ContentPermissionsService

@{
    // We are modifiyng the default behaviour to check for permissions
    if (!ContentPermissionsService.CanAccess(Model.ContentItem))
    {
        return;
    }

    TagBuilder tag = Tag(Model, "li");

    // Morphing the shape to keep Model untouched
    Model.Metadata.Alternates.Clear();
    Model.Classes.Clear();
    Model.Metadata.Type = "MenuItemLink";

    tag.InnerHtml.AppendHtml(await DisplayAsync(Model));

    if ((bool)Model.HasItems)
    {
        tag.InnerHtml.AppendHtml("<ul>");

        foreach (var item in Model.Items)
        {
            tag.InnerHtml.AppendHtml(await DisplayAsync(item));
        }

        tag.InnerHtml.AppendHtml("</ul>");
    }
}

@tag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants