Code sample

Hiding EPiServer's standard Category property

using System.Collections.Generic;
using EPiServer.Core;
using EPiServer.Shell.ObjectEditing;
using EPiServer.Shell.ObjectEditing.EditorDescriptors;

namespace MySite.EditorDescriptors
{
   [EditorDescriptorRegistration(TargetType = typeof(CategoryList))]
   public class HideCategoryEditorDescriptor : EditorDescriptor
   {
      public override void ModifyMetadata(
         ExtendedMetadata metadata,
         IEnumerable<Attribute> attributes)
      {
         base.ModifyMetadata(metadata, attributes);
         if (metadata.PropertyName == "icategorizable_category")
         {
            metadata.ShowForEdit = false;
         }
      }
   }
}

Moving it to a different tab, illustrated by the Settings tab in the example below:

using System.Collections.Generic;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.Shell.ObjectEditing;
using EPiServer.Shell.ObjectEditing.EditorDescriptors;

namespace MySite.EditorDescriptors
{
   [EditorDescriptorRegistration(TargetType = typeof(CategoryList))]
   public class HideCategoryEditorDescriptor : EditorDescriptor
   {
      public override void ModifyMetadata(
         ExtendedMetadata metadata,
         IEnumerable<Attribute> attributes)
      {
         base.ModifyMetadata(metadata, attributes);
         if (metadata.PropertyName == "icategorizable_category")
         {
            metadata.GroupName = SystemTabNames.Settings;
         }
      }
   }
}

For a specific page type only, illustrated as ArticlePage below:

using System.Collections.Generic;
using EPiServer.Core;
using EPiServer.Shell.ObjectEditing;
using EPiServer.Shell.ObjectEditing.EditorDescriptors;

namespace MySite.EditorDescriptors
{
   [EditorDescriptorRegistration(TargetType = typeof(CategoryList))]
   public class HideCategoryEditorDescriptor : EditorDescriptor
   {
      public override void ModifyMetadata(
         ExtendedMetadata metadata,
         IEnumerable<Attribute> attributes)
      {
         base.ModifyMetadata(metadata, attributes);

         dynamic mayQuack = metadata;
         var ownerContent = mayQuack.OwnerContent;
         if (ownerContent is ArticlePage
&& metadata.PropertyName == "icategorizable_category")
         {
            metadata.GroupName = SystemTabNames.Settings;
         }
      }
   }
}

For a specific page type only, without using dynamic but with reference to EPiServer.Cms.Shell.UI.dll (not recommended unless we're building an add-on):

using System.Collections.Generic;
using EPiServer.Cms.Shell.UI.ObjectEditing;
using EPiServer.Core;
using EPiServer.Shell.ObjectEditing;
using EPiServer.Shell.ObjectEditing.EditorDescriptors;

namespace MySite.EditorDescriptors
{
   [EditorDescriptorRegistration(TargetType = typeof(CategoryList))]
   public class HideCategoryEditorDescriptor : EditorDescriptor
   {
      public override void ModifyMetadata(
         ExtendedMetadata metadata,
         IEnumerable<Attribute> attributes)
      {
         base.ModifyMetadata(metadata, attributes);

         var contentMetadata = (ContentDataMetadata) metadata;
         var ownerContent = contentMetadata.OwnerContent;
         if (ownerContent is ArticlePage
&& metadata.PropertyName == "icategorizable_category")
         {
            metadata.GroupName = SystemTabNames.Settings;
         }
      }
   }
}
Joel Abrahamsson

Joel Abrahamsson

I'm a passionate web developer and systems architect living in Stockholm, Sweden. I work as CTO for a large media site and enjoy developing with all technologies, especially .NET, Node.js, and ElasticSearch. Read more

More about EPiServer CMS