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:
Opened a new project and copied the code from the manual, changing the guid and code as required.
Created a reference to MemberExport.Library which copied over several dlls.
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.
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?
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";
}
}
}
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?
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.
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:
Here is my class:
Any help as to what I am doing wrong would be much appreciated.
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
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:
Can you tell me how MemberExport knows which classes to look for as custom valueParsers?
You need the property editor alias you can see it in the developer section of Umbraco Umbraco.TrueFalse etc
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:
Hi Chris,
Weird, that should work and your dll is in the /bin folder I assume?
Best,
Richard
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
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).
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
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
is working on a reply...