Changed method signatures of some of the conversion methods on the PropertyValueEditor to make it more flexible for developers to do what they want.
This commit is contained in:
@@ -4,6 +4,7 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
|
||||
namespace Umbraco.Web.Models.Mapping
|
||||
@@ -15,6 +16,13 @@ namespace Umbraco.Web.Models.Mapping
|
||||
internal class ContentPropertyBasicConverter<T> : TypeConverter<Property, T>
|
||||
where T : ContentPropertyBasic, new()
|
||||
{
|
||||
protected Lazy<IDataTypeService> DataTypeService { get; private set; }
|
||||
|
||||
public ContentPropertyBasicConverter(Lazy<IDataTypeService> dataTypeService)
|
||||
{
|
||||
DataTypeService = dataTypeService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Assigns the PropertyEditor, Id, Alias and Value to the property
|
||||
/// </summary>
|
||||
@@ -34,12 +42,11 @@ namespace Umbraco.Web.Models.Mapping
|
||||
var result = new T
|
||||
{
|
||||
Id = property.Id,
|
||||
Value = editor.ValueEditor.ConvertDbToEditor(property.Value),
|
||||
Alias = property.Alias
|
||||
Value = editor.ValueEditor.ConvertDbToEditor(property, property.PropertyType, DataTypeService.Value),
|
||||
Alias = property.Alias,
|
||||
PropertyEditor = editor
|
||||
};
|
||||
|
||||
result.PropertyEditor = editor;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,18 +13,17 @@ namespace Umbraco.Web.Models.Mapping
|
||||
/// </summary>
|
||||
internal class ContentPropertyDisplayConverter : ContentPropertyBasicConverter<ContentPropertyDisplay>
|
||||
{
|
||||
private readonly Lazy<IDataTypeService> _dataTypeService;
|
||||
|
||||
public ContentPropertyDisplayConverter(Lazy<IDataTypeService> dataTypeService)
|
||||
: base(dataTypeService)
|
||||
{
|
||||
_dataTypeService = dataTypeService;
|
||||
|
||||
}
|
||||
|
||||
protected override ContentPropertyDisplay ConvertCore(Property originalProp)
|
||||
{
|
||||
var display = base.ConvertCore(originalProp);
|
||||
|
||||
var dataTypeService = _dataTypeService.Value;
|
||||
var dataTypeService = DataTypeService.Value;
|
||||
var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(originalProp.PropertyType.DataTypeDefinitionId);
|
||||
|
||||
//configure the editor for display with the pre-values
|
||||
|
||||
@@ -12,18 +12,16 @@ namespace Umbraco.Web.Models.Mapping
|
||||
/// </summary>
|
||||
internal class ContentPropertyDtoConverter : ContentPropertyBasicConverter<ContentPropertyDto>
|
||||
{
|
||||
private readonly Lazy<IDataTypeService> _dataTypeService;
|
||||
|
||||
public ContentPropertyDtoConverter(Lazy<IDataTypeService> dataTypeService)
|
||||
: base(dataTypeService)
|
||||
{
|
||||
_dataTypeService = dataTypeService;
|
||||
}
|
||||
|
||||
protected override ContentPropertyDto ConvertCore(Property originalProperty)
|
||||
{
|
||||
var propertyDto = base.ConvertCore(originalProperty);
|
||||
|
||||
var dataTypeService = _dataTypeService.Value;
|
||||
var dataTypeService = DataTypeService.Value;
|
||||
|
||||
propertyDto.IsRequired = originalProperty.PropertyType.Mandatory;
|
||||
propertyDto.ValidationRegExp = originalProperty.PropertyType.ValidationRegExp;
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
|
||||
//FROM Property TO ContentPropertyBasic
|
||||
config.CreateMap<Property, ContentPropertyBasic>()
|
||||
.ConvertUsing<ContentPropertyBasicConverter<ContentPropertyBasic>>();
|
||||
.ConvertUsing(new ContentPropertyBasicConverter<ContentPropertyBasic>(lazyDataTypeService));
|
||||
|
||||
//FROM Property TO ContentPropertyDto
|
||||
config.CreateMap<Property, ContentPropertyDto>()
|
||||
|
||||
Reference in New Issue
Block a user