This project is read-only.

How to attach a part to my type using a "part picker" UI?

Topics: Customizing Orchard, General, Writing modules
Feb 9, 2012 at 8:59 PM

I have a "TopicProfile" part that I want to be able to associate with other parts. There are about 6 parts that I want to attach to TopicProfile. The relationship is 1-1, so I could actually do it quickly by just attaching the parts. But each part i'm attaching has so much data to set up that it would be very hard for editors to use this. They would end up with a page with over a dozen WYSIWYG editors, several route parts, etc. 

It would be easier to keep the creation of the parts separate, and to be able to just attach them to TopicProfile at the end. So the Dashboard editor for TopicProfile would be droplists, or some sort of UI where you can browse all instances of PartA and select one, then another field to browse through instances of PartB and select one of those etc. So kind of similar to MediaPicker, but for parts. 

Are there any examples of this? If not, can anyone please point me in the right direction? 

Feb 9, 2012 at 9:31 PM

You can weld parts on the fly. Althoug it does look like your content part really should be a content type, as those have natural 1-1 associations with parts.

Feb 9, 2012 at 9:34 PM

I'm going to try the same thing as what's done in the 1-n relationships documentation. No reason that wouldn't work for content parts as well right? The only extra thing I might have to do is a popup window to present a better UI to pick the parts from.  

Feb 9, 2012 at 9:37 PM

I agree, a Type models the relationships I want to represent very well, but I mentioned reasons in the OP why I don't want to do it that way. 

What are some examples of welding parts on the fly that I can look at? 

Feb 9, 2012 at 10:01 PM

Well, it does sound like you want to remodel the data based on UI considerations. That smells ;)

You can find examples of welding parts in very old modules, before we had metadata representing the types, we had to do it that way. It usually happened in handlers.

Feb 10, 2012 at 6:40 AM
Edited Feb 10, 2012 at 6:40 AM

The problem is a type can't have multiple RouteParts. What you seem to be describing is welding multiple content types which is impossible. Types are collections of Parts (but only 1 of each part ... if you need multiple instances of some UI on a single type, you have to use fields).

My Mechanics module handles relationships between content types ... you can create 1-1, 1-n, n-n relationships, even "required" relationships. Are you using 1.x? My current source code is nearly production ready but it needs 1.x :)