joshb
joshb

Reputation: 5220

Hide item from Settings menu

I created a custom part and attached it to the Site part/content item via an ActivatingFilter in my part's handler (similar to what's described here). I also added a Settings menu item to edit the part by overriding the handler's GetItemMetadata method and adding a GroupInfo object for it. This works and I'm able to edit my part as expected.

Here's what my part's handler looks like:

public class ProductSettingsPartHandler : ContentHandler {
        public ProductSettingsPartHandler() {
            T = NullLocalizer.Instance;
            Filters.Add(new ActivatingFilter<ProductSettingsPart>("Site"));
        }

        public Localizer T { get; set; }

        protected override void GetItemMetadata(GetContentItemMetadataContext context) {
            if (context.ContentItem.ContentType != "Site")
                return;
            base.GetItemMetadata(context);

            // If I remove the following call, I can't use the site settings AdminController anymore.
            // But if I make this call, a menu item will be added to the Settings section - which I don't want.
            context.Metadata.EditorGroupInfo.Add(new GroupInfo(T("Pricing")) {
                Id = "Pricing",
                Position = "4.2"
            });
        }
    }

Now I'd like to move the menu item to another section. I can create the new menu item by implementing INavigationProvider and providing it the route to the settings AdminController for my part. However, when I try to remove the original menu item from the Settings menu (by no longer adding the GroupInfo object) my new menu item link doesn't work anymore.

Based on my research, it looks like the settings AdminController is doing an explicit check to make sure a GroupInfo object has been added for the part or it won't return the view to edit it. This seems to make it impossible to use the settings AdminController to edit parts attached to the Site content part but not show them in the Settings menu section.

Any suggestions or ideas on how to get around this? My end goal is to treat this site settings part just like any other but have the menu item that's used to update it display in another section of the admin menu.

I'm developing off of the Orchard 1.x branch if that makes any difference.

Thanks!

Upvotes: 3

Views: 540

Answers (1)

Piotr Szmyd
Piotr Szmyd

Reputation: 13366

In order to display a given part editor on a specific group only, replace

ContentShape("<your editor name>", () => ...);

with

ContentShape("<your editor name>", () => ...).OnGroup("Pricing");

inside the Editor method of the driver for your part. In addition to what you've already done with the handler above.

UPDATE:

After re-reading your question twice again I think I initially misunderstood the problem. You want the AdminController to continue working, but the provided group should not appear under Settings.

This is not possible without overriding the default Orchard behavior. Default settings AdminController requires the group to exist, which in turn makes it always appear in the menu.

The easiest solution is to create your own controller to which you'll point the admin link. Copying and pasting the current AdminController and removing all GroupInfo-related checks from it should do the trick.

Upvotes: 2

Related Questions