codingintherain
codingintherain

Reputation: 263

Populate ContentPart in ContentHandler from custom data source

We have an existing application that is using RavenDB and are hoping to create a custom Orchard Admin module that can read and write data into Raven so we can manage the data. The implementation would ideally allow us to make use of ContentParts so we can create reusuable "modules".

There are several references to accessing data from a Web Service by loading the data in a ContentHandler, but I have not been able to come up with an implementation. I have been able to read/write data using a Controller/View, but that seems more restrictive.

Use RavenDB as the database for an Orchard CMS module

How to change Orchard record repository

Additionally, one of the properties that we need to manage is an image. We would like to make use of the Media Picker Field for selecting images in our admin interface. It would be okay for the physical image to be stored by Orchard as long as we can get to the image via a browser.

Can anyone point me in the correct direction?

Thanks!

Upvotes: 1

Views: 775

Answers (2)

Bertrand Le Roy
Bertrand Le Roy

Reputation: 17814

if you want to be able to enrich the external data with Orchard parts (comments, ratings, etc.) you should build a part, like Piotr explains. That would mean somehow creating content items for all remote objects, which will come with its own challenges (this means synchronizing distinct data source, something that's never fun).

If you don't need to do that, then you should build controller actions (and maybe widgets) to surface that data. Even if you do that, you can still benefit from many Orchard things such as theming.

Upvotes: 0

Piotr Szmyd
Piotr Szmyd

Reputation: 13366

If you're using Orchard content items, the Id is already there - no need to store a new one. You need to use some identifier to bind Orchard and backend store, otherwise you'd have to reimplement the whole Orchard data layer (it's an overkill).

You just need to:

  • create a part deriving from ContentPart (not ContentPart<T>, because you don't want it to be stored in Orchard database). Then,
  • add a handler for your part, hook up to appropriate lifetime events (like OnLoading) and load your data from backend for a given content item id and part type combination.
  • add a driver for your part (as usual) and put your data-storing logic in Editor method.

This way you will have a part without any data stored inside Orchard database, loaded completely from external source.

Upvotes: 1

Related Questions