Last active
October 25, 2018 06:10
-
-
Save BatJan/f725cf71be5b9213db18e5fd0b0b21f0 to your computer and use it in GitHub Desktop.
This file contains 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 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