I know I could create my own custom Property Editor value converter for DAMP, but just wondering if there is an easier way to signal that my DAMP picker should use the value converter for a standard media picker?
I have upgraded some media pickers to DAMP and as they are single item pickers, I would like the following call to return a typed media object, as they do when they are a media picker:
var media = Model.Content.GetPropertyValue<IPublishedContent>("prop");
Even if this was a fallback in the DAMP value converter, this would be good.
I don't really understand what you did. If you want to use the value converter just use the DAMP Property Editor Value Converter. What do you mean with fallback and default media pickers? If you want a single item with DAMP you can do:
var media =Model.Content.GetPropertyValue<DAMP.PropertyEditorValueConverter.Model>("prop").First;
Hi Jeroen - the DAMP property editors will only be single pickers so I just implemented a Value Converter in the same way as a standard media picker in the end. This standardises the project code a little bit better. Cheers for the alternative solution anyway!
public class GenericDampPickerPropertyEditorValueConverter : IPropertyEditorValueConverter
{
string _propertyTypeAlias = string.Empty;
string _docTypeAlias = string.Empty;
public bool IsConverterFor(Guid propertyEditorId, string docTypeAlias, string propertyTypeAlias)
{
_propertyTypeAlias = propertyTypeAlias;
_docTypeAlias = docTypeAlias;
return Guid.Parse("ef94c406-9e83-4058-a780-0375624ba7ca").Equals(propertyEditorId);
}
public Attempt<object> ConvertPropertyValue(object value)
{
int nodeId; //check value is node id and not stored as node names
if (UmbracoContext.Current != null && int.TryParse(value.ToString(), out nodeId))
{
var umbHelper = new UmbracoHelper(UmbracoContext.Current);
IPublishedContent mediaPickerContent = null;
if (uQuery.GetUmbracoObjectType(nodeId) == uQuery.UmbracoObjectType.Media)
{
mediaPickerContent = umbHelper.TypedMedia(value.ToString());
}
else
{
return Attempt<object>.False;
}
return new Attempt<object>(true, mediaPickerContent);
}
else
{
return Attempt<object>.False;
}
}
}
Fallback to Media Picker value converter
I know I could create my own custom Property Editor value converter for DAMP, but just wondering if there is an easier way to signal that my DAMP picker should use the value converter for a standard media picker?
I have upgraded some media pickers to DAMP and as they are single item pickers, I would like the following call to return a typed media object, as they do when they are a media picker:
Even if this was a fallback in the DAMP value converter, this would be good.
Hello,
I don't really understand what you did. If you want to use the value converter just use the DAMP Property Editor Value Converter. What do you mean with fallback and default media pickers? If you want a single item with DAMP you can do:
Then you can do media.Url and things like that.
Jeroen
Hi Jeroen - the DAMP property editors will only be single pickers so I just implemented a Value Converter in the same way as a standard media picker in the end. This standardises the project code a little bit better. Cheers for the alternative solution anyway!
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.