PublishedContent - align with v7, refactor PublishedPropertyType
This commit is contained in:
@@ -27,20 +27,20 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
Alias = propertyType.Alias;
|
||||
|
||||
DataTypeId = propertyType.DataTypeDefinitionId;
|
||||
EditorGuid = propertyType.DataTypeId;
|
||||
PropertyEditorGuid = propertyType.DataTypeId;
|
||||
|
||||
InitializeConverters();
|
||||
}
|
||||
|
||||
// for unit tests
|
||||
internal PublishedPropertyType(string alias, Guid dataTypeGuid, int propertyTypeId, int dataTypeDefinitionId)
|
||||
internal PublishedPropertyType(string alias, Guid propertyEditorGuid, int propertyTypeId, int dataTypeDefinitionId)
|
||||
{
|
||||
// ContentType to be set by PublishedContentType when creating it
|
||||
Id = propertyTypeId;
|
||||
Alias = alias;
|
||||
|
||||
DataTypeId = dataTypeDefinitionId;
|
||||
EditorGuid = dataTypeGuid;
|
||||
PropertyEditorGuid = propertyEditorGuid;
|
||||
|
||||
InitializeConverters();
|
||||
}
|
||||
@@ -59,7 +59,7 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
|
||||
public int DataTypeId { get; private set; }
|
||||
|
||||
public Guid EditorGuid { get; private set; }
|
||||
public Guid PropertyEditorGuid { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -124,7 +124,7 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
// use the converter else use dark (& performance-wise expensive) magic
|
||||
return _sourceConverter != null
|
||||
? _sourceConverter.ConvertDataToSource(this, source, preview)
|
||||
: ConvertSourceUsingDarkMagic(source);
|
||||
: ConvertUsingDarkMagic(source);
|
||||
}
|
||||
|
||||
// gets the source cache level
|
||||
@@ -168,7 +168,7 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
// gets the xpath cache level
|
||||
public PropertyCacheLevel XPathCacheLevel { get { return _xpathCacheLevel; } }
|
||||
|
||||
private static object ConvertSourceUsingDarkMagic(object source)
|
||||
internal static object ConvertUsingDarkMagic(object source)
|
||||
{
|
||||
// convert to string
|
||||
var stringSource = source as string;
|
||||
@@ -192,7 +192,7 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
// try xml - that is expensive, performance-wise
|
||||
XElement elt;
|
||||
if (XmlHelper.TryCreateXElementFromPropertyValue(stringSource, out elt))
|
||||
return Attempt<object>.Succeed(new DynamicXml(elt)); // xml => return DynamicXml for compatiblity's sake
|
||||
return new DynamicXml(elt); // xml => return DynamicXml for compatiblity's sake
|
||||
|
||||
return source;
|
||||
}
|
||||
@@ -207,7 +207,7 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
{
|
||||
return PropertyEditorValueConvertersResolver.HasCurrent
|
||||
? PropertyEditorValueConvertersResolver.Current.Converters
|
||||
.Where(x => x.IsConverterFor(EditorGuid, ContentType.Alias, Alias))
|
||||
.Where(x => x.IsConverterFor(PropertyEditorGuid, ContentType.Alias, Alias))
|
||||
.Select(x => new CompatConverter(x))
|
||||
: Enumerable.Empty<IPropertyValueConverter>();
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Umbraco.Core.PropertyEditors
|
||||
{
|
||||
[PropertyValueType(typeof(DateTime))]
|
||||
[PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Content)]
|
||||
internal class DatePickerValueConverter : IPropertyValueConverter
|
||||
internal class DatePickerValueConverter : PropertyValueConverterBase
|
||||
{
|
||||
private static readonly Guid[] DataTypeGuids = new[]
|
||||
{
|
||||
@@ -16,12 +16,12 @@ namespace Umbraco.Core.PropertyEditors
|
||||
Guid.Parse(Constants.PropertyEditors.Date)
|
||||
};
|
||||
|
||||
public bool IsDataToSourceConverter(PublishedPropertyType propertyType)
|
||||
public override bool IsDataToSourceConverter(PublishedPropertyType propertyType)
|
||||
{
|
||||
return DataTypeGuids.Contains(propertyType.EditorGuid);
|
||||
return DataTypeGuids.Contains(propertyType.PropertyEditorGuid);
|
||||
}
|
||||
|
||||
public object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
|
||||
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
|
||||
{
|
||||
if (source == null) return DateTime.MinValue;
|
||||
|
||||
@@ -42,23 +42,19 @@ namespace Umbraco.Core.PropertyEditors
|
||||
: DateTime.MinValue;
|
||||
}
|
||||
|
||||
public bool IsSourceToObjectConverter(PublishedPropertyType propertyType)
|
||||
public override bool IsSourceToObjectConverter(PublishedPropertyType propertyType)
|
||||
{
|
||||
return IsDataToSourceConverter(propertyType);
|
||||
}
|
||||
|
||||
public object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview)
|
||||
{
|
||||
// source should come from ConvertSource and be a DateTime already
|
||||
return source;
|
||||
}
|
||||
// default ConvertSourceToObject just returns source ie a DateTime value
|
||||
|
||||
public bool IsSourceToXPathConverter(PublishedPropertyType propertyType)
|
||||
public override bool IsSourceToXPathConverter(PublishedPropertyType propertyType)
|
||||
{
|
||||
return IsDataToSourceConverter(propertyType);
|
||||
}
|
||||
|
||||
public object ConvertSourceToXPath(PublishedPropertyType propertyType, object source, bool preview)
|
||||
public override object ConvertSourceToXPath(PublishedPropertyType propertyType, object source, bool preview)
|
||||
{
|
||||
// source should come from ConvertSource and be a DateTime already
|
||||
return XmlConvert.ToString((DateTime) source, "yyyy-MM-ddTHH:mm:ss");
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
|
||||
namespace Umbraco.Core.PropertyEditors
|
||||
{
|
||||
@@ -10,34 +7,34 @@ namespace Umbraco.Core.PropertyEditors
|
||||
/// </summary>
|
||||
class PropertyValueConverterBase : IPropertyValueConverter
|
||||
{
|
||||
public virtual bool IsSourceToObjectConverter(Models.PublishedContent.PublishedPropertyType propertyType)
|
||||
public virtual bool IsDataToSourceConverter(PublishedPropertyType propertyType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual object ConvertSourceToObject(Models.PublishedContent.PublishedPropertyType propertyType, object source, bool preview)
|
||||
public virtual object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
|
||||
{
|
||||
return null;
|
||||
return PublishedPropertyType.ConvertUsingDarkMagic(source);
|
||||
}
|
||||
|
||||
public virtual bool IsDataToSourceConverter(Models.PublishedContent.PublishedPropertyType propertyType)
|
||||
public virtual bool IsSourceToObjectConverter(PublishedPropertyType propertyType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual object ConvertDataToSource(Models.PublishedContent.PublishedPropertyType propertyType, object source, bool preview)
|
||||
public virtual object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview)
|
||||
{
|
||||
return null;
|
||||
return source;
|
||||
}
|
||||
|
||||
public virtual bool IsSourceToXPathConverter(Models.PublishedContent.PublishedPropertyType propertyType)
|
||||
public virtual bool IsSourceToXPathConverter(PublishedPropertyType propertyType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual object ConvertSourceToXPath(Models.PublishedContent.PublishedPropertyType propertyType, object source, bool preview)
|
||||
public virtual object ConvertSourceToXPath(PublishedPropertyType propertyType, object source, bool preview)
|
||||
{
|
||||
return null;
|
||||
return source.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,14 +10,14 @@ namespace Umbraco.Core.PropertyEditors
|
||||
// PropertyCacheLevel.Content is ok here because that version of RTE converter does not parse {locallink} nor executes macros
|
||||
[PropertyValueType(typeof(IHtmlString))]
|
||||
[PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Content)]
|
||||
internal class TinyMceValueConverter : IPropertyValueConverter
|
||||
internal class TinyMceValueConverter : PropertyValueConverterBase
|
||||
{
|
||||
public bool IsDataToSourceConverter(PublishedPropertyType propertyType)
|
||||
public override bool IsDataToSourceConverter(PublishedPropertyType propertyType)
|
||||
{
|
||||
return Guid.Parse(Constants.PropertyEditors.TinyMCEv3).Equals(propertyType.EditorGuid);
|
||||
return Guid.Parse(Constants.PropertyEditors.TinyMCEv3).Equals(propertyType.PropertyEditorGuid);
|
||||
}
|
||||
|
||||
public virtual object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
|
||||
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
|
||||
{
|
||||
// in xml a string is: string
|
||||
// in the database a string is: string
|
||||
@@ -25,25 +25,25 @@ namespace Umbraco.Core.PropertyEditors
|
||||
return source;
|
||||
}
|
||||
|
||||
public bool IsSourceToObjectConverter(PublishedPropertyType propertyType)
|
||||
public override bool IsSourceToObjectConverter(PublishedPropertyType propertyType)
|
||||
{
|
||||
return IsDataToSourceConverter(propertyType);
|
||||
}
|
||||
|
||||
public virtual object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview)
|
||||
public override object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview)
|
||||
{
|
||||
// source should come from ConvertSource and be a string already
|
||||
return new HtmlString((string)source);
|
||||
// source should come from ConvertSource and be a string (or null) already
|
||||
return new HtmlString(source == null ? string.Empty : (string)source);
|
||||
}
|
||||
|
||||
public bool IsSourceToXPathConverter(PublishedPropertyType propertyType)
|
||||
public override bool IsSourceToXPathConverter(PublishedPropertyType propertyType)
|
||||
{
|
||||
return IsDataToSourceConverter(propertyType);
|
||||
}
|
||||
|
||||
public virtual object ConvertSourceToXPath(PublishedPropertyType propertyType, object source, bool preview)
|
||||
public override object ConvertSourceToXPath(PublishedPropertyType propertyType, object source, bool preview)
|
||||
{
|
||||
// source should come from ConvertSource and be a string already
|
||||
// source should come from ConvertSource and be a string (or null) already
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,14 +5,14 @@ namespace Umbraco.Core.PropertyEditors
|
||||
{
|
||||
[PropertyValueType(typeof(bool))]
|
||||
[PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Content)]
|
||||
class YesNoValueConverter : IPropertyValueConverter
|
||||
class YesNoValueConverter : PropertyValueConverterBase
|
||||
{
|
||||
public bool IsDataToSourceConverter(PublishedPropertyType propertyType)
|
||||
public override bool IsDataToSourceConverter(PublishedPropertyType propertyType)
|
||||
{
|
||||
return Guid.Parse(Constants.PropertyEditors.TrueFalse).Equals(propertyType.EditorGuid);
|
||||
return Guid.Parse(Constants.PropertyEditors.TrueFalse).Equals(propertyType.PropertyEditorGuid);
|
||||
}
|
||||
|
||||
public object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
|
||||
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
|
||||
{
|
||||
// in xml a boolean is: string
|
||||
// in the database a boolean is: string "1" or "0" or empty
|
||||
@@ -24,23 +24,19 @@ namespace Umbraco.Core.PropertyEditors
|
||||
return sourceString == "1";
|
||||
}
|
||||
|
||||
public bool IsSourceToObjectConverter(PublishedPropertyType propertyType)
|
||||
public override bool IsSourceToObjectConverter(PublishedPropertyType propertyType)
|
||||
{
|
||||
return IsDataToSourceConverter(propertyType);
|
||||
}
|
||||
|
||||
public object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview)
|
||||
{
|
||||
// source should come from ConvertSource and be a boolean already
|
||||
return source;
|
||||
}
|
||||
// default ConvertSourceToObject just returns source ie a boolean value
|
||||
|
||||
public bool IsSourceToXPathConverter(PublishedPropertyType propertyType)
|
||||
public override bool IsSourceToXPathConverter(PublishedPropertyType propertyType)
|
||||
{
|
||||
return IsDataToSourceConverter(propertyType);
|
||||
}
|
||||
|
||||
public object ConvertSourceToXPath(PublishedPropertyType propertyType, object source, bool preview)
|
||||
public override object ConvertSourceToXPath(PublishedPropertyType propertyType, object source, bool preview)
|
||||
{
|
||||
// source should come from ConvertSource and be a boolean already
|
||||
return (bool) source ? "1" : "0";
|
||||
|
||||
Reference in New Issue
Block a user