This project is read-only.

Adding Installed Fields to my Custom Widget

Topics: Customizing Orchard, Writing modules
Sep 8, 2011 at 1:47 AM
Edited Sep 8, 2011 at 1:48 AM

I have installed the Image field from the gallery and it's pretty sweet. Now I want to create a custom widget that uses this field. i.e. a user can select a zone on a layer and then just upload an image. I will then format how this HTML is then generated using a shape template.


I know when you create a nodule you can make it use specific parts, i.e. below.

ContentDefinitionManager.AlterTypeDefinition("TwitterWidget", cfg => cfg
                .WithSetting("Stereotype", "Widget"));



Is there anything that you can say, WithField() for example?

Is this possible? Do you think I am approaching this correctly?

Again thanks for all your help,


Sep 8, 2011 at 3:41 AM

Yes, you can attach a field in your migration, but you have to add it to a Part not a ContentType. The Content Types UI in the dashboard is a little misleading because it appears that you can add fields to types there. But Orchard is actually adding the field to a part with the same name as the type.

So in the example you showed, if you wanted to have an ImageField available on that widget, you would add it to the TwitterWidgetPart like this:

ContentDefinitionManager.AlterPartDefinition("TwitterWidgetPart", cfg => cfg
                .WithField("Picture", cfg => cfg.OfType("ImageField")));

Sep 8, 2011 at 3:52 AM

Hi Kevin, Great name by the way :)

That's great news, I will try and add it to my custom module part and see if I can get this working. I will post an update if I manage to do this.

Love all the help on here, keep it up.