Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using global::Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Umbraco.Web;
using Umbraco.Core;
using System.Linq;
namespace YourNamespace.PropertyEditors
{
[PropertyValueType(typeof(EditorColorTheme))]
[PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Content)]
public class EditorThemeColorPicker : PropertyValueConverterBase
{
public override bool IsConverter(PublishedPropertyType propertyType)
{
return propertyType.PropertyEditorAlias == "Our.Umbraco.EditorThemeColorPicker";
}
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
{
if (source == null)
{
return string.Empty;
}
return source.ToString();
}
public override object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview)
{
string sourceString = (string)source;
if (sourceString.IsNullOrWhiteSpace())
{
return null;
}
var editorColorThemeData = JsonConvert.DeserializeObject<EditorColorThemeData>(sourceString);
return new EditorColorTheme
{
BackgroundColor = "#" + editorColorThemeData.BackgroundColor,
TextColor = "#" + editorColorThemeData.TextColor
};
}
public class EditorColorTheme
{
public string BackgroundColor { get; set; }
public string TextColor { get; set; }
}
public class EditorColorThemeData
{
public string BackgroundColor { get; set; }
public string TextColor { get; set; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment