Hi CH,
Maybe I am missing something here, but why do you have a list for a list of links? This might be just simplified for explanation.
I would have used a ContentArea rather than an IList on the OuterBlock.
I see you are using the new way of doing lists as outlined here .
You could say this is a bug however, speak to any developer out there and they will warn you when nesting blocks inside of blocks as the editing experience will be greatly impacted.
Paul
Hi Paul,
Thank you for replying. As you suggest, I actually used a ContentArea in the OuterBlock at first. The reason that I changed to this construct instead was that we wanted to completely hide InnerBlock from editors and only make it possible to create them from within OuterBlock in the UI.
My first thought was to decorate InnerBlock with ContentType(AvailableInEditMode = false), but that would also have lead to not being able to select the InnerBlock type in the ContentArea of OuterBlock. So by changing ContentArea to IList in the OuterBlock I was still able to create InnerBlocks from within OuterBlock. That solution did however give me this problem with the LinkItemCollection not being saved correctly.
I have also tried another approach to hide InnerBlock from editors using the technique described by Paul Gruffydd in this answer, for a question that is very much like my scenario https://world.optimizely.com/forum/developer-forum/CMS/Thread-Container/2015/9/hide-blocktype-from-editmode-but-available-when-combined-with-allowedtypes/#203888.
Using this technique I only succeed in hiding the block type in the global assets panel however. It is still available in ContentAreas in various page and block types. I would like it to be available only in the ContentArea in OuterBlock. I cannot think of any other way than to decorate every ContentArea in the solution with [AllowedTypes(RestrictedTypes = new[] { typeof(InnerBlock) })], which would be a maintenance headache.
Any suggestions on an alternative way to solve this would be highly appreciated.
CH
Hi CH,
The only alternative I can think of is to change the InnerBlock to a standard POCO, and remove the LinkItemCollection.
You would then need to explicity declare the properties you would like e.g.
public class InnerBlock
{
public string Title{get;set;}
public string Name {get;set;}
public url Link {get;set;}
public contentreference{get;set;}
...
}
This would possibly even give you some degree of flexibility.
Paul
Hi,
I have a class structure involving two nested blocks, where the outer block contains an IList of the inner block type. The inner block contains a LinkItemCollection.
In the editor UI, when I add an instance of the outer block to a ContentArea, then add two instances of the inner block to the outer block and then add links to the LinkItemCollection in both instances, it works at first. Both inner block instances has links when I preview the changes. If I then go back to the editor, add another link to one of the inner block instances and publish the changes, the other instance is emptied of all its links.
Is this a bug or is it not supported to have a LinkItemCollection in an inner block?