Copied to clipboard

Flag this post as spam?

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


  • Chris 12 posts 84 karma points
    Sep 14, 2018 @ 15:48
    Chris
    0

    creating Value parsers

    I have tried to follow the manual to create a value parser. Nothing now happens (still get umb://document/...) and I have no idea where to start diagnosing the problem. I am new to creating dlls and fairly new to Umbraco. The steps I have taken are:

    1. Opened a new project and copied the code from the manual, changing the guid and code as required.
    2. Created a reference to MemberExport.Library which copied over several dlls.
    3. Built the solution and then copied the created dll to the bin folder of my umbraco solution. My dll is called MemberExport.Library.ValueParsers

    Here is my class:

    namespace MemberExport.Library.ValueParsers
    {
        public class ChapterContentPicker2Parser : IValueParser
        {
            /// <summary>
            /// Returns the Datatype GUID of the Chapter Content Picker Render Control.
            /// </summary>
            public string DataTypeId
            {
                get { return "fb1dc6c7-1e0e-4fc3-bad6-6bdbf8a52db2"; }
            }
            /// <summary>
            /// Converts the Chapter Id to Chapter Name
            /// </summary>
            /// <param name="memberfieldInfo">The memberfield info.</param>
            /// <param name="value">The value.</param>
            /// <returns>The yes/no string</returns>
            public object Parse(Types.MemberField memberfieldInfo, object value)
            {
                //return memberfieldInfo.Text;//string.Format("{0}", value) == "1" ? "yes" : "no";
                return "TEST";
            }
        }
    }
    

    Any help as to what I am doing wrong would be much appreciated.

  • Richard Soeteman 4035 posts 12842 karma points MVP
    Sep 17, 2018 @ 06:26
    Richard Soeteman
    0

    Hi Chris,

    Your DattypeId propably doesn't match the propertyeditor alias of the datatype. If you matsch that one it should hit the class.

    Best,

    Richard

  • Chris 12 posts 84 karma points
    Sep 17, 2018 @ 13:27
    Chris
    0

    I am pretty sure I got the correct GUID. It does not show in the current umbraco. When editing the datatype, There is an ID at the end of the url ([mysite]/umbraco#/developer/dataTypes/edit/5213) I then used the code below to get the GUID key:

    var dataService = ApplicationContext.Current.Services.DataTypeService;
    var chapterPicker = dataService.GetDataTypeDefinitionById(5213);
    var chapterPickerGuid = chapterPicker.Key.ToString();
    

    Can you tell me how MemberExport knows which classes to look for as custom valueParsers?

  • Richard Soeteman 4035 posts 12842 karma points MVP
    Sep 17, 2018 @ 13:30
    Richard Soeteman
    0

    You need the property editor alias you can see it in the developer section of Umbraco Umbraco.TrueFalse etc

  • Chris 12 posts 84 karma points
    Sep 17, 2018 @ 15:48
    Chris
    0

    I'm getting no joy here, I take it you meant the dataTypeId should now return the dataType alias. I have implemented that and included the TrueFalse one you used as an example but still nothing changes with the export.

    Using Umbraco ver: 7.7.7 and Member Export Pro V2.8.2.

    My code now:

    namespace MemberExport.Library.ValueParsers
    {
        public class ContentPicker2Parser : IValueParser
        {
            /// <summary>
            /// Returns the Datatype alias of the ContentPicker2 Render Control.
            /// </summary>
            public string DataTypeId
            {
                get { return "Umbraco.ContentPicker2"; } // fb1dc6c7-1e0e-4fc3-bad6-6bdbf8a52db2"; }
            }
            /// <summary>
            /// Converts the Chapter Id to Chapter Name
            /// </summary>
            /// <param name="memberfieldInfo">The memberfield info.</param>
            /// <param name="value">The value.</param>
            /// <returns>The chapter name string</returns>
            public object Parse(Types.MemberField memberfieldInfo, object value)
            {
                //return memberfieldInfo.Text;//string.Format("{0}", value) == "1" ? "yes" : "no";
                return "TEST";
            }
        }
    
        public class TrueFalseParser : IValueParser
        {
            /// <summary>
            /// Returns the Datatype alias of the true/false Render Control.
            /// </summary>
            public string DataTypeId
            {
            get { return "Umbraco.TrueFalse"; }
            }
            /// <summary>
            /// Converts the 0/1 to a normal yes/no string.
            /// </summary>
            /// <param name="memberfieldInfo">The memberfield info.</param>
            /// <param name="value">The value.</param>
            /// <returns>The yes/no string</returns>
            public object Parse(Library.Types.MemberField memberfieldInfo, object value)
            {
            return string.Format("{0}", value) == "1" ? "yes" : "no";
            }
        }
    }
    
  • Richard Soeteman 4035 posts 12842 karma points MVP
    Sep 18, 2018 @ 06:44
    Richard Soeteman
    0

    Hi Chris,

    Weird, that should work and your dll is in the /bin folder I assume?

    Best,

    Richard

  • Chris 12 posts 84 karma points
    Sep 18, 2018 @ 07:55
    Chris
    0

    Hi Richard,

    Yes, I created it in a separate project then copied the dll to the bin folder of my umbraco project. Is there any way to check if it has been picked up by Member Export?

    Thanks for your help,

    Chris

  • Richard Soeteman 4035 posts 12842 karma points MVP
    Sep 18, 2018 @ 11:48
    Richard Soeteman
    0

    Hi Chris,

    Sorry this has been updated. I am about to write a new manual for v3. Looks like old syntax was still in the docs (and in my head as well).

     [ValueParser(PropertyEditorAlias = "Umbraco.RadioButtonList")]
        public  class RadioBoxValueParser :IValueParser
    {
        public virtual object Parse(object value)
        {
            return null;
        }
        public virtual object Parse(MemberField memberField, object value, FieldParserOptions fieldParserOptions)
        {
            if (value != null)
            {
                var prevalue = memberField.GetPrevalues().FindLast(p => p.Id.ToString() == value.ToString());
                if (prevalue != null)
                {
                    value = prevalue.Value;
                }
            }
    
            return value;
        }
    }
    

    This is how it works these days. Derive from IValueParser and decorate with one or more ValueParser attributes. Where propertyeditor alias is the alias of your property editor.

    Hope this works now.

    Best, Richard

  • Chris 12 posts 84 karma points
    Sep 19, 2018 @ 08:36
    Chris
    0

    Hi Richard,

    I am unable to find the type for ValueParser or PropertyEditorAlias for the decoration and FieldParserOptions in the Parse method.

    My class also no longer implements IValueParser as the property DataTypeId is required.

    Does this have to do with the version I'm using being 2.8.2 rather than 3? 2.8.2 is the version currently showing in NuGet.

    Regards,

    Chris

Please Sign in or register to post replies

Write your reply to:

Draft