Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

List of blocks - how to get the advertised editor experience?

Vote:
 

Hi,

I am reading the official documentation here: "://docs.developers.optimizely.com/content-cloud/v12.0.0-content-cloud/docs/property-value-list" on how to create list properties. What I would like to do is to create a property that is a list of a custom block type (such as Contact in the docs).

public virtual IList<ContactBlock> Contacts { get; set; }

Obviously, I have a block type called ContactBlock.

But the result in the CMS edit mode is always a plain textarea and not the fancy list view shown in the docs. What am I doing wrong? My CMS version is 12.6.1

#296255
Feb 09, 2023 14:04
Vote:
 

If the ContactBlock is a standard block (i.e. not Local) would it not be better for you to use a ContentArea. 

[AllowedTypes(new[] { typeof(ContactBlock) })]
public virtual ContentArea Contacts {get;set;} 

If you still wanting to use an IList you will need to create an EditorDescriptor and decorate your property 

#296256
Edited, Feb 09, 2023 14:19
Emil - Feb 09, 2023 14:40
Thanks for the reply. I know of the ContentArea way of doing it but would appreciate some more input on what I have to do with the EditorDescriptor in regards to IList as the docs don't mention this.
Vote:
 

As an alternative to Minesh's suggestion and what the documentation say I sometimes use IList<ContentReference> limiting it using AllowedTypes

[Display(
    Name = "Kontakt",
    GroupName = SystemTabNames.Content,
    Order = 120)]
[AllowedTypes(AllowedTypes = new[] { typeof(ContactBlock) })]
public virtual IList<ContentReference> Contacts { get; set; }

This will render a control looking like this in CMS 12, the items in the list is draggable and droppable

#296258
Edited, Feb 09, 2023 14:39
Emil - Feb 09, 2023 14:42
Interesting, thanks! Is there a way of achieving this using the ContentDefinitions API (enforcing specific type(s))
Emil - Feb 09, 2023 14:44
...and a follow up question. Have you been able to get the IList[ContactBlock] - solution to work?
Minesh Shah (Netcel) - Feb 09, 2023 15:11
Eric’s suggestion is recommended over using a PropertyList as it will allow you to drag Blocks in where PropertList will not
Eric Herlitz - Feb 09, 2023 15:16
The general recommendation is to use IList with complex types with caution (ContentReference is not a complex type in this context). Regarding content definitions you can check supported datatypes in your instance using the url /api/episerver/v3.0/propertydatatypes but the one you are looking for should be called PropertyContentReferenceList (https://docs.developers.optimizely.com/content-cloud/v1.7.0-content-definitions-api/docs/property-data-types#common-property-data-types). I can't answer if AllowedTypes is allowed, I can have a look at it.
Emil - Feb 09, 2023 15:43
Thanks, Eric (and Minesh)! Really appreciate it. Regarding complex types in lists I thought the generic implementation (://docs.developers.optimizely.com/content-cloud/v12.0.0-content-cloud/docs/generic-propertylist) was the one to avoid? The generic documentation even suggests instead using IList[ContactBlock] (where ContactBlock is BlockData). I am still wondering why I don't get the editor experience described in the documentation when using IList.
Eric Herlitz - Feb 09, 2023 15:44
As do I, I would say the documentation is incomplete and incorrect.
Emil - Feb 09, 2023 15:51
Haha! A shame though as this looks a really good option. Guess PropertyContentReferenceList is the way forward (we have to use the Content Definitions API). If you find a way to restrict types using the API that would be pure gold! :)
Vote:
 

Here is One Example

    [EditorDescriptor(EditorDescriptorType = typeof(CollectionEditorDescriptor<ContactBlock>))]
    public virtual IList<ContactBlock> Contacts { get; set; }
}

[PropertyDefinitionTypePlugIn]
public class ContactOptionPropertyList : PropertyListBase<ContactBlock>
{
}

public class PropertyListBase<T> : PropertyList<T>
{
    private readonly IObjectSerializer _objectSerializer;

    private Injected<IObjectSerializerFactory> _objectSerializerFactory;

    public PropertyListBase()
    {
        _objectSerializer = _objectSerializerFactory.Service.GetSerializer("application/json");
    }

    public PropertyListBase(IObjectSerializer serializer)
    {
        _objectSerializer = serializer;
    }

    protected override T ParseItem(string value)
    {
        return _objectSerializer.Deserialize<T>(value);
    }
}

Although the editor experience will look like 

#296270
Edited, Feb 09, 2023 14:57
Vote:
 

The UI support for IList<BlockData> was included in the CMS UI version that was unlisted and then removed IIRC. This should be available again in 12.18. The documentation was never updated when the version was delisted. Sorry for any inconvenience.

#296515
Edited, Feb 14, 2023 13:22
Emil - Feb 14, 2023 14:23
Thanks! That sounds promising. :)
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.