Try our conversational search powered by Generative AI!

Hide default category property

Vote:
 

Hi!

Does anyone know how to hide the default category property in Optimizely 12? The editor descriptor with the scaffold attribute works in older versions, but it doesn't seem to work in version 12.

#299983
Apr 12, 2023 13:14
Vote:
 

Have a look at Geta.Optimizely.Categories repo they have an example here on how it can be achieved using an editor descriptor. I tested on a CMS12 site and looks to work 

geta-optimizely-categories/HideCategoryEditorDescriptor.cs at master · Geta/geta-optimizely-categories (github.com) 

   /// <summary>
   /// Hides the categories drop down list for types where it is not needed
   /// </summary>
    [EditorDescriptorRegistration(TargetType = typeof(CategoryList), EditorDescriptorBehavior = EditorDescriptorBehavior.Default)]
    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;
            }
        }
    }
#299984
Edited, Apr 12, 2023 13:29
Vote:
 

Thanks. I tried it in an Alloy solution here, and it works there. So I guess it must be something in our solution that is causing it not to work.

#299990
Apr 12, 2023 15:14
Vote:
 

ScaffoldColumn(false) seems to work on custom made properties but not on Optimizely native ones ie Category. Following code will work on all properties. This will keep the functionality as it was in Epi11.

[ModuleDependency(
        typeof(InitializationModule)
    )]
    public class SiteMetadataExtenderInitialization : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {
            if (context.HostType == HostType.WebApplication)
            {
                var registry = context.Locate.Advanced.GetInstance<MetadataHandlerRegistry>();
                registry.RegisterMetadataHandler(typeof(ContentData), new SiteMetadataExtender());
            }
        }

        public void Uninitialize(InitializationEngine context)
        {
        }
    }

public class SiteMetadataExtender : IMetadataExtender
    {
        public void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
        {
            foreach (ExtendedMetadata property in metadata.Properties)
            {
                foreach (var attribute in property.Attributes)
                {
                    if (attribute is ScaffoldColumnAttribute s)
                    {
                        if (s.Scaffold == false)
                        {
                            property.ShowForEdit = false;
                        }                        
                    }
                }
            }
        }

}

And on the property

[ScaffoldColumn(false)]
public virtual CategoryList Category { get; set; }

#310346
Edited, Oct 10, 2023 13:04
Vote:
 

I managed to solve it like this:

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

            if (metadata.PropertyName == "icategorizable_category")
            {
                metadata.ShowForEdit = false;
            }
        }
    }
#310685
Oct 12, 2023 7:33
Carl Schéle - Oct 12, 2023 8:01
Doesn't this solution hide all category properties on every page?
Vote:
 

No, it seems to work. If I add a new CategoryList property, it shows up.

#310687
Oct 12, 2023 8:26
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.