diff --git a/src/Umbraco.Core/Models/IDataValueEditor.cs b/src/Umbraco.Core/Models/IDataValueEditor.cs
index 5a1c6fd29d..6158711c3c 100644
--- a/src/Umbraco.Core/Models/IDataValueEditor.cs
+++ b/src/Umbraco.Core/Models/IDataValueEditor.cs
@@ -59,12 +59,12 @@ namespace Umbraco.Core.PropertyEditors
///
/// Converts a property value to a value for the editor.
///
- object ToEditor(IProperty property, IDataTypeService dataTypeService, string culture = null, string segment = null);
+ object ToEditor(IProperty property, string culture = null, string segment = null);
// TODO: / deal with this when unplugging the xml cache
// why property vs propertyType? services should be injected! etc...
- IEnumerable ConvertDbToXml(IProperty property, IDataTypeService dataTypeService, ILocalizationService localizationService, bool published);
- XNode ConvertDbToXml(IPropertyType propertyType, object value, IDataTypeService dataTypeService);
- string ConvertDbToString(IPropertyType propertyType, object value, IDataTypeService dataTypeService);
+ IEnumerable ConvertDbToXml(IProperty property, bool published);
+ XNode ConvertDbToXml(IPropertyType propertyType, object value);
+ string ConvertDbToString(IPropertyType propertyType, object value);
}
}
diff --git a/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs
index 396d32c833..3dde5a8949 100644
--- a/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs
+++ b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs
@@ -20,6 +20,8 @@ namespace Umbraco.Core.PropertyEditors
///
public class DataValueEditor : IDataValueEditor
{
+ protected readonly IDataTypeService _dataTypeService;
+ protected readonly ILocalizationService _localizationService;
private string _view;
///
@@ -29,14 +31,18 @@ namespace Umbraco.Core.PropertyEditors
{
ValueType = ValueTypes.String;
Validators = new List();
+ _dataTypeService = Current.Services.DataTypeService;
+ _localizationService = Current.Services.LocalizationService;
}
///
/// Initializes a new instance of the class.
///
- public DataValueEditor(string view, params IValueValidator[] validators) // not used
+ public DataValueEditor(IDataTypeService dataTypeService, ILocalizationService localizationService, string view, params IValueValidator[] validators) // not used
: this()
{
+ _dataTypeService = dataTypeService;
+ _localizationService = localizationService;
View = view;
Validators.AddRange(validators);
}
@@ -232,7 +238,7 @@ namespace Umbraco.Core.PropertyEditors
/// The object returned will automatically be serialized into json notation. For most property editors
/// the value returned is probably just a string but in some cases a json structure will be returned.
///
- public virtual object ToEditor(IProperty property, IDataTypeService dataTypeService, string culture = null, string segment = null)
+ public virtual object ToEditor(IProperty property, string culture = null, string segment = null)
{
var val = property.GetValue(culture, segment);
if (val == null) return string.Empty;
@@ -283,7 +289,7 @@ namespace Umbraco.Core.PropertyEditors
///
/// Converts a property to Xml fragments.
///
- public IEnumerable ConvertDbToXml(IProperty property, IDataTypeService dataTypeService, ILocalizationService localizationService, bool published)
+ public IEnumerable ConvertDbToXml(IProperty property, bool published)
{
published &= property.PropertyType.SupportsPublishing;
@@ -301,7 +307,7 @@ namespace Umbraco.Core.PropertyEditors
if (pvalue.Segment != null)
xElement.Add(new XAttribute("segment", pvalue.Segment));
- var xValue = ConvertDbToXml(property.PropertyType, value, dataTypeService);
+ var xValue = ConvertDbToXml(property.PropertyType, value);
xElement.Add(xValue);
yield return xElement;
@@ -317,12 +323,12 @@ namespace Umbraco.Core.PropertyEditors
/// Returns an XText or XCData instance which must be wrapped in a element.
/// If the value is empty we will not return as CDATA since that will just take up more space in the file.
///
- public XNode ConvertDbToXml(IPropertyType propertyType, object value, IDataTypeService dataTypeService)
+ public XNode ConvertDbToXml(IPropertyType propertyType, object value)
{
//check for null or empty value, we don't want to return CDATA if that is the case
if (value == null || value.ToString().IsNullOrWhiteSpace())
{
- return new XText(ConvertDbToString(propertyType, value, dataTypeService));
+ return new XText(ConvertDbToString(propertyType, value));
}
switch (ValueTypes.ToStorageType(ValueType))
@@ -330,11 +336,11 @@ namespace Umbraco.Core.PropertyEditors
case ValueStorageType.Date:
case ValueStorageType.Integer:
case ValueStorageType.Decimal:
- return new XText(ConvertDbToString(propertyType, value, dataTypeService));
+ return new XText(ConvertDbToString(propertyType, value));
case ValueStorageType.Nvarchar:
case ValueStorageType.Ntext:
//put text in cdata
- return new XCData(ConvertDbToString(propertyType, value, dataTypeService));
+ return new XCData(ConvertDbToString(propertyType, value));
default:
throw new ArgumentOutOfRangeException();
}
@@ -343,7 +349,7 @@ namespace Umbraco.Core.PropertyEditors
///
/// Converts a property value to a string.
///
- public virtual string ConvertDbToString(IPropertyType propertyType, object value, IDataTypeService dataTypeService)
+ public virtual string ConvertDbToString(IPropertyType propertyType, object value)
{
if (value == null)
return string.Empty;
diff --git a/src/Umbraco.Core/Services/Implement/EntityXmlSerializer.cs b/src/Umbraco.Core/Services/Implement/EntityXmlSerializer.cs
index f115dacc6c..f488c12657 100644
--- a/src/Umbraco.Core/Services/Implement/EntityXmlSerializer.cs
+++ b/src/Umbraco.Core/Services/Implement/EntityXmlSerializer.cs
@@ -560,7 +560,7 @@ namespace Umbraco.Core.Services.Implement
var propertyEditor = Current.PropertyEditors[propertyType.PropertyEditorAlias];
return propertyEditor == null
? Array.Empty()
- : propertyEditor.GetValueEditor().ConvertDbToXml(property, _dataTypeService, _localizationService, published);
+ : propertyEditor.GetValueEditor().ConvertDbToXml(property, published);
}
// exports an IContent item descendants.
diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj
index 0bd65f784c..4532483471 100755
--- a/src/Umbraco.Core/Umbraco.Core.csproj
+++ b/src/Umbraco.Core/Umbraco.Core.csproj
@@ -236,7 +236,6 @@
-
@@ -295,8 +294,6 @@
-
-
diff --git a/src/Umbraco.Tests/Models/VariationTests.cs b/src/Umbraco.Tests/Models/VariationTests.cs
index ab5f726894..28663a9dbe 100644
--- a/src/Umbraco.Tests/Models/VariationTests.cs
+++ b/src/Umbraco.Tests/Models/VariationTests.cs
@@ -8,6 +8,7 @@ using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
+using Umbraco.Core.Services.Implement;
using Umbraco.Tests.TestHelpers;
namespace Umbraco.Tests.Models
@@ -35,9 +36,12 @@ namespace Umbraco.Tests.Models
var factory = Mock.Of();
Current.Factory = factory;
+ var dataTypeService = Mock.Of();
+ var localizationService = Mock.Of();
+
var dataEditors = new DataEditorCollection(new IDataEditor[]
{
- new DataEditor(Mock.Of()) { Alias = "editor", ExplicitValueEditor = new DataValueEditor("view") }
+ new DataEditor(Mock.Of()) { Alias = "editor", ExplicitValueEditor = new DataValueEditor(dataTypeService, localizationService, "view") }
});
var propertyEditors = new PropertyEditorCollection(dataEditors);
@@ -46,7 +50,6 @@ namespace Umbraco.Tests.Models
.Setup(x => x.Configuration)
.Returns(null);
- var dataTypeService = Mock.Of();
Mock.Get(dataTypeService)
.Setup(x => x.GetDataType(It.IsAny()))
.Returns(x => dataType);
@@ -75,7 +78,7 @@ namespace Umbraco.Tests.Models
// 1. if exact is set to true: culture cannot be null when the ContentVariation.Culture flag is set
// 2. if wildcards is set to false: fail when "*" is passed in as either culture or segment.
// 3. ContentVariation flag is ignored when wildcards are used.
- // 4. Empty string is considered the same as null
+ // 4. Empty string is considered the same as null
#region Nothing
@@ -141,7 +144,7 @@ namespace Umbraco.Tests.Models
#endregion
#region CultureAndSegment
-
+
Assert4B(ContentVariation.CultureAndSegment, null, null, false, true, false, true);
Assert4B(ContentVariation.CultureAndSegment, null, "", false, true, false, true);
Assert4B(ContentVariation.CultureAndSegment, null, "*", false, false, false, true);
@@ -163,7 +166,7 @@ namespace Umbraco.Tests.Models
}
///
- /// Asserts the result of
+ /// Asserts the result of
///
///
///
diff --git a/src/Umbraco.Tests/PropertyEditors/MultiValuePropertyEditorTests.cs b/src/Umbraco.Tests/PropertyEditors/MultiValuePropertyEditorTests.cs
index b7037eb192..7f708b6c53 100644
--- a/src/Umbraco.Tests/PropertyEditors/MultiValuePropertyEditorTests.cs
+++ b/src/Umbraco.Tests/PropertyEditors/MultiValuePropertyEditorTests.cs
@@ -25,7 +25,7 @@ namespace Umbraco.Tests.PropertyEditors
/// to cache. Now we always just deal with strings and we'll keep the tests that show that.
///
[TestFixture]
- public class MultiValuePropertyEditorTests
+ public class MultiValuePropertyEditorTests
{
[Test]
public void DropDownMultipleValueEditor_Format_Data_For_Cache()
@@ -51,7 +51,7 @@ namespace Umbraco.Tests.PropertyEditors
var valueEditor = dataType.Editor.GetValueEditor();
((DataValueEditor) valueEditor).Configuration = dataType.Configuration;
- var result = valueEditor.ConvertDbToString(prop.PropertyType, prop.GetValue(), dataTypeService);
+ var result = valueEditor.ConvertDbToString(prop.PropertyType, prop.GetValue());
Assert.AreEqual("Value 1,Value 2,Value 3", result);
}
@@ -78,7 +78,7 @@ namespace Umbraco.Tests.PropertyEditors
var prop = new Property(1, new PropertyType(dataType));
prop.SetValue("Value 2");
- var result = dataType.Editor.GetValueEditor().ConvertDbToString(prop.PropertyType, prop.GetValue(), dataTypeService);
+ var result = dataType.Editor.GetValueEditor().ConvertDbToString(prop.PropertyType, prop.GetValue());
Assert.AreEqual("Value 2", result);
}
diff --git a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs
index 764f6ac4a4..c7e889c84b 100644
--- a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs
+++ b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs
@@ -52,7 +52,7 @@ namespace Umbraco.Tests.PropertyEditors
ValueType = ValueTypes.String
};
- var result = valueEditor.ToEditor(prop, new Mock().Object);
+ var result = valueEditor.ToEditor(prop);
Assert.AreEqual(isOk, !(result is string));
}
@@ -142,7 +142,7 @@ namespace Umbraco.Tests.PropertyEditors
ValueType = valueType
};
- var result = valueEditor.ToEditor(prop, new Mock().Object);
+ var result = valueEditor.ToEditor(prop);
Assert.AreEqual(expected, result);
}
@@ -158,7 +158,7 @@ namespace Umbraco.Tests.PropertyEditors
var prop = new Property(1, new PropertyType("test", ValueStorageType.Decimal));
prop.SetValue(value);
- var result = valueEditor.ToEditor(prop, new Mock().Object);
+ var result = valueEditor.ToEditor(prop);
Assert.AreEqual("12.34", result);
}
@@ -173,7 +173,7 @@ namespace Umbraco.Tests.PropertyEditors
var prop = new Property(1, new PropertyType("test", ValueStorageType.Decimal));
prop.SetValue(string.Empty);
- var result = valueEditor.ToEditor(prop, new Mock().Object);
+ var result = valueEditor.ToEditor(prop);
Assert.AreEqual(string.Empty, result);
}
@@ -189,7 +189,7 @@ namespace Umbraco.Tests.PropertyEditors
var prop = new Property(1, new PropertyType("test", ValueStorageType.Date));
prop.SetValue(now);
- var result = valueEditor.ToEditor(prop, new Mock().Object);
+ var result = valueEditor.ToEditor(prop);
Assert.AreEqual(now.ToIsoString(), result);
}
}
diff --git a/src/Umbraco.Web/Models/Mapping/ContentPropertyBasicMapper.cs b/src/Umbraco.Web/Models/Mapping/ContentPropertyBasicMapper.cs
index 4e49f2ea2a..cddcfc6d1c 100644
--- a/src/Umbraco.Web/Models/Mapping/ContentPropertyBasicMapper.cs
+++ b/src/Umbraco.Web/Models/Mapping/ContentPropertyBasicMapper.cs
@@ -71,7 +71,7 @@ namespace Umbraco.Web.Models.Mapping
dest.Culture = culture;
// if no 'IncludeProperties' were specified or this property is set to be included - we will map the value and return.
- dest.Value = editor.GetValueEditor().ToEditor(property, DataTypeService, culture);
+ dest.Value = editor.GetValueEditor().ToEditor(property, culture);
}
}
}
diff --git a/src/Umbraco.Web/PropertyEditors/DateValueEditor.cs b/src/Umbraco.Web/PropertyEditors/DateValueEditor.cs
index 657e2b2b49..bc1c5dc5f8 100644
--- a/src/Umbraco.Web/PropertyEditors/DateValueEditor.cs
+++ b/src/Umbraco.Web/PropertyEditors/DateValueEditor.cs
@@ -18,7 +18,7 @@ namespace Umbraco.Web.PropertyEditors
Validators.Add(new DateTimeValidator());
}
- public override object ToEditor(IProperty property, IDataTypeService dataTypeService, string culture= null, string segment = null)
+ public override object ToEditor(IProperty property, string culture= null, string segment = null)
{
var date = property.GetValue(culture, segment).TryConvertTo();
if (date.Success == false || date.Result == null)
diff --git a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs
index 5964964ab7..bae06e09c2 100644
--- a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs
+++ b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs
@@ -115,7 +115,7 @@ namespace Umbraco.Web.PropertyEditors
///
///
///
- public override object ToEditor(IProperty property, IDataTypeService dataTypeService, string culture = null, string segment = null)
+ public override object ToEditor(IProperty property, string culture = null, string segment = null)
{
var val = property.GetValue(culture, segment);
if (val == null) return string.Empty;
diff --git a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs
index fdeb726902..c9ce5a9d9d 100644
--- a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs
+++ b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs
@@ -32,7 +32,7 @@ namespace Umbraco.Web.PropertyEditors
/// This is called to merge in the prevalue crops with the value that is saved - similar to the property value converter for the front-end
///
- public override object ToEditor(IProperty property, IDataTypeService dataTypeService, string culture = null, string segment = null)
+ public override object ToEditor(IProperty property, string culture = null, string segment = null)
{
var val = property.GetValue(culture, segment);
if (val == null) return null;
@@ -47,7 +47,7 @@ namespace Umbraco.Web.PropertyEditors
value = new ImageCropperValue { Src = val.ToString() };
}
- var dataType = dataTypeService.GetDataType(property.PropertyType.DataTypeId);
+ var dataType = _dataTypeService.GetDataType(property.PropertyType.DataTypeId);
if (dataType?.Configuration != null)
value.ApplyConfiguration(dataType.ConfigurationAs());
@@ -161,7 +161,7 @@ namespace Umbraco.Web.PropertyEditors
}
- public override string ConvertDbToString(IPropertyType propertyType, object value, IDataTypeService dataTypeService)
+ public override string ConvertDbToString(IPropertyType propertyType, object value)
{
if (value == null || string.IsNullOrEmpty(value.ToString()))
return null;
@@ -172,7 +172,7 @@ namespace Umbraco.Web.PropertyEditors
return val;
// more magic here ;-(
- var configuration = dataTypeService.GetDataType(propertyType.DataTypeId).ConfigurationAs();
+ var configuration = _dataTypeService.GetDataType(propertyType.DataTypeId).ConfigurationAs();
var crops = configuration?.Crops ?? Array.Empty();
return JsonConvert.SerializeObject(new
diff --git a/src/Umbraco.Web/PropertyEditors/MultiUrlPickerValueEditor.cs b/src/Umbraco.Web/PropertyEditors/MultiUrlPickerValueEditor.cs
index c2ad58a101..36d40cceb8 100644
--- a/src/Umbraco.Web/PropertyEditors/MultiUrlPickerValueEditor.cs
+++ b/src/Umbraco.Web/PropertyEditors/MultiUrlPickerValueEditor.cs
@@ -28,7 +28,7 @@ namespace Umbraco.Web.PropertyEditors
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
- public override object ToEditor(IProperty property, IDataTypeService dataTypeService, string culture = null, string segment = null)
+ public override object ToEditor(IProperty property, string culture = null, string segment = null)
{
var value = property.GetValue(culture, segment)?.ToString();
@@ -118,7 +118,7 @@ namespace Umbraco.Web.PropertyEditors
_logger.Error("Error getting links", ex);
}
- return base.ToEditor(property, dataTypeService, culture, segment);
+ return base.ToEditor(property, culture, segment);
}
diff --git a/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs
index 23ceb0f22a..279bc3618a 100644
--- a/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs
+++ b/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs
@@ -95,7 +95,7 @@ namespace Umbraco.Web.PropertyEditors
///
/// The legacy property editor saved this data as new line delimited! strange but we have to maintain that.
///
- public override object ToEditor(IProperty property, IDataTypeService dataTypeService, string culture = null, string segment = null)
+ public override object ToEditor(IProperty property, string culture = null, string segment = null)
{
var val = property.GetValue(culture, segment);
return val?.ToString().Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
diff --git a/src/Umbraco.Web/PropertyEditors/MultipleValueEditor.cs b/src/Umbraco.Web/PropertyEditors/MultipleValueEditor.cs
index 4c59a8e3c5..b46de6d092 100644
--- a/src/Umbraco.Web/PropertyEditors/MultipleValueEditor.cs
+++ b/src/Umbraco.Web/PropertyEditors/MultipleValueEditor.cs
@@ -33,9 +33,9 @@ namespace Umbraco.Web.PropertyEditors
///
///
///
- public override object ToEditor(IProperty property, IDataTypeService dataTypeService, string culture = null, string segment = null)
+ public override object ToEditor(IProperty property, string culture = null, string segment = null)
{
- var json = base.ToEditor(property, dataTypeService, culture, segment).ToString();
+ var json = base.ToEditor(property, culture, segment).ToString();
return JsonConvert.DeserializeObject(json) ?? Array.Empty();
}
diff --git a/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs
index 778b69d9db..8784a9bb49 100644
--- a/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs
+++ b/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs
@@ -92,7 +92,7 @@ namespace Umbraco.Web.PropertyEditors
#region DB to String
- public override string ConvertDbToString(IPropertyType propertyType, object propertyValue, IDataTypeService dataTypeService)
+ public override string ConvertDbToString(IPropertyType propertyType, object propertyValue)
{
if (propertyValue == null || string.IsNullOrWhiteSpace(propertyValue.ToString()))
return string.Empty;
@@ -129,9 +129,9 @@ namespace Umbraco.Web.PropertyEditors
{
continue;
}
- var tempConfig = dataTypeService.GetDataType(propType.DataTypeId).Configuration;
+ var tempConfig = _dataTypeService.GetDataType(propType.DataTypeId).Configuration;
var valEditor = propEditor.GetValueEditor(tempConfig);
- var convValue = valEditor.ConvertDbToString(propType, propValues[propAlias]?.ToString(), dataTypeService);
+ var convValue = valEditor.ConvertDbToString(propType, propValues[propAlias]?.ToString());
propValues[propAlias] = convValue;
}
catch (InvalidOperationException)
@@ -152,7 +152,7 @@ namespace Umbraco.Web.PropertyEditors
// note: there is NO variant support here
- public override object ToEditor(IProperty property, IDataTypeService dataTypeService, string culture = null, string segment = null)
+ public override object ToEditor(IProperty property, string culture = null, string segment = null)
{
var val = property.GetValue(culture, segment);
if (val == null || string.IsNullOrWhiteSpace(val.ToString()))
@@ -197,9 +197,9 @@ namespace Umbraco.Web.PropertyEditors
propValues[propAlias] = tempProp.GetValue()?.ToString();
continue;
}
- var tempConfig = dataTypeService.GetDataType(propType.DataTypeId).Configuration;
+ var tempConfig = _dataTypeService.GetDataType(propType.DataTypeId).Configuration;
var valEditor = propEditor.GetValueEditor(tempConfig);
- var convValue = valEditor.ToEditor(tempProp, dataTypeService);
+ var convValue = valEditor.ToEditor(tempProp);
propValues[propAlias] = convValue == null ? null : JToken.FromObject(convValue);
}
catch (InvalidOperationException)
diff --git a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs
index 1fa2c9323b..6932504f06 100644
--- a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs
+++ b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs
@@ -92,7 +92,7 @@ namespace Umbraco.Web.PropertyEditors
///
///
///
- public override object ToEditor(IProperty property, IDataTypeService dataTypeService, string culture = null, string segment = null)
+ public override object ToEditor(IProperty property, string culture = null, string segment = null)
{
var val = property.GetValue(culture, segment);
if (val == null)
diff --git a/src/Umbraco.Web/PropertyEditors/TextOnlyValueEditor.cs b/src/Umbraco.Web/PropertyEditors/TextOnlyValueEditor.cs
index f925daba30..826051a79b 100644
--- a/src/Umbraco.Web/PropertyEditors/TextOnlyValueEditor.cs
+++ b/src/Umbraco.Web/PropertyEditors/TextOnlyValueEditor.cs
@@ -26,7 +26,7 @@ namespace Umbraco.Web.PropertyEditors
///
/// The object returned will always be a string and if the database type is not a valid string type an exception is thrown
///
- public override object ToEditor(IProperty property, IDataTypeService dataTypeService, string culture = null, string segment = null)
+ public override object ToEditor(IProperty property, string culture = null, string segment = null)
{
var val = property.GetValue(culture, segment);