Hi Edwin,
You will more than likely need to introduce a custom model for the IList e.g.
public class CustomListObjectItem
{
public virtual ContentReference Content {get; set;}
}
....
public virtual IList<CustomListObjectItem> ListContent
You can then add your EditorDescriptor etc to the property of the custom model.
Let me know if you need more help.
Thanks
Paul
Hi Paul,
Thank you for your swift response.
That does sound like a solution that would work in and of itself, but in our context it would not be the preferred solution.
Allow me to elaborate.
This topic came up as part of a migration from CMS11 to CMS12.
In CMS11, the IList<ContentReference> property looked like the following:
[Display(
Name = "Product calculator underlyings to exclude",
GroupName = GroupNames.Products,
Order = 1040,
Description = "When a underlying is present in the list, the option 'product calculator' on the product detail is hidden")]
[UIHint("UnderlyingContent")]
[AllowedTypes(typeof(UnderlyingContent))]
[UnderlyingContentRoot]
public virtual IList<ContentReference> ProductCalculatorExcludedUnderlyings { get; set; }
The related UnderlyingContentRoot, that worked for both ContentReference and IList<ContentReference>, looked as follows:
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class UnderlyingContentRootAttribute : Attribute, IMetadataAware
{
public void OnMetadataCreated(ModelMetadata metadata)
{
var extendedMetadata = metadata as ExtendedMetadata;
var siteSettings = ServiceLocator.Current.GetInstance<ISiteSettingsFactory>().Find();
if (!siteSettings.HasValue)
{
return;
}
if (extendedMetadata == null)
{
return;
}
if (siteSettings.Value.UnderlyingDetailPage != null)
{
extendedMetadata.EditorConfiguration["roots"] = new[] { siteSettings.Value.UnderlyingDetailPage.ID };
}
}
}
Unfortunately, IMetadataAware is no longer available in .NET 6.0, but it is hard to imagine that there would not be an equivalent implementation possible in CMS12/.NET 6.0. It actually surprises us that the EditorDescriptors apparently do not work in the same way.
So to get back to your suggestion: the introduction of an intermediate model would introduce the challenge of migrating the current data to said new model structure as well. This was also not the only property that was implemented along these lines.
Ideally, we would just keep using IList<ContentReference> as before.
As a collegue of Edwin, we solved it by adding an extra EditorDescriptorRegistration for the IList<ContentReferences>, the behaviour is key to support both
For future references, these are the attributes to add
[EditorDescriptorRegistration(TargetType = typeof(ContentReference), UIHint = nameof(VirtualUnderlyingContentDescriptor))]
[EditorDescriptorRegistration(TargetType = typeof(IList<ContentReference>), UIHint = nameof(VirtualUnderlyingContentDescriptor), EditorDescriptorBehavior = EditorDescriptorBehavior.ExtendBase)]
We have a page in our application with various properties, for which we use AllowedTypes to restrict which content can be selected.
This is an example of such a property:
The accompanying EditorDescriptor looks as follows:
So far, this all works perfectly; when selecting an item, the content selector pop-up neatly opens the correct node to select content from.
We are now trying to accomplish the same for a collection, but this does not work with the same EditorDescriptor:
Can anyone tell me how to implement an EditorDescriptor for an IList<ContentReference>?
I know of the existence of ContentReferenceListEditorDescriptor, for instance, but I cannot find any examples of implementations that use this.
With the documentation available I have not been able to figure out how it works either.