November Happy Hour will be moved to Thursday December 5th.

Class AvailableContentTypesAttribute

Defines which content types that should be available under a ContentType

Inheritance
System.Object
System.Attribute
AvailableContentTypesAttribute
Implements
System.Runtime.InteropServices._Attribute
Inherited Members
System.Attribute.GetCustomAttributes(System.Reflection.MemberInfo, System.Type)
System.Attribute.GetCustomAttributes(System.Reflection.MemberInfo, System.Type, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.MemberInfo)
System.Attribute.GetCustomAttributes(System.Reflection.MemberInfo, System.Boolean)
System.Attribute.IsDefined(System.Reflection.MemberInfo, System.Type)
System.Attribute.IsDefined(System.Reflection.MemberInfo, System.Type, System.Boolean)
System.Attribute.GetCustomAttribute(System.Reflection.MemberInfo, System.Type)
System.Attribute.GetCustomAttribute(System.Reflection.MemberInfo, System.Type, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.ParameterInfo)
System.Attribute.GetCustomAttributes(System.Reflection.ParameterInfo, System.Type)
System.Attribute.GetCustomAttributes(System.Reflection.ParameterInfo, System.Type, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.ParameterInfo, System.Boolean)
System.Attribute.IsDefined(System.Reflection.ParameterInfo, System.Type)
System.Attribute.IsDefined(System.Reflection.ParameterInfo, System.Type, System.Boolean)
System.Attribute.GetCustomAttribute(System.Reflection.ParameterInfo, System.Type)
System.Attribute.GetCustomAttribute(System.Reflection.ParameterInfo, System.Type, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.Module, System.Type)
System.Attribute.GetCustomAttributes(System.Reflection.Module)
System.Attribute.GetCustomAttributes(System.Reflection.Module, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.Module, System.Type, System.Boolean)
System.Attribute.IsDefined(System.Reflection.Module, System.Type)
System.Attribute.IsDefined(System.Reflection.Module, System.Type, System.Boolean)
System.Attribute.GetCustomAttribute(System.Reflection.Module, System.Type)
System.Attribute.GetCustomAttribute(System.Reflection.Module, System.Type, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.Assembly, System.Type)
System.Attribute.GetCustomAttributes(System.Reflection.Assembly, System.Type, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.Assembly)
System.Attribute.GetCustomAttributes(System.Reflection.Assembly, System.Boolean)
System.Attribute.IsDefined(System.Reflection.Assembly, System.Type)
System.Attribute.IsDefined(System.Reflection.Assembly, System.Type, System.Boolean)
System.Attribute.GetCustomAttribute(System.Reflection.Assembly, System.Type)
System.Attribute.GetCustomAttribute(System.Reflection.Assembly, System.Type, System.Boolean)
System.Attribute.Equals(System.Object)
System.Attribute.GetHashCode()
System.Attribute.Match(System.Object)
System.Attribute.IsDefaultAttribute()
System.Attribute.System.Runtime.InteropServices._Attribute.GetTypeInfoCount(System.UInt32)
System.Attribute.System.Runtime.InteropServices._Attribute.GetTypeInfo(System.UInt32, System.UInt32, System.IntPtr)
System.Attribute.System.Runtime.InteropServices._Attribute.GetIDsOfNames(System.Guid, System.IntPtr, System.UInt32, System.UInt32, System.IntPtr)
System.Attribute.System.Runtime.InteropServices._Attribute.Invoke(System.UInt32, System.Guid, System.UInt32, System.Int16, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr)
System.Attribute.TypeId
System.Object.ToString()
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer.DataAnnotations
Assembly: EPiServer.dll
Version: 11.20.7
Syntax
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class AvailableContentTypesAttribute : Attribute, _Attribute, IContentTypeAvailableModelSetting
Remarks

The diffent properties of the attribute are applied in the following way:

  • Include implicitly exclude all PageTypes not in the list.
  • Exclude implicitly include all PageTypes not in the list.
  • IncludeOn and ExcludeOn combine with the settings on the target PageType. If there is a conflict Exclude/ExcludeOn have precedency over Include/IncludeOn.

Refer to "Attributes" and "Pages, Page Types and Page Templates" under "Content" in the Developer Guide for more information and examples.

Examples
      Here is an example on how you can set available page types on your page types using this attribute.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EPiServer.Core;
using EPiServer.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using EPiServer.Security;
using EPiServer;
using EPiServer.Web;
using EPiServer.Shell.ObjectEditing.EditorDescriptors;
using EPiServer.Shell.ObjectEditing;
using EPiServer.DataAbstraction;

namespace CodeSamples
{
[ContentType(
DisplayName="My Page Type",
Description="Description for this page type",
Order=1024,
GUID="9CBBF910-CB5A-4C72-83AA-EDCF02E8A2BD",
GroupName="My Group",
AvailableInEditMode=true)]
[AvailableContentTypes(Include = new Type[] { typeof(MyPageType2), typeof(MyPageType3) })]
[Access(Users = "niis", Roles = "CmsEditors")]
public class TypedPageWithAttributeSample : PageData
{
[Required]
[Searchable]
[CultureSpecific]
[Editable(true)]
[Display(
Name = "My Heading",
Description = "Heading for my page type.",
GroupName = "My Tab",
Order = 64)]
public virtual string Heading { get; set; }

//An integer between 0 and 130.
[Range(0, 130)]
public virtual int Age { get; set; }

//Validating against a given regular expression.
[RegularExpression("[SomeRegularExpression]")]
public virtual string CustomValidation { get; set; }

//A string with a maximum length of 20 characters.
[StringLength(20)]
public virtual string Header { get; set; }

//Any URL
public virtual Url RedirectPage { get; set; }

//Reference to an image in the EPiServer media system.
[UIHint(UIHint.Image)]
public virtual ContentReference Logotype { get; set; }

//URL to image is also supported but mostly for upgrade support or when there is a need to add custom query parameters to the URL.
[UIHint(UIHint.Image)]
public virtual Url LogotypeAsUrl { get; set; }

//Creates a selection of predefined values.
[SelectOne(SelectionFactoryType=typeof(CustomLanguageSelectionFactory))]
public virtual string LanguageSelection { get; set; }

//Creates a selection of predefined values with the option to select several items.
[SelectMany(SelectionFactoryType=typeof(CustomLanguageSelectionFactory))]
public virtual string MultipleLanguageSelection { get; set; }
}

public class CustomLanguageSelectionFactory : ISelectionFactory
{
public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
{
var languages = new List<SelectItem>();

languages.Add(new SelectItem() { Text = "English", Value = "en"});
languages.Add(new SelectItem() { Text = "Swedish", Value = "sv" });
languages.Add(new SelectItem() { Text = "Norwegian", Value = "no" });

return languages;
}
}

[AvailableContentTypes(IncludeOn = new Type[] { typeof(TypedPageWithAttributeSample) })]
[ContentType]
public class MyPageType1 : PageData { }

[AvailableContentTypes(Exclude = new Type[] { typeof(TypedPageWithAttributeSample) })]
[ContentType]
public class MyPageType2 : PageData { }

[AvailableContentTypes(ExcludeOn = new Type[] { typeof(MyPageType1) })]
[ContentType]
public class MyPageType3 : PageData { }

[AvailableContentTypes(Availability = Availability.None)]
[ContentType]
public class MyPageType4 : PageData { }
}

Constructors

AvailableContentTypesAttribute()

Initializes a new instance of the AvailableContentTypesAttribute class.

Declaration
public AvailableContentTypesAttribute()

AvailableContentTypesAttribute(Availability)

Initializes a new instance of the AvailableContentTypesAttribute class.

Declaration
public AvailableContentTypesAttribute(Availability availability)
Parameters
Type Name Description
Availability availability

Properties

Availability

Gets or sets wether none ContentType should be available to create under the ContentType that has this attribute set.

Declaration
public Availability Availability { get; set; }
Property Value
Type Description
Availability

true if no ContentType is available; otherwise, false.

Exclude

Gets or sets the typed pages that are not available under an instance of a page of corresponding PageType.

Declaration
public Type[] Exclude { get; set; }
Property Value
Type Description
System.Type[]

The available page types.

ExcludeOn

Will exclude the typed page from the list of available ContentType for the specified typed pages.

Declaration
public Type[] ExcludeOn { get; set; }
Property Value
Type Description
System.Type[]

The available page types.

Include

Gets or sets the typed pages that are available under an instance of a page of corresponding ContentType.

Declaration
public Type[] Include { get; set; }
Property Value
Type Description
System.Type[]

The available page types.

IncludeOn

Will make the typed page available as child under the specified typed pages.

Declaration
public Type[] IncludeOn { get; set; }
Property Value
Type Description
System.Type[]

The available page types.

Explicit Interface Implementations

IContentTypeAvailableModelSetting.Exclude

Gets the typed pages that are not available under an instance of a page of corresponding PageType.

Declaration
IEnumerable<Type> IContentTypeAvailableModelSetting.Exclude { get; }
Returns
Type Description
System.Collections.Generic.IEnumerable<System.Type>

The available page types.

IContentTypeAvailableModelSetting.ExcludeOn

Will exclude the typed page from the list of available PageType for the specified typed pages.

Declaration
IEnumerable<Type> IContentTypeAvailableModelSetting.ExcludeOn { get; }
Returns
Type Description
System.Collections.Generic.IEnumerable<System.Type>

The available page types.

IContentTypeAvailableModelSetting.Include

Gets the typed pages that are available under an instance of a page of corresponding PageType.

Declaration
IEnumerable<Type> IContentTypeAvailableModelSetting.Include { get; }
Returns
Type Description
System.Collections.Generic.IEnumerable<System.Type>

The available page types.

IContentTypeAvailableModelSetting.IncludeOn

Will make the typed page available as child under the specified typed pages.

Declaration
IEnumerable<Type> IContentTypeAvailableModelSetting.IncludeOn { get; }
Returns
Type Description
System.Collections.Generic.IEnumerable<System.Type>

The available page types.

Implements

System.Runtime.InteropServices._Attribute

Extension Methods

See Also

PageTypeAttribute
AccessAttribute