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
    Oct 31, 2014 @ 05:39
    Tom
    0

    Content Service - Add DocType as Child Doesn't Inherit Properties

    Hi we have a console app we've written which lets us migrate umbraco content as part of our migration strategy.

     

    If we try and add a DocType to be a child of another DocType it won't inherit any of its parent's properties.

     

    Code:

    public int AddDocType(int? parentDocTypeId, string name, string docTypeAlias, IEnumerable<PropertyTypeGrouping> propertyGroupings, IEnumerable<string> childDocTypeAliases, string thumbnail = UmbracoThumbnails.Doc, string icon = UmbracoIcons.Doc, string[] templateAliases = null)
            {
                var contentTypeService = ServiceContext.ContentTypeService;
                var docTypeToAdd = parentDocTypeId.HasValue ? new ContentType(parentDocTypeId.Value) : new ContentType(-1);
                docTypeToAdd.Name = name;
    
                docTypeToAdd.Alias = docTypeAlias;
                docTypeToAdd.Thumbnail = thumbnail;
                docTypeToAdd.Icon = icon;
                if (templateAliases != null && templateAliases.Any())
                {
                    var templates = GetTemplates(templateAliases);
                    docTypeToAdd.AllowedTemplates = templates;
                    docTypeToAdd.SetDefaultTemplate(templates[0]);
                }
                contentTypeService.Save(docTypeToAdd);
    
                if(propertyGroupings != null && propertyGroupings.Any())
                { 
                    AddTabsToDocType(docTypeToAdd, propertyGroupings.Select(p => p.Name));
                    AddPropertiesFromGroupings(docTypeToAdd, propertyGroupings);
                }
    
                if (childDocTypeAliases != null && childDocTypeAliases.Any())
                {
                    foreach (var childDocTypeAlias in childDocTypeAliases)
                    {
                        AllowNodeToCreateChildOfType(docTypeToAdd, childDocTypeAlias, false);
                    }
    
                    contentTypeService.Save(docTypeToAdd);
                }
                return docTypeToAdd.Id;
            }
  • Charles Afford 1163 posts 1709 karma points
    Nov 03, 2014 @ 21:03
    Charles Afford
    0

    Hi, What version of umbraco are you using? :)

  • Charles Afford 1163 posts 1709 karma points
    Nov 03, 2014 @ 21:03
    Charles Afford
    0

    Hi, What version of umbraco are you using? :) Are your doc types saving?

  • 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