Skip to content

Commit

Permalink
Create doctype collections under the chosen parent
Browse files Browse the repository at this point in the history
  • Loading branch information
kjac authored and nul800sebastiaan committed Oct 24, 2018
1 parent f699768 commit df1c4fa
Showing 1 changed file with 7 additions and 25 deletions.
32 changes: 7 additions & 25 deletions src/Umbraco.Web/Editors/ContentTypeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,6 @@ public HttpResponseMessage PostRenameContainer(int id, string name)

public DocumentTypeCollectionDisplay PostCreateCollection(int parentId, string collectionName, bool collectionCreateTemplate, string collectionItemName, bool collectionItemCreateTemplate, string collectionIcon, string collectionItemIcon)
{
var storeInContainer = false;
var allowUnderDocType = -1;
// check if it's a folder
if (Services.ContentTypeService.GetContentType(parentId) == null)
{
storeInContainer = true;
} else
{
// if it's not a container, we'll change the parentid to the root,
// and use the parent id as the doc type the collection should be allowed under
allowUnderDocType = parentId;
parentId = -1;
}

// create item doctype
var itemDocType = new ContentType(parentId);
itemDocType.Name = collectionItemName;
Expand Down Expand Up @@ -260,20 +246,16 @@ public DocumentTypeCollectionDisplay PostCreateCollection(int parentId, string c
// save collection doctype
Services.ContentTypeService.Save(collectionDocType);

// test if the parent id exist and then allow the collection underneath
if (storeInContainer == false && allowUnderDocType != -1)
// test if the parent exist and then allow the collection underneath
var parentCt = Services.ContentTypeService.GetContentType(parentId);
if (parentCt != null)
{
var parentCt = Services.ContentTypeService.GetContentType(allowUnderDocType);
if (parentCt != null)
{
var allowedCts = parentCt.AllowedContentTypes.ToList();
allowedCts.Add(new ContentTypeSort(collectionDocType.Id, allowedCts.Count()));
parentCt.AllowedContentTypes = allowedCts;
Services.ContentTypeService.Save(parentCt);
}
var allowedCts = parentCt.AllowedContentTypes.ToList();
allowedCts.Add(new ContentTypeSort(collectionDocType.Id, allowedCts.Count()));
parentCt.AllowedContentTypes = allowedCts;
Services.ContentTypeService.Save(parentCt);
}


return new DocumentTypeCollectionDisplay
{
CollectionId = collectionDocType.Id,
Expand Down

0 comments on commit df1c4fa

Please sign in to comment.