Created
June 7, 2013 17:33
-
-
Save mattbrailsford/5730950 to your computer and use it in GitHub Desktop.
An IPropertyEditorValueConverter for the uComponents MultiUrlPicker for Umbraco
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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