How can I create a non-persisted content item based on the name of a content type definition?

Topics: Customizing Orchard
Jan 20, 2015 at 5:26 PM
Hi

Hopefully you can help me with a problem I'm finding hard to figure out the answer to!

I have a custom module which has various orchard content types and so on. It's all working fine and now I'd like to add a piece of functionality where the users can set up content type definitions and then map them to sets of data that are pulled from outside Orchard (and that I don't want or need to be persisted in Orchard). The reason for creating content items and content parts is so that the user can use the existing, user-friendly way of creating definitions and mapping them to content parts that we also supply in our module.

So! The problem is that I need to create a non-persisting content item which welds the correct content parts as set out in the definition, and therefore hits the correct drivers and handlers for those parts.

(Sorry that this must be quite confusing for people! )

We definitely don't want to create an actual content item that is saved in the database, we simply want to create on on the fly so that the built in display methods load up the various parts defined on the content type definition.

I found this blog post about faking content items for testing purposes - http://weblogs.asp.net/bleroy/faking-orchard-content-items-for-testing, but one issue is that I'm not sure how to retrieve a class of the correct ContentPart type based on the information supplied by the ContentTypeDefinition.

If you could help point me in the right direction to either retrieve or create new instances of ContentParts (based on info from the definition) I think this would help me get further.

Many thanks
Jan 20, 2015 at 5:33 PM
It's also possible that I'm barking up the wrong tree with this attempt to fake a content item.

In my controller code I am able to retrieve the data from the third party service, and also retrieve the name and object of the ContentTypeDefinition that needs to be used to render the data. Perhaps I should be investigating shapes more, but from what I can see the BuildDisplay method expects a ContentItem with all the information on it in order to fire the necessary drivers and handlers of the child ContentParts defined in the definition :/
Jan 21, 2015 at 3:20 PM
doh, after all that I was able to do it with a simple call to OrchardServices.ContentManager.New(contentDefinitionName)