Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

EditorDescriptor on shared blocks not executing

Vote:
 

I want to extend the group container for my block but when adding a EditorDescriptor it's executed when I use it as a local block but not as a shared block. What's the difference and how can I accomplish this with a shared block?

[EditorDescriptorRegistration(TargetType = typeof(MyBlock))]
public class MyBlockEditorDescriptor : EditorDescriptor
{
	public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable attributes)
	{
		base.ModifyMetadata(metadata, attributes);
		metadata.Properties.Cast().First().GroupSettings.ClientLayoutClass = "MyBlockContainer";
	}
}
#116114
Jan 23, 2015 12:39
Vote:
 

I also noted that if you set TargetType to the block, it only triggers for local blocks. I ended up switching up to using TargetType = typeof(ContentData) and then check in editor descriptor what type of content is being created. That works for shared blocks. Example to hide LinkUrl property on contact block for alloy site:

    [EditorDescriptorRegistration(TargetType = typeof(ContentData))]
    public class MoveFormsPropertyEditorDescriptor : EditorDescriptor
    {
        public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
        {
            var contentDataMetadata = (ContentDataMetadata)metadata;
            if ((contentDataMetadata.Model as ContactBlock != null))
            {
                foreach (var metadataProperty in metadata.Properties)
                {
                    var mp = metadataProperty;
                    if (mp.PropertyName == nameof(ContactBlock.LinkUrl))
                    {
                        mp.ShowForEdit = false;
                    }
                }
            }

            
        }
    }
#223738
Jun 03, 2020 10:13
* 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.