Recursive related links and property value convertor
I have a custom property value converter which converts RelatedLinks properties into a custom object representing the links (UmbracoRelatedLink).
public class RelatedLinkConverter : PropertyValueConverterBase
{
public override bool IsConverter(PublishedPropertyType propertyType)
{
return propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.RelatedLinksAlias);
}
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
{
return JsonConvert.DeserializeObject<List<UmbracoRelatedLink>>(source.ToString());
}
}
This is working fine apart from sometimes when I use it recursively. For some reason, and I haven't yet worked out why, when a page is published on which the related links property has no links set then the value coming into the property value converter is [] (i.e. an empty json object).
The problem is that umbraco then decides that the value is set on that node, and doesn't bother to look up the ancestry tree to find a node where the list does have some values.
Can somebody explain how I can either make the publish save the empty list as a genuinely empty property, or somehow have my property value converter handle this scenario correctly? You cannot just check for "[]" and return null, as an ArgumentNullException is thrown when you use it.
I have a pretty rubbish work around where I manually check whether the returned list is empty and do the recursion by hand, but this isn't pretty and I rather have something clean which works properly.
Recursive related links and property value convertor
I have a custom property value converter which converts RelatedLinks properties into a custom object representing the links (UmbracoRelatedLink).
This is working fine apart from sometimes when I use it recursively. For some reason, and I haven't yet worked out why, when a page is published on which the related links property has no links set then the value coming into the property value converter is [] (i.e. an empty json object).
The problem is that umbraco then decides that the value is set on that node, and doesn't bother to look up the ancestry tree to find a node where the list does have some values.
Can somebody explain how I can either make the publish save the empty list as a genuinely empty property, or somehow have my property value converter handle this scenario correctly? You cannot just check for "[]" and return null, as an ArgumentNullException is thrown when you use it.
I have a pretty rubbish work around where I manually check whether the returned list is empty and do the recursion by hand, but this isn't pretty and I rather have something clean which works properly.
is working on a reply...