Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mattbrailsford/5730950 to your computer and use it in GitHub Desktop.
Save mattbrailsford/5730950 to your computer and use it in GitHub Desktop.
An IPropertyEditorValueConverter for the uComponents MultiUrlPicker for Umbraco
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;
using Umbraco.Core;
using Umbraco.Core.Dynamics;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Web;
using uComponents.DataTypes.MultiUrlPicker.Dto;
using umbraco;
namespace TheOutfield.Umbraco.PropertyEditors
{
public class MultiUrlPickerPropertyEditorValueConverter : IPropertyEditorValueConverter
{
private string _propertyTypeAlias;
private string _docTypeAlias;
public bool IsConverterFor(Guid propertyEditorId, string docTypeAlias, string propertyTypeAlias)
{
_propertyTypeAlias = propertyTypeAlias;
_docTypeAlias = docTypeAlias;
return Guid.Parse("29F9301C-31F8-437D-B6B5-897C1CAFE586").Equals(propertyEditorId);
}
public Attempt<object> ConvertPropertyValue(object value)
{
if (UmbracoContext.Current != null)
{
try
{
var result = MultiUrlPickerState.Deserialize((string)value);
return new Attempt<object>(true, result);
}
catch (System.Xml.XmlException e)
{
return Attempt<object>.False;
}
}
return Attempt<object>.False;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment