Skip to content

Instantly share code, notes, and snippets.

@BatJan
Last active October 25, 2018 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BatJan/f725cf71be5b9213db18e5fd0b0b21f0 to your computer and use it in GitHub Desktop.
Save BatJan/f725cf71be5b9213db18e5fd0b0b21f0 to your computer and use it in GitHub Desktop.
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