Copied to clipboard

Flag this post as spam?

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


  • Barry Fogarty 493 posts 1129 karma points
    Sep 09, 2013 @ 16:05
    Barry Fogarty
    0

    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:

    var media = Model.Content.GetPropertyValue<IPublishedContent>("prop");
    

    Even if this was a fallback in the DAMP value converter, this would be good.

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Sep 10, 2013 @ 09:38
    Jeroen Breuer
    0

    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:

    var media =Model.Content.GetPropertyValue<DAMP.PropertyEditorValueConverter.Model>("prop").First;

    Then you can do media.Url and things like that.

    Jeroen

  • Barry Fogarty 493 posts 1129 karma points
    Sep 10, 2013 @ 12:49
    Barry Fogarty
    100

    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;
                }
            }
        }
    
Please Sign in or register to post replies

Write your reply to:

Draft