diff --git a/src/Umbraco.Core/PropertyEditors/SliderConfiguration.cs b/src/Umbraco.Core/PropertyEditors/SliderConfiguration.cs index 3dc4ea2057..68b90c7403 100644 --- a/src/Umbraco.Core/PropertyEditors/SliderConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/SliderConfiguration.cs @@ -1,5 +1,3 @@ -using System.Text.Json.Serialization; - namespace Umbraco.Cms.Core.PropertyEditors; /// @@ -15,10 +13,4 @@ public class SliderConfiguration [ConfigurationField("maxVal")] public decimal MaximumValue { get; set; } - - [ConfigurationField("initVal1")] - public decimal InitialValue1 { get; set; } - - [ConfigurationField("initVal2")] - public decimal InitialValue2 { get; set; } } diff --git a/src/Umbraco.Core/PropertyEditors/TrueFalseConfiguration.cs b/src/Umbraco.Core/PropertyEditors/TrueFalseConfiguration.cs deleted file mode 100644 index 589075b936..0000000000 --- a/src/Umbraco.Core/PropertyEditors/TrueFalseConfiguration.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Umbraco.Cms.Core.PropertyEditors; - -/// -/// Represents the configuration for the true/false (toggle) value editor. -/// -public class TrueFalseConfiguration -{ - [ConfigurationField("default")] - public bool InitialState { get; set; } -} diff --git a/src/Umbraco.Core/PropertyEditors/TrueFalseConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/TrueFalseConfigurationEditor.cs deleted file mode 100644 index 0e9bfd0d36..0000000000 --- a/src/Umbraco.Core/PropertyEditors/TrueFalseConfigurationEditor.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Umbraco.Cms.Core.IO; - -namespace Umbraco.Cms.Core.PropertyEditors; - -/// -/// Represents the configuration editor for the true/false (toggle) value editor. -/// -public class TrueFalseConfigurationEditor : ConfigurationEditor -{ - public TrueFalseConfigurationEditor(IIOHelper ioHelper) - : base(ioHelper) - { - } -} diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/SliderValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/SliderValueConverter.cs index 0a34668e23..28eedeb797 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/SliderValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/SliderValueConverter.cs @@ -49,29 +49,16 @@ public class SliderValueConverter : PropertyValueConverterBase /// public override object? ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object? source, bool preview) { - SliderConfiguration? configuration = propertyType.DataType.ConfigurationAs(); - bool isRange = IsRange(configuration); + bool isRange = IsRange(propertyType); var sourceString = source?.ToString(); - // If source is null, the returned value depends on the configured initial values. - if (string.IsNullOrEmpty(sourceString)) - { - return isRange - ? new Range - { - Minimum = configuration?.InitialValue1 ?? 0M, - Maximum = configuration?.InitialValue2 ?? 0M - } - : configuration?.InitialValue1 ?? 0M; - } - return isRange ? HandleRange(sourceString) : HandleDecimal(sourceString); } - private static Range HandleRange(string sourceString) + private static Range HandleRange(string? sourceString) { if (sourceString is null) { @@ -105,8 +92,13 @@ public class SliderValueConverter : PropertyValueConverterBase return new Range(); } - private static decimal HandleDecimal(string sourceString) + private static decimal HandleDecimal(string? sourceString) { + if (string.IsNullOrEmpty(sourceString)) + { + return default; + } + // This used to be a range slider, so we'll assign the minimum value as the new value if (sourceString.Contains(',')) { @@ -131,9 +123,7 @@ public class SliderValueConverter : PropertyValueConverterBase private static bool TryParseDecimal(string? representation, out decimal value) => decimal.TryParse(representation, NumberStyles.Number, CultureInfo.InvariantCulture, out value); - private static bool IsRange(IPublishedPropertyType propertyType) - => IsRange(propertyType.DataType.ConfigurationAs()); - private static bool IsRange(SliderConfiguration? configuration) - => configuration?.EnableRange == true; + private static bool IsRange(IPublishedPropertyType propertyType) + => propertyType.DataType.ConfigurationAs()?.EnableRange == true; } diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/YesNoValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/YesNoValueConverter.cs index 96b8afc250..f3953d73a3 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/YesNoValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/YesNoValueConverter.cs @@ -18,7 +18,7 @@ public class YesNoValueConverter : PropertyValueConverterBase { if (source is null) { - return null; + return false; } // in xml a boolean is: string @@ -59,17 +59,4 @@ public class YesNoValueConverter : PropertyValueConverterBase // false for any other value return false; } - - /// - public override object? ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object? source, bool preview) - { - // If source is null, whether we return true or false depends on the configured default value (initial state). - if (source is null) - { - TrueFalseConfiguration? configuration = propertyType.DataType.ConfigurationAs(); - return configuration?.InitialState ?? false; - } - - return (bool)source; - } } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/TrueFalsePropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/TrueFalsePropertyEditor.cs index 98e70a8c80..66d1af9c77 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/TrueFalsePropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/TrueFalsePropertyEditor.cs @@ -1,8 +1,6 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Editors; @@ -20,37 +18,17 @@ namespace Umbraco.Cms.Core.PropertyEditors; ValueEditorIsReusable = true)] public class TrueFalsePropertyEditor : DataEditor { - private readonly IIOHelper _ioHelper; - /// /// Initializes a new instance of the class. /// - [Obsolete("Please use the constructor taking all parameters. This constructor will be removed in V17.")] public TrueFalsePropertyEditor(IDataValueEditorFactory dataValueEditorFactory) - : this( - dataValueEditorFactory, - StaticServiceProvider.Instance.GetRequiredService()) - { - } - - /// - /// Initializes a new instance of the class. - /// - public TrueFalsePropertyEditor(IDataValueEditorFactory dataValueEditorFactory, IIOHelper ioHelper) : base(dataValueEditorFactory) - { - _ioHelper = ioHelper; - SupportsReadOnly = true; - } + => SupportsReadOnly = true; /// protected override IDataValueEditor CreateValueEditor() => DataValueEditorFactory.Create(Attribute!); - /// - protected override IConfigurationEditor CreateConfigurationEditor() => - new TrueFalseConfigurationEditor(_ioHelper); - internal class TrueFalsePropertyValueEditor : DataValueEditor { public TrueFalsePropertyValueEditor( diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/PropertyEditorValueConverterTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/PropertyEditorValueConverterTests.cs index a4ef26ece9..461edeef69 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/PropertyEditorValueConverterTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/PropertyEditorValueConverterTests.cs @@ -9,7 +9,6 @@ using Umbraco.Cms.Core.PropertyEditors; using Umbraco.Cms.Core.PropertyEditors.ValueConverters; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Infrastructure.Serialization; -using Umbraco.Cms.Tests.Common.Builders; namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.PropertyEditors; @@ -47,54 +46,30 @@ public class PropertyEditorValueConverterTests } } - [TestCase("TRUE", null, true)] - [TestCase("True", null, true)] - [TestCase("true", null, true)] - [TestCase("1", null, true)] - [TestCase(1, null, true)] - [TestCase(true, null, true)] - [TestCase("FALSE", null, false)] - [TestCase("False", null, false)] - [TestCase("false", null, false)] - [TestCase("0", null, false)] - [TestCase(0, null, false)] - [TestCase(false, null, false)] - [TestCase("", null, false)] - [TestCase("blah", null, false)] - [TestCase(null, false, false)] - [TestCase(null, true, true)] - public void CanConvertTrueFalsePropertyEditor(object value, bool initialStateConfigurationValue, bool expected) + [TestCase("TRUE", true)] + [TestCase("True", true)] + [TestCase("true", true)] + [TestCase("1", true)] + [TestCase(1, true)] + [TestCase(true, true)] + [TestCase("FALSE", false)] + [TestCase("False", false)] + [TestCase("false", false)] + [TestCase("0", false)] + [TestCase(0, false)] + [TestCase(false, false)] + [TestCase("", false)] + [TestCase(null, false)] + [TestCase("blah", false)] + public void CanConvertYesNoPropertyEditor(object value, bool expected) { - var publishedDataType = CreatePublishedDataType(initialStateConfigurationValue); - - var publishedPropertyTypeMock = new Mock(); - publishedPropertyTypeMock - .SetupGet(p => p.DataType) - .Returns(publishedDataType); - var converter = new YesNoValueConverter(); - var intermediateResult = converter.ConvertSourceToIntermediate(null, publishedPropertyTypeMock.Object, value, false); - var result = converter.ConvertIntermediateToObject(null, publishedPropertyTypeMock.Object, PropertyCacheLevel.Element, intermediateResult, false); + var result = + converter.ConvertSourceToIntermediate(null, null, value, false); // does not use type for conversion Assert.AreEqual(expected, result); } - private static PublishedDataType CreatePublishedDataType(bool initialStateConfigurationValue) - { - var dataTypeConfiguration = new TrueFalseConfiguration - { - InitialState = initialStateConfigurationValue - }; - - var dateTypeMock = new Mock(); - dateTypeMock.SetupGet(x => x.Id).Returns(1000); - dateTypeMock.SetupGet(x => x.EditorAlias).Returns(global::Umbraco.Cms.Core.Constants.PropertyEditors.Aliases.Boolean); - dateTypeMock.SetupGet(x => x.EditorUiAlias).Returns("Umb.PropertyEditorUi.Toggle"); - dateTypeMock.SetupGet(x => x.ConfigurationObject).Returns(dataTypeConfiguration); - - return new PublishedDataType(dateTypeMock.Object.Id, dateTypeMock.Object.EditorAlias, dateTypeMock.Object.EditorUiAlias, new Lazy(() => dataTypeConfiguration)); - } - [TestCase("[\"apples\"]", new[] { "apples" })] [TestCase("[\"apples\",\"oranges\"]", new[] { "apples", "oranges" })] [TestCase("[\"apples\",\"oranges\",\"pears\"]", new[] { "apples", "oranges", "pears" })]