4
votes

I am building a module for orchard cms. I would like to use the mediapiker module in my module.

Through the orchard backend interface, its possible to add a moudle to a content item. What is not clear, is how to use one module in another.

how do I add the mediapiker field to my razor view in visual studio?

2

2 Answers

5
votes

You should take a look at MediaPickerFieldDriver.cs and MediaPicker.Edit.cshtml. They are both in Orchard.Fields. That should give you everything you need. Then again it's not entirely clear what you are trying to do. If you are just trying to add a media picker field to your content type from code, then you should do it from the migration, like this:

ContentDefinitionManager.AlterPartDefinition("Product",
    builder => builder.WithField("ProductImage",
        fieldBuilder => fieldBuilder
            .OfType("MediaPickerField")
            .WithDisplayName("Product Image")));

Update: As @ed13 points out in his answer, for more recent versions of Orchard 1.x (1.10+), the field type is MediaLibraryPickerField instead of MediaPickerField.

1
votes

If it helps anyone using a later version of Orchard (v1.10.+), the code required to add a media picker field is below:

ContentDefinitionManager.AlterPartDefinition("YourContentPart", builder =>
                builder.WithField("BackgroundImage",
                    fieldBuilder => fieldBuilder
                        .OfType("MediaLibraryPickerField")
                        .WithDisplayName("Background Image")));

Hope that helps someone.