From 9621403f79bdfcf167da60d43e0edaf540c50163 Mon Sep 17 00:00:00 2001 From: Morten Christensen Date: Tue, 16 Apr 2013 17:19:46 -0200 Subject: [PATCH] Fixes U4-2053 --- src/Umbraco.Core/Models/ContentType.cs | 13 +++++++++++-- .../Models/ContentTypeCompositionBase.cs | 4 +++- src/Umbraco.Core/Models/MediaType.cs | 11 ++++++++++- .../umbraco/create/nodetypeTasks.cs | 17 ++++++++++------- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/Umbraco.Core/Models/ContentType.cs b/src/Umbraco.Core/Models/ContentType.cs index 581c11ce41..d675b966ba 100644 --- a/src/Umbraco.Core/Models/ContentType.cs +++ b/src/Umbraco.Core/Models/ContentType.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Runtime.Serialization; -using Umbraco.Core.Persistence.Mappers; namespace Umbraco.Core.Models { @@ -16,12 +15,22 @@ namespace Umbraco.Core.Models { private int _defaultTemplate; private IEnumerable _allowedTemplates; - + + /// + /// Constuctor for creating a ContentType with the parent's id. + /// + /// You usually only want to use this for creating ContentTypes at the root. + /// public ContentType(int parentId) : base(parentId) { _allowedTemplates = new List(); } + /// + /// Constuctor for creating a ContentType with the parent as an inherited type. + /// + /// Use this to ensure inheritance from parent. + /// public ContentType(IContentType parent) : base(parent) { _allowedTemplates = new List(); diff --git a/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs b/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs index 02a5e7d8f7..3f912f4972 100644 --- a/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs +++ b/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs @@ -20,8 +20,10 @@ namespace Umbraco.Core.Models { } - protected ContentTypeCompositionBase(IContentTypeBase parent) : base(parent) + protected ContentTypeCompositionBase(IContentTypeComposition parent) + : base(parent) { + AddContentType(parent); } private static readonly PropertyInfo ContentTypeCompositionSelector = diff --git a/src/Umbraco.Core/Models/MediaType.cs b/src/Umbraco.Core/Models/MediaType.cs index 0fb4bd171b..d8e3c58538 100644 --- a/src/Umbraco.Core/Models/MediaType.cs +++ b/src/Umbraco.Core/Models/MediaType.cs @@ -1,6 +1,5 @@ using System; using System.Runtime.Serialization; -using Umbraco.Core.Persistence.Mappers; namespace Umbraco.Core.Models { @@ -11,10 +10,20 @@ namespace Umbraco.Core.Models [DataContract(IsReference = true)] public class MediaType : ContentTypeCompositionBase, IMediaType { + /// + /// Constuctor for creating a MediaType with the parent's id. + /// + /// You usually only want to use this for creating MediaTypes at the root. + /// public MediaType(int parentId) : base(parentId) { } + /// + /// Constuctor for creating a MediaType with the parent as an inherited type. + /// + /// Use this to ensure inheritance from parent. + /// public MediaType(IMediaType parent) : base(parent) { } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/nodetypeTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/nodetypeTasks.cs index f540234ef6..75917f4eee 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/nodetypeTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/nodetypeTasks.cs @@ -47,13 +47,16 @@ namespace umbraco { //NOTE: TypeID is the parent id! //NOTE: ParentID is aparently a flag to determine if we are to create a template! Hack much ?! :P - var contentType = new ContentType(TypeID != 0 ? TypeID : -1) - { - CreatorId = _userID, - Alias = Alias.Replace("'", "''"), - Icon = UmbracoSettings.IconPickerBehaviour == IconPickerBehaviour.HideFileDuplicates ? ".sprTreeFolder" : "folder.gif", - Name = Alias.Replace("'", "''") - }; + var parentId = TypeID != 0 ? TypeID : -1; + var contentType = parentId == -1 + ? new ContentType(-1) + : new ContentType(ApplicationContext.Current.Services.ContentTypeService.GetContentType(parentId)); + contentType.CreatorId = _userID; + contentType.Alias = Alias.Replace("'", "''"); + contentType.Name = Alias.Replace("'", "''"); + contentType.Icon = UmbracoSettings.IconPickerBehaviour == IconPickerBehaviour.HideFileDuplicates + ? ".sprTreeFolder" + : "folder.gif"; // Create template? if (ParentID == 1)