orchard cms: how to add media picker field to anew module

这一生的挚爱 提交于 2019-12-12 12:23:59

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/10369967/orchard-cms-how-to-add-media-picker-field-to-anew-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!