Last active
January 1, 2016 05:39
-
-
Save dampee/8099570 to your computer and use it in GitHub Desktop.
Umbraco MultiNodeTreePicker PropertyEditorValueConverter
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.Text; | |
using System.Web; | |
using Umbraco.Core; | |
using Umbraco.Core.PropertyEditors; | |
using Umbraco.Core.Models; | |
using umbraco.editorControls; | |
using Umbraco.Web; | |
using umbraco; | |
namespace Our.Umbraco.PropertyEditorConverters | |
{ | |
// original from : https://bitbucket.org/jeavon/umbraco-core-property-editor-converters/src/b1eb094077362bbbb5d86ff209c024d595b44457/Our.Umbraco.PropertyEditors/MultiNodeTreePickerPropertyEditorValueConverter.cs?at=default | |
public class MultiNodeTreePickerPropertyEditorValueConverter : IPropertyEditorValueConverter | |
{ | |
public bool IsConverterFor(Guid propertyEditorId, string docTypeAlias, string propertyTypeAlias) | |
{ | |
return Guid.Parse("7e062c13-7c41-4ad9-b389-41d88aeef87c").Equals(propertyEditorId); | |
} | |
public Attempt<object> ConvertPropertyValue(object value) | |
{ | |
if (UmbracoContext.Current != null) | |
{ | |
var nodeIds = XmlHelper.CouldItBeXml(value.ToString()) ? | |
uQuery.GetXmlIds(value.ToString()) : | |
value.ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray(); | |
if (nodeIds == null || nodeIds.Length == 0) | |
{ | |
return new Attempt<object>(false, null); | |
} | |
var umbHelper = new UmbracoHelper(UmbracoContext.Current); | |
var multiNodeTreePickerContent = umbHelper.TypedContent(nodeIds).Where(x => x != null) ?? | |
umbHelper.TypedMedia(nodeIds).Where(x => x != null); | |
return new Attempt<object>(multiNodeTreePickerContent != null, multiNodeTreePickerContent); | |
} | |
else | |
{ | |
return Attempt<object>.False; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment