Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tom 713 posts 952 karma points
    Jan 21, 2014 @ 03:23
    Tom
    0

    API v7 Allow a node to create child of type.. i.e. add to structure list

    Hi I wanted to know in code how can I allow a doc type to add a value to the structure ending up in the cmsContentTypeAllowedContentType table.

    I've tried extending the Content Types AllowedContentTypes array but am not sure if that's the right way to do it:

    var newContentTypeSize = parentType.AllowedContentTypes.Count() + 1;
                        Array.Resize(ref allowedChildContentTypes, newContentTypeSize);
    
                        var currentSort = allowedChildContentTypes.Max(c => c.SortOrder);
                        allowedChildContentTypes[newContentTypeSize - 1] = ???
  • Kevin Jump 1867 posts 11859 karma points MVP 4x c-trib
    Jan 21, 2014 @ 10:09
    Kevin Jump
    100

    The way i have done it in the past (works on v6 api - no changes as far as i can see for v7) is to get a List

    List<ContentTypeSort> allowedTypes = new List<ContentTypeSort>(item.AllowedContentTypes);
    

    assuming you have the docType you want to add - i add it to the list and assign the list back to the original ContentType

    allowedTypes.Add(
            new ContentTypeSort(new Lazy<int>(() => allowedDoc.Id),
                                  sortOrder, allowedDoc.Name));
    
    item.AllowedContentTypes = allowedTypes;
    

    then you should beable to save the doctype back with the new types

  • Tom 713 posts 952 karma points
    Jan 21, 2014 @ 23:33
    Tom
    0

    Thanks Kevin,

    the list makes it much cleaner than the array!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies