U4-1362 - Setting Allowed child nodetypes with old API doesn't work - UmbracoCms.6.0.0.build.93

Created by Jeroen Breuer 28 Dec 2012, 21:44:50 Updated by Sebastiaan Janssen 15 Jan 2013, 13:05:53

Duplicates: U4-1363

Relates to: U4-1399

When you install the [DAMP 2.0 Samples|http://our.umbraco.org/FileDownload?id=3145] package it will create Media Types and adds those as Allowed child nodetypes on the Folder Media Type with this code:

//Add new MediaTypes to the folder Allowed child nodetypes. MediaType folder = MediaType.GetByAlias(FOLDER_MEDIATYPE_NAME);

int[] folderStructure = folder.AllowedChildContentTypeIDs; int newsize = folderStructure.Count() + 2;

Array.Resize(ref folderStructure, newsize); folderStructure[newsize - 2] = imageWide.Id; folderStructure[newsize - 1] = imageLong.Id;

folder.AllowedChildContentTypeIDs = folderStructure;

This used to work in v4, but in v6 the new Media Types are still not allowed in the Folder Media Type.


Sebastiaan Janssen 29 Dec 2012, 09:18:09

FYI: In my tests, I saw that there ARE values inserted in the database, but they are incorrect. Wasn't sure if they were hardcoded in the starter kits, but it looks like this may be a larger issue then.

Morten Christensen 29 Dec 2012, 10:06:37

The saving looks like its wired up correctly in the DocumentType class, but as I recall there was room for improvement in the Save/Update part of the ContentTypeRepository, so I put this issue on my todo list.

Morten Christensen 29 Dec 2012, 12:07:37

This issue is basically the same as U4-1363 - should have seen it right away, but didn't :/ You need to finalize what you are doing by saving the MediaType: folder.Save(); then it'll work. Here is my test case:

[Test] public void Can_Verify_AllowedChildContentTypes_On_MediaType() { // Arrange var folder = MediaType.GetByAlias("Folder"); var folderStructure = folder.AllowedChildContentTypeIDs.ToList(); folderStructure.Add(1045);

// Act
folder.AllowedChildContentTypeIDs = folderStructure.ToArray();

// Assert
var updated = MediaType.GetByAlias("Folder");

Assert.That(updated.AllowedChildContentTypeIDs.Any(), Is.True);
Assert.That(updated.AllowedChildContentTypeIDs.Any(x => x == 1045), Is.True);


Sebastiaan Janssen 15 Jan 2013, 13:05:37

Closing this as it relates to the breaking change where you need to do a .Save() to finalize your changes.

Priority: Normal

Type: Bug

State: Duplicate

Assignee: Morten Christensen

Difficulty: Normal

Category: Architecture

Backwards Compatible: True

Fix Submitted:

Affected versions: 6.0.0

Due in version:


Story Points: