Allowed Child Types

sensenet content repository stores different content types. One of the major differences between a file system and the content repository is that in a file system you can store any type (file or folder) anywhere, whereas in the sensenet content repository it is possible to define restrictions on what content types the different containers can contain. This allows you to create a much more precisely defined structure and provide the users a better user experience when creating new content under different places in the repository.

Basically you can configure allowed child types in the content type definition of the different types (for example a TaskList can only contain Tasks, a DocumentLibrary can only contain Folders and Files, etc.). These settings can be overridden on the specific content, for example you can modify any of your document libraries to be able to contain images, too.

Get child types allowed effectively on a content

Following example results in the list of content types that are allowed effectively on the given content (e.g. a merged list with content types allowed in the content type definition or directly on the content):

Copy
url: https://dev.demo.sensenet.com/OData.svc/Root/Content('IT')/EffectiveAllowedChildTypes

Get child types allowed on a content

This next example returns the list of content types allowed directly on the given content:

Copy
url: https://dev.demo.sensenet.com/OData.svc/Root/Content('IT')/AllowedChildTypes

Get allowed child types set in the content type definition

The next example returns the list of content types set as allowed in the given content's CTD:

Copy
url: https://dev.demo.sensenet.com/OData.svc/Root/Content('IT')/GetAllowedChildTypesFromCTD

Update list of allowed child types on a content

You are able to update the allowed type list at once with updating the value of the AllowedChildTypes field of the content. It works the same way as updating other field values as you can see in the next example, you can update the list by providing the list of type names as the value of the mentioned field:

Copy
url: "/OData.svc/Root/Content('IT')",
type: 'PATCH',
data: "models=[" + JSON.stringify({
  'AllowedChildTypes': ['ImageLibrary','DocumentLibrary','TaskList']
}) + "]",

Add a type to the allowed childtypes

The following example shows you how to add types to the given content's allowed content type list:

Copy
url: "/OData.svc/Root/Content('IT')/AddAllowedChildTypes",
type: 'POST',
data: "models=[" + JSON.stringify({
    "contentTypes": ["Task", "Image"]
  }) + "]",

Remove a type from the allowed childtypes

The next example shows you how to remove a type from the given content's allowed content type list:

Copy
url: "/OData.svc/Root/Content('IT')/RemoveAllowedChildTypes",
type: 'POST',
data: "models=[" + JSON.stringify({
    "contentTypes": ["Task", "Image"]
  }) + "]",
 

Check allowed childtypes

With the next example you are able to get all contents/paths where AllowedChildTypes list is empty. Paths are categorized by content type names. This is a helper function that can be used to get an overview of your system.

Copy
url: https://dev.demo.sensenet.com/OData.svc/Root/Content('IT')/CheckAllowedChildTypesOfFolders