Creating ContentItem Definition from code / without admin panel

Dec 22, 2010 at 8:40 AM

I would like to define a contentitem from code, not using a class for it so it will be completely independent, dynamicly created as if it was defined in the admin ui.

Looking at the ContentType project i think i should call IContentDefinitionService.AddPart(myDefinition).
It will require that my module creating the definition will have a dependency on ContentTypes that way.

Unless someone has any tips or comments, i think i'll do the above.

Coordinator
Dec 22, 2010 at 8:43 AM

You have an example of that in SetupService.cs.

Dec 22, 2010 at 8:52 AM

BlogPost, Page and BodyPart ?

It isn't using the wrapper "IContentDefinitionService", but instead it uses the IContentDefinitionManager.
I don't see a StoreTypeDefinition method being called in SetupService.cs

Coordinator
Dec 22, 2010 at 9:00 AM

I don't understand what you're saying. You asked for creation of a content item from code. The setup service is doing that, for example when it creates the home page. I don't understand what this would have to do with IContentDefinitionService, IContentDefinitionManager or StoreTypeDefinition.

Dec 22, 2010 at 9:24 AM
Edited Dec 22, 2010 at 9:28 AM

The SetupService class seems to call all the migrations and after that it createsTenantData which does:

- create superuser
- sitename / settings
- theme
- hackInstallatiionGenerator :)

- AlterTypeDefinition BlogPost with several parts..
- AlterTypeDefinition Page with several parts.
- AlterPartDefinition BodyPart

Then if Widgets are enabled it creates layers and a homepageLayer.

I don't see a ContentItem being created, or is that publishing layers by calling contentManager.Publish?

In the Relation example: http://orchardproject.net/docs/GetFile.aspx?File=Orchard.Module.RelationSample.0.5.0.nupkg&AsStreamAttachment=1&Provider=ScrewTurn.Wiki.FilesStorageProvider&IsPageAttachment=1&Page=Creating-1-n-and-n-n-relations&NoHit=1 it says to create a Customer ContentItem definition by using the admin UI. How would i create a Customer definition by code?

Dec 22, 2010 at 9:28 AM
bertrandleroy wrote:

I don't understand what you're saying. You asked for creation of a content item from code. The setup service is doing that, for example when it creates the home page. I don't understand what this would have to do with IContentDefinitionService, IContentDefinitionManager or StoreTypeDefinition.

PS: not a contentitem from code but a contentitem-definition from code.

Coordinator
Dec 22, 2010 at 8:17 PM

Ah, ok, what you call a content definition we call a content type.

A content type can be created using ContentDefinitionManager.AlterTypeDefinition, for example from a migration. Orchard.Blogs.Migrations has several examples.