You would need a value converter that understands that format. You could use the JsonValueConverter if you setup your property editor to have a ValueType of Json.
If you want the image to return an IPublishedContent instead, you would need a model for storing, and another for display.
public class StoredValue
{
public string text{get;set;}
public string image{get;set;}
}
public class DisplayValue
{
public string Text{get;set;}
public IPublishedContent Image{get;set;}
}
Calling built in value converter from custom value converter
Hi
I'm building some custom property editors, that makes use some of the built in editors fx. the "Multi Url Picker" or "Media Picker".
Here i might end up with a value like:
Can i somehow use the built in value converters inside my own value converter, fx.
https://github.com/umbraco/Umbraco-CMS/blob/v8/contrib/src/Umbraco.Web/PropertyEditors/ValueConverters/MediaPickerWithCropsValueConverter.cs
to convert parts of my model, or do i need to basicly have duplicate code in my custom value converter?Hi,
Say you store
You would need a value converter that understands that format. You could use the JsonValueConverter if you setup your property editor to have a ValueType of Json.
If you want the image to return an IPublishedContent instead, you would need a model for storing, and another for display.
Looking at https://github.com/umbraco/Umbraco-CMS/blob/v8/contrib/src/Umbraco.Web/PropertyEditors/ValueConverters/ContentPickerValueConverter.cs as a base, you would need to override
GetPropertyValueType
andConvertSourceToIntermediate
The above code is just a mockup - not tested... :)
HTH :)
Hi Søren
Thanks for your reply, though not really what i'm looking for. Maybe i wasn't clear in my question.
For example they new Media picker (v3) has a more complex value than just a UDI. It contains crops, focal points etc.
So instead of me replicating the logic from the core Media Picker Value Converter. https://github.com/umbraco/Umbraco-CMS/blob/v8/contrib/src/Umbraco.Web/PropertyEditors/ValueConverters/MediaPickerWithCropsValueConverter.cs
I'm trying to figure out if you can just call/use that instead inside my own value converter for parts of my model.
I guess you could create an instance of the converter and call it?
is working on a reply...