Skip to content
This repository has been archived by the owner on Dec 13, 2021. It is now read-only.

Commit

Permalink
Ditched the custome PropertyValueEditor in favour of the new SimpleIn…
Browse files Browse the repository at this point in the history
…nerContentPropertyValueEditor
  • Loading branch information
mattbrailsford committed Mar 18, 2017
1 parent 1b8d6af commit 07ba627
Showing 1 changed file with 1 addition and 70 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Our.Umbraco.InnerContent.PropertyEditors;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Editors;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;

namespace Our.Umbraco.StackedContent.PropertyEditors
{
Expand Down Expand Up @@ -64,71 +59,7 @@ internal class StackPreValueEditor : PreValueEditor

protected override PropertyValueEditor CreateValueEditor()
{
return new StackPropertyValueEditor(base.CreateValueEditor());
}

internal class StackPropertyValueEditor : InnerContentPropertyValueEditorWrapper
{
public StackPropertyValueEditor(PropertyValueEditor wrapped)
: base(wrapped)
{ }

public override string ConvertDbToString(Property property, PropertyType propertyType, IDataTypeService dataTypeService)
{
// Convert / validate value
if (property.Value == null || string.IsNullOrWhiteSpace(property.Value.ToString()))
return string.Empty;

var value = JsonConvert.DeserializeObject<JArray>(property.Value.ToString());
if (value == null)
return string.Empty;

// Process value
ConvertInnerContentDbToString(value);

// Update the value on the property
property.Value = JsonConvert.SerializeObject(value);

// Pass the call down
return base.ConvertDbToString(property, propertyType, dataTypeService);
}

public override object ConvertDbToEditor(Property property, PropertyType propertyType, IDataTypeService dataTypeService)
{
// Convert / validate value
if (property.Value == null || string.IsNullOrWhiteSpace(property.Value.ToString()))
return string.Empty;

var value = JsonConvert.DeserializeObject<JArray>(property.Value.ToString());
if (value == null)
return string.Empty;

// Process value
ConvertInnerContentDbToEditor(value);

// Update the value on the property
property.Value = JsonConvert.SerializeObject(value);

// Pass the call down
return base.ConvertDbToEditor(property, propertyType, dataTypeService);
}

public override object ConvertEditorToDb(ContentPropertyData editorValue, object currentValue)
{
// Convert / validate value
if (editorValue.Value == null || string.IsNullOrWhiteSpace(editorValue.Value.ToString()))
return null;

var value = JsonConvert.DeserializeObject<JArray>(editorValue.Value.ToString());
if (value == null || value.Count == 0)
return null;

// Process value
ConvertInnerContentEditorToDb(value);

// Return value
return JsonConvert.SerializeObject(value);
}
return new SimpleInnerContentPropertyValueEditor(base.CreateValueEditor());
}

#endregion
Expand Down

0 comments on commit 07ba627

Please sign in to comment.