Is there a way to list all the allowed types within a content area? I have been using the ContentTypeAvailabilityService for pages (GetSetting() then accessing AllowedContentTypeNames).
I would also like to view/list the available content types for a contentarea so does anyone know if there is a way to do this for a property (specifically a content area)?
Hi Gustav, one thing you can do is get the AllowedTypes attribute for the content area property using reflection.
var allowedTypesAttribute = typeof(MyContentType)
.GetCustomAttribute(typeof(AllowedTypesAttribute)) as AllowedTypesAttribute;
var allowedTypes = allowedTypesAttribute?.AllowedTypes;
The only problem I can see with this is that internally the allowed types are also filtered by user permissions among other things using the ContentTypeAvailabilityService. Sadly some of the methods used for this are not public. However in order to do this yourself you can first get all the available content types using the ListAvailable method.
var availableTypes = _contentTypeAvailabilityService.ListAvailable("MyContentType", PrincipalInfo.Current.Principal);
And then compare the available types with the allowed types in order to filter out any types that not available to the user. I will leave this bit up to you if this is what you require. Hope this helps 😀
Hi, you can do this by getting all the usage of content data which will give you all contents on your site.
here is example code but you need to modify it according to you I've made it generic,
private IEnumerable<T> GetDataList<T>()
where T : ContentData
var objectType = _contentTypeRepository.Load<T>();
var usages = _contentModelUsage.ListContentOfContentType(objectType)
.Select(x => x.ContentLink.ToReferenceWithoutVersion())
.Select(x => _contentLoader.Get<IContentData>(x))