Geta shop
DevelopmentOptimizely
13 februari 2015

Controlling allowed types in a ContentArea using an interface

Given the way that the AllowedTypesAttribute works, you have to specify each type that you might want inside that ContentArea, no inheritance or interfacing allowed. I came up with a fairly simple workaround for situations where you want to control the allowance on all ContentAreas that have no AllowedTypesAttribute defined in the solution. Mainly to avoid having to enter a lot of text.

Step 1: Create an interface

Create a new interface, preferably somewhere where interfaces like to grow.

public interface IContentAreaContent : IContentData { } Step 2: Create a configuration class In the same project as your models. Or modify the below example accordingly.

public static class ModelConfiguration { public static readonly Type[] DefaultAllowedContentTypes = Assembly.GetExecutingAssembly() .GetTypes() .Where(p => typeof(IContentAreaContent).IsAssignableFrom(p) && !p.IsInterface) .ToArray(); } Step 3: Create an EditorDescriptor This step overrides the ContentAreaEditorDescriptor and specifies all the classes that implement IContentAreaContent for you.

Controlling allowed types in a ContentArea using an interface | Geta Digital