Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jeroen Wijdeven 31 posts 72 karma points MVP
    May 09, 2016 @ 12:46
    Jeroen Wijdeven
    0

    ModelsBuilder PropertyValueConverter

    Hi,

    I'am playing around with the modelsbuilder and have a question regarding the generation of the models. Is it possible to define which object is returned by a property. For some properties I like to have a different type of object or a more specific type. for example:

    For example: A relatedlinks type now returns a JArray, but I have my own propertyvalue converter. The contentpicker returns an object but I like to have a different more specific type.

    What I did with my own models builder was give the programmer full control over which types are generated by using a dictionary (in a T4 template, but I could be an xml file, or an implemementation of a specific interface as well). Maybe this is an Idea for the modelsbuilder (if there is not jet another solution);

    var types = new Dictionary<string, string> {
    {Constants.PropertyEditors.RelatedLinksAlias, "IEnumerable<LinkModel>"},
    {Constants.PropertyEditors.ContentPickerAlias, "IModel"},
    {Constants.PropertyEditors.MultiNodeTreePickerAlias, "IEnumerable<IModel>"}, 
    {"Umbraco.Grid", "GridModel"},
    {Constants.PropertyEditors.MacroContainerAlias, "IEnumerable<DynamicMacroModel>"},
    {Constants.PropertyEditors.MediaPickerAlias, "ICropImageModel"},
    {Constants.PropertyEditors.ImageCropperAlias, "ICropImageModel"},
    {Constants.PropertyEditors.TrueFalseAlias, "bool"}};
    
  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    May 27, 2016 @ 09:50
    Dave Woestenborghs
    0

    Hi Jeroen,

    You can install this one : https://github.com/Jeavon/Umbraco-Core-Property-Value-Converters/tree/v2/Our.Umbraco.PropertyConverters

    This has a property value convertor for the related links datatype. Should use this convertor after installing the package and rebuilding your models.

    Dave

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    May 27, 2016 @ 09:54
    Jeroen Breuer
    0

    If you don't like those Converters you can also write your own. I've done this for the Hybrid Framework: https://github.com/jbreuer/Hybrid-Framework-for-Umbraco-v7-Best-Practises/tree/master/Umbraco.Extensions/PropertyConverters

  • Jeroen Wijdeven 31 posts 72 karma points MVP
    May 27, 2016 @ 11:45
    Jeroen Wijdeven
    0

    Are you guys saying that the modelsbuilder does look into the propertyvalueconverters about which object is returned and that one is used to build the model? Because that's not the case at my side.. Maybe I do something wrong here than (forgot a setting?)

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    May 27, 2016 @ 11:47
    Dave Woestenborghs
    0

    Yes that should be the case.

    Dave

  • Jeroen Wijdeven 31 posts 72 karma points MVP
    May 28, 2016 @ 07:37
    Jeroen Wijdeven
    0

    Thanks guys, you hit me in the right direction. I wasn't aware of the IPropertyValueConverterMeta http://issues.umbraco.org/issue/U4-4716 which is needed by the modelsbuilder to define the return type.

    Happy to see a solution was already available and that I just forgot something.

Please Sign in or register to post replies

Write your reply to:

Draft