When editing EPiServer property pages, I want to hide certain tabs for a page depending upon the site. I found a snippet of code on the web which looks like the following (I've modified it slightly to suit my needs):
[EPiServer.Shell.ObjectEditing.EditorDescriptors.EditorDescriptorRegistration(TargetType = typeof(EPiServer.Core.ContentData))]
public class SiteMetadataExtender : EPiServer.Shell.ObjectEditing.EditorDescriptors.EditorDescriptor
{
public override void ModifyMetadata(EPiServer.Shell.ObjectEditing.ExtendedMetadata metadata, System.Collections.Generic.IEnumerable<System.Attribute> attributes)
{
List<string> groupsToHide = new List<string> { "Tab1", "Tab2" }
if (SiteDefinition.Current.Name == "Site1" || SiteDefinition.Current.Name == "Site2")
{
foreach (EPiServer.Shell.ObjectEditing.ExtendedMetadata property in metadata.Properties)
{
if (property.GroupSettings != null && groupsToHide.Contains(property.GroupSettings.Name))
{
property.GroupSettings.DisplayUI = false;
return;
}
}
}
}
}
This code gets fired when I open a property page, however through most iterations, property.GroupSettings is null and I am not seeing my custom tabs enumerated.
Does anyone know how to fix this? Is this even the proper code to handle this scenario?
Thanks.