Create doctype collections under the chosen parent

This commit is contained in:
Kenn Jacobsen
2018-10-24 08:26:13 +02:00
committed by Sebastiaan Janssen
parent f69976852e
commit df1c4faeb9

View File

@@ -209,20 +209,6 @@ namespace Umbraco.Web.Editors
public DocumentTypeCollectionDisplay PostCreateCollection(int parentId, string collectionName, bool collectionCreateTemplate, string collectionItemName, bool collectionItemCreateTemplate, string collectionIcon, string collectionItemIcon) 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 // create item doctype
var itemDocType = new ContentType(parentId); var itemDocType = new ContentType(parentId);
itemDocType.Name = collectionItemName; itemDocType.Name = collectionItemName;
@@ -260,20 +246,16 @@ namespace Umbraco.Web.Editors
// save collection doctype // save collection doctype
Services.ContentTypeService.Save(collectionDocType); Services.ContentTypeService.Save(collectionDocType);
// test if the parent id exist and then allow the collection underneath // test if the parent exist and then allow the collection underneath
if (storeInContainer == false && allowUnderDocType != -1) var parentCt = Services.ContentTypeService.GetContentType(parentId);
if (parentCt != null)
{ {
var parentCt = Services.ContentTypeService.GetContentType(allowUnderDocType); var allowedCts = parentCt.AllowedContentTypes.ToList();
if (parentCt != null) allowedCts.Add(new ContentTypeSort(collectionDocType.Id, allowedCts.Count()));
{ parentCt.AllowedContentTypes = allowedCts;
var allowedCts = parentCt.AllowedContentTypes.ToList(); Services.ContentTypeService.Save(parentCt);
allowedCts.Add(new ContentTypeSort(collectionDocType.Id, allowedCts.Count()));
parentCt.AllowedContentTypes = allowedCts;
Services.ContentTypeService.Save(parentCt);
}
} }
return new DocumentTypeCollectionDisplay return new DocumentTypeCollectionDisplay
{ {
CollectionId = collectionDocType.Id, CollectionId = collectionDocType.Id,