Simple sample on how to use interfaces and allowed types on cms 12

  • Updated
Description

This is a simple example on how to use interfaces with blocks and AllowedTypes on contentareas using cms 12

Steps

1. Interface should be inherited from IContentData

public interface ISpecificBlock : IContentData{}

2. Custom interface should have individual UI Descriptor

/// <summary>
/// Represents a UI descriptor for ISpecificBlock content.
/// </summary>
[UIDescriptorRegistration]
public class SpecificBlockUIDescriptor : UIDescriptor<ISpecificBlock>
{
    /// <summary>
/// Initializes a new instance of the <see cref="SpecificBlockUIDescriptor"/> class.
/// </summary>
public SpecificBlockUIDescriptor()
        : base(ContentTypeCssClassNames.SharedBlock)
    {
        IsPrimaryType = true;
        ContainerTypes = new Type[] { typeof(ContentFolder) }; // list block folder in restore dialog only, since block cannot be moved into another block.
        SortKey = new SortColumn { ColumnName = "typeIdentifier", SortDescending = true };
        CommandIconClass = "epi-iconCreateSharedBlock";
    }

    public bool ActAsAnAsset { get { returntrue; } }
}

Block inheriting from interface

public class JumbotronBlock : SiteBlockData, ISpecificBlock 
Using interface with AllowedTypes
[AllowedTypes(new[] { typeof(ISpecificBlock ) })]
public virtual ContentArea RelatedContentArea { get; set; }