Override built-in page / block properties

Vote:
 

Is there a way to override built-in page type properties. I am working on a multi-lingual website and I want to make certain properties like SortOrder, VisibleInMenu, etc to be CultureSpecific? 

#79963
Jan 11, 2014 0:10
Vote:
 

They are virtual, so you could override them:

        [CultureSpecific]
        public override bool VisibleInMenu { get; set; }

    

#79965
Jan 11, 2014 9:37
Vote:
 

However, "SortOrder" is an internal metadata property. I doubt you could make that culture specific.

#79966
Jan 11, 2014 11:01
Vote:
 

Hi Per

 

I tried to override the VisibleInMenu property and it just duplicated the property. I ended up having two properties with the same name.

Any other suggestions on how we can achieve culture specific sort order and visible in menu ?

#80091
Jan 14, 2014 22:26
Vote:
 

I have the same problem as Sayeed, doing like Per Magne saying dublicates the property.

Any updates on this?

#117098
Feb 11, 2015 16:09
Vote:
 

Here is a thing you could try (at your own risk!!!):

Create a new property:

        [Display(Name = "Display in navigation", GroupName = "EPiServerCMS_SettingsPanel", Order = 2)]
        [CultureSpecific]
        public virtual bool VisibleinMenuHack { get; set; }

You can replace the built in VisibleInMenu property with the VisibleInMenuHack property. Notice the GroupName? This will put the property in the settings area. An IMetaDataExtender is needed in order to hide the old one from edit mode:

    public class SiteMetadataExtender : IMetadataExtender
    {
        public void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
        {
            foreach (ExtendedMetadata property in metadata.Properties)
            {
                if
                   (property.PropertyName == "PageVisibleInMenu")
                {
                    property.ShowForEdit = false;
                }
            }
        }
    }

Then, the IMetadataExtender must be registered:

    [InitializableModule]
    [ModuleDependency(typeof (EPiServer.Cms.Shell.InitializableModule))]
    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 Preload(string[] parameters){} 
        public void Uninitialize(InitializationEngine context) { }
    }

Now they are swapped - but the value from the old property will still be used by the system, whenever lists are rendered and such. So here is the last part of the puzzle(might be risky!!):

On your content model, make sure that whenever the value for the old property is fetched, the property from VisibleInMenuHack is fetched instead:

        [Ignore]
        public override object this[string index]
        {
            get
            {
                if (index == "PageVisibleInMenu")
                {
                    return VisibleinMenuHack;
                }
                return base[index];
            }
            set { base[index] = value; }
        }

... And you should have a culture specific "VisibleInMenu". I suppose you could do the same for SortOrder

#117387
Edited, Feb 19, 2015 18:03
Vote:
 

What you might do is hide the built-in property with an editor descriptor and create a new one that is culture specific:

  [EditorDescriptorRegistration(TargetType = typeof(bool))]
  [EditorDescriptorRegistration(TargetType = typeof(bool?))]
    public class HideVisibleInMenuEditorDescriptor : EditorDescriptor
    {
        public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
        {
            base.ModifyMetadata(metadata, attributes);

            if (metadata.PropertyName == "PageVisibleInMenu")
            {
                metadata.ShowForEdit = false;
            }
        }
    }

Now, I am not sure if there is a way to force the new property to be shown in the grey area, I think I saw a blog or forum post on it, but I cannot find it now.

This does not really fix the problem, especially with sort order.

BR,

Marija

#117410
Feb 20, 2015 9:58
Vote:
 

Ah, sorry, I haven't seen that Per already answered :)

#117411
Feb 20, 2015 9:59
Vote:
 

And I have written a slightly simpler example that works for Episerver CMS 7.5 and later:

http://world.episerver.com/blogs/Linus-Ekstrom/Dates/2014/2/Tweaking-the-settings-header-in-EPiServer-75/

#151674
Aug 03, 2016 15:21
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.