diff --git a/src/Umbraco.Core/PropertyEditors/PropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/PropertyEditor.cs index 4a6f80ea61..056ba13965 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyEditor.cs @@ -17,8 +17,6 @@ namespace Umbraco.Core.PropertyEditors [DebuggerDisplay("{" + nameof(DebuggerDisplay) + "(),nq}")] public class PropertyEditor : IParameterEditor { - private readonly PropertyEditorAttribute _attribute; - private ValueEditor _valueEditor; private ValueEditor _valueEditorAssigned; private ConfigurationEditor _configurationEditor; @@ -36,17 +34,22 @@ namespace Umbraco.Core.PropertyEditors Group = "common"; // assign properties based on the attribute, if it is found - _attribute = GetType().GetCustomAttribute(false); - if (_attribute == null) return; + Attribute = GetType().GetCustomAttribute(false); + if (Attribute == null) return; - Alias = _attribute.Alias; - Name = _attribute.Name; - IsParameterEditor = _attribute.IsMacroParameterEditor; - Icon = _attribute.Icon; - Group = _attribute.Group; - IsDeprecated = _attribute.IsDeprecated; + Alias = Attribute.Alias; + Name = Attribute.Name; + IsParameterEditor = Attribute.IsMacroParameterEditor; + Icon = Attribute.Icon; + Group = Attribute.Group; + IsDeprecated = Attribute.IsDeprecated; } + /// + /// Gets the editor attribute. + /// + protected ValueEditorAttribute Attribute { get; } + /// /// Gets a logger. /// @@ -126,22 +129,8 @@ namespace Umbraco.Core.PropertyEditors protected virtual ValueEditor CreateValueEditor() { // handle assigned editor - if (_valueEditorAssigned != null) - return _valueEditorAssigned; - - // create a new editor - var editor = new ValueEditor(); - - var view = _attribute?.View; - if (string.IsNullOrWhiteSpace(view)) - throw new InvalidOperationException("The editor does not specify a view."); - if (view.StartsWith("~/")) - view = IOHelper.ResolveUrl(view); - editor.View = view; - - editor.ValueType = _attribute.ValueType; - editor.HideLabel = _attribute.HideLabel; - return editor; + // or create a new editor + return _valueEditorAssigned ?? new ValueEditor(Attribute); } /// diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/ImageCropperValue.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/ImageCropperValue.cs index 360394af93..8efd98191d 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/ImageCropperValue.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/ImageCropperValue.cs @@ -47,7 +47,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters // fixme MOVE TO MODELS O : Crops.FirstOrDefault(x => x.Alias.InvariantEquals(alias)); } - // fixme was defined in web project, extension methods? + // fixme was defined in web project, extension methods? why internal? internal void AppendCropBaseUrl(StringBuilder url, ImageCropperCrop crop, bool preferFocalPoint) { if (preferFocalPoint && HasFocalPoint() @@ -140,6 +140,45 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters // fixme MOVE TO MODELS O public bool HasImage() => !string.IsNullOrWhiteSpace(Src); + /// + /// Applies a configuration. + /// + /// Ensures that all crops defined in the configuration exists in the value. + internal void ApplyConfiguration(ImageCropperEditorConfiguration configuration) + { + // merge the crop values - the alias + width + height comes from + // configuration, but each crop can store its own coordinates + + var configuredCrops = configuration.Crops; + var crops = Crops.ToList(); + + foreach (var configuredCrop in configuredCrops) + { + var crop = crops.FirstOrDefault(x => x.Alias == configuredCrop.Alias); + if (crop != null) + { + // found, apply the height & width + crop.Width = configuredCrop.Width; + crop.Height = configuredCrop.Height; + } + else + { + // not found, add + crops.Add(new ImageCropperCrop + { + Alias = configuredCrop.Alias, + Width = configuredCrop.Width, + Height = configuredCrop.Height + }); + } + } + + // assume we don't have to remove the crops in value, that + // are not part of configuration anymore? + + Crops = crops; + } + #region IEquatable /// diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs index 5fc7b807ee..036c3dd4d7 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs @@ -1,20 +1,12 @@ using System; using System.Globalization; -using System.Linq; using Newtonsoft.Json; using Umbraco.Core.Composing; using Umbraco.Core.Logging; -using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; -using Umbraco.Core.Services; namespace Umbraco.Core.PropertyEditors.ValueConverters { - // fixme - this is VERY fucked up - // see the SAME converter in the web project - // there is ABSOLUTELY no reason to split the converter - // no converters in WEB unless they absolutely need WEB, FFS - /// /// Represents a value converter for the image cropper value editor. /// @@ -33,54 +25,6 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType) => PropertyCacheLevel.Element; - private static void MergeConfiguration(ImageCropperValue value, PublishedDataType dataType) - { - var configuration = dataType.ConfigurationAs(); - MergeConfiguration(value, configuration); - } - - // fixme why internal - internal static void MergeConfiguration(ImageCropperValue value, IDataType dataType) - { - var configuration = dataType.ConfigurationAs(); - MergeConfiguration(value, configuration); - } - - private static void MergeConfiguration(ImageCropperValue value, ImageCropperEditorConfiguration configuration) - { - // merge the crop values - the alias + width + height comes from - // configuration, but each crop can store its own coordinates - - var configuredCrops = configuration.Crops; - var crops = value.Crops.ToList(); - - foreach (var configuredCrop in configuredCrops) - { - var crop = crops.FirstOrDefault(x => x.Alias == configuredCrop.Alias); - if (crop != null) - { - // found, apply the height & width - crop.Width = configuredCrop.Width; - crop.Height = configuredCrop.Height; - } - else - { - // not found, add - crops.Add(new ImageCropperValue.ImageCropperCrop - { - Alias = configuredCrop.Alias, - Width = configuredCrop.Width, - Height = configuredCrop.Height - }); - } - } - - // assume we don't have to remove the crops in value, that - // are not part of configuration anymore? - - value.Crops = crops.ToArray(); - } - /// public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview) { @@ -103,7 +47,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters value = new ImageCropperValue { Src = sourceString }; } - MergeConfiguration(value, propertyType.DataType); + value.ApplyConfiguration(propertyType.DataType.ConfigurationAs()); return value; } diff --git a/src/Umbraco.Core/PropertyEditors/ValueEditor.cs b/src/Umbraco.Core/PropertyEditors/ValueEditor.cs index c3f768f707..3ae14fa0ee 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueEditor.cs @@ -39,6 +39,23 @@ namespace Umbraco.Core.PropertyEditors Validators.AddRange(validators); } + /// + /// Initializes a new instance of the class. + /// + public ValueEditor(ValueEditorAttribute attribute) + : this() + { + if (attribute == null) return; + + var view = attribute.View; + if (string.IsNullOrWhiteSpace(view)) + throw new ArgumentException("The attribute does not specify a view.", nameof(attribute)); + + View = view; + ValueType = attribute.ValueType; + HideLabel = attribute.HideLabel; + } + private PreValueCollection _preVals; protected PreValueCollection PreValues { diff --git a/src/Umbraco.Core/PropertyEditors/PropertyEditorAttribute.cs b/src/Umbraco.Core/PropertyEditors/ValueEditorAttribute.cs similarity index 82% rename from src/Umbraco.Core/PropertyEditors/PropertyEditorAttribute.cs rename to src/Umbraco.Core/PropertyEditors/ValueEditorAttribute.cs index 4c2bd2b035..059aafa818 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyEditorAttribute.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueEditorAttribute.cs @@ -1,93 +1,93 @@ -using System; -using Umbraco.Core.Exceptions; - -namespace Umbraco.Core.PropertyEditors -{ - /// - /// Marks a class that represents a data editor. - /// - [AttributeUsage(AttributeTargets.Class)] - public sealed class PropertyEditorAttribute : DataEditorAttribute - { - /// - /// Initializes a new instance of the class. - /// - /// The unique identifier of the editor. - /// The friendly name of the editor. - public PropertyEditorAttribute(string alias, string name) - : this(alias, name, NullView) - { } - - /// - /// Initializes a new instance of the class. - /// - /// The unique identifier of the editor. - /// The friendly name of the editor. - /// The view to use to render the editor. - public PropertyEditorAttribute(string alias, string name, string view) - : base(alias, name, view) - { - // defaults - ValueType = ValueTypes.String; - Icon = Constants.Icons.PropertyEditor; - Group = "common"; - } - - /// - /// Initializes a new instance of the class. - /// - /// The unique identifier of the editor. - /// The friendly name of the editor. - /// The view to use to render the editor. - /// The type of the edited value. - /// The must be a valid value. - public PropertyEditorAttribute(string alias, string name, string view, string valueType) - : this(alias, name, view) - { - if (string.IsNullOrWhiteSpace(valueType)) throw new ArgumentNullOrEmptyException(nameof(valueType)); - if (!ValueTypes.IsValue(valueType)) throw new ArgumentOutOfRangeException(nameof(valueType), "Not a valid ValueTypes."); - ValueType = valueType; - } - - /// - /// Gets or sets the type of the edited value. - /// - /// Must be a valid value. - public string ValueType { get; set; } - - /// - /// Gets or sets a value indicating the editor type. - /// - public EditorType EditorType { get; set; } // fixme should be the attribute 1st ctor parameter? - - public bool IsPropertyValueEditor => (EditorType & EditorType.PropertyValue) != 0; - - /// - /// Gets or sets a value indicating whether the editor is a macro parameter editor. - /// - public bool IsMacroParameterEditor { get; set; } // => (EditorType & EditorType.MacroParameter) != 0; - - /// - /// If set to true, this property editor will not show up in the DataType's drop down list - /// if there is not already one of them chosen for a DataType - /// - public bool IsDeprecated { get; set; } // fixme should just kill in v8 - - /// - /// Gets or sets a value indicating whether the editor should be displayed without its label. - /// - public bool HideLabel { get; set; } - - /// - /// Gets or sets an optional icon. - /// - /// The icon can be used for example when presenting datatypes based upon the editor. - public string Icon { get; set; } - - /// - /// Gets or sets an optional group. - /// - /// The group can be used for example to group the editors by category. - public string Group { get; set; } - } -} +using System; +using Umbraco.Core.Exceptions; + +namespace Umbraco.Core.PropertyEditors +{ + /// + /// Marks a class that represents a value editor. + /// + [AttributeUsage(AttributeTargets.Class)] + public sealed class ValueEditorAttribute : DataEditorAttribute + { + /// + /// Initializes a new instance of the class. + /// + /// The unique identifier of the editor. + /// The friendly name of the editor. + public ValueEditorAttribute(string alias, string name) + : this(alias, name, NullView) + { } + + /// + /// Initializes a new instance of the class. + /// + /// The unique identifier of the editor. + /// The friendly name of the editor. + /// The view to use to render the editor. + public ValueEditorAttribute(string alias, string name, string view) + : base(alias, name, view) + { + // defaults + ValueType = ValueTypes.String; + Icon = Constants.Icons.PropertyEditor; + Group = "common"; + } + + /// + /// Initializes a new instance of the class. + /// + /// The unique identifier of the editor. + /// The friendly name of the editor. + /// The view to use to render the editor. + /// The type of the edited value. + /// The must be a valid value. + public ValueEditorAttribute(string alias, string name, string view, string valueType) + : this(alias, name, view) + { + if (string.IsNullOrWhiteSpace(valueType)) throw new ArgumentNullOrEmptyException(nameof(valueType)); + if (!ValueTypes.IsValue(valueType)) throw new ArgumentOutOfRangeException(nameof(valueType), "Not a valid ValueTypes."); + ValueType = valueType; + } + + /// + /// Gets or sets the type of the edited value. + /// + /// Must be a valid value. + public string ValueType { get; set; } + + /// + /// Gets or sets a value indicating the editor type. + /// + public EditorType EditorType { get; set; } // fixme should be the attribute 1st ctor parameter? + + public bool IsPropertyValueEditor => (EditorType & EditorType.PropertyValue) != 0; + + /// + /// Gets or sets a value indicating whether the editor is a macro parameter editor. + /// + public bool IsMacroParameterEditor { get; set; } // => (EditorType & EditorType.MacroParameter) != 0; + + /// + /// If set to true, this property editor will not show up in the DataType's drop down list + /// if there is not already one of them chosen for a DataType + /// + public bool IsDeprecated { get; set; } // fixme should just kill in v8 + + /// + /// Gets or sets a value indicating whether the editor should be displayed without its label. + /// + public bool HideLabel { get; set; } + + /// + /// Gets or sets an optional icon. + /// + /// The icon can be used for example when presenting datatypes based upon the editor. + public string Icon { get; set; } + + /// + /// Gets or sets an optional group. + /// + /// The group can be used for example to group the editors by category. + public string Group { get; set; } + } +} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 157d3e30ab..7fd733fab7 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -1200,7 +1200,7 @@ - + diff --git a/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs b/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs index ff6a940a7f..536786f597 100644 --- a/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs +++ b/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs @@ -29,7 +29,7 @@ namespace Umbraco.Tests.Models.Mapping Container.RegisterSingleton(f => Mock.Of()); } - [PropertyEditor("Test.Test", "Test", "~/Test.html")] + [ValueEditor("Test.Test", "Test", "~/Test.html")] public class TestPropertyEditor : PropertyEditor { /// diff --git a/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs b/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs index 542553e5e6..8d1a65f296 100644 --- a/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs @@ -61,9 +61,7 @@ namespace Umbraco.Web.Cache // fixme - not sure I like these? TagsValueConverter.ClearCaches(); - MediaPickerLegacyValueConverter.ClearCaches(); SliderValueConverter.ClearCaches(); - MediaPickerValueConverter.ClearCaches(); // notify _publishedSnapshotService.Notify(payloads); diff --git a/src/Umbraco.Web/Models/Mapping/DataTypeMapperProfile.cs b/src/Umbraco.Web/Models/Mapping/DataTypeMapperProfile.cs index 36ff7dd1dc..c1c886bac1 100644 --- a/src/Umbraco.Web/Models/Mapping/DataTypeMapperProfile.cs +++ b/src/Umbraco.Web/Models/Mapping/DataTypeMapperProfile.cs @@ -6,7 +6,6 @@ using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; -using Umbraco.Core.Services; using Umbraco.Web.Composing; using Umbraco.Web.Models.ContentEditing; @@ -17,11 +16,11 @@ namespace Umbraco.Web.Models.Mapping /// internal class DataTypeMapperProfile : Profile { - public DataTypeMapperProfile(IDataTypeService dataTypeService) + public DataTypeMapperProfile() { // create, capture, cache var availablePropertyEditorsResolver = new AvailablePropertyEditorsResolver(UmbracoConfig.For.UmbracoSettings().Content); - var preValueDisplayResolver = new DataTypeConfigurationFieldDisplayResolver(dataTypeService); + var preValueDisplayResolver = new DataTypeConfigurationFieldDisplayResolver(); var databaseTypeResolver = new DatabaseTypeResolver(); CreateMap(); diff --git a/src/Umbraco.Web/Models/PublishedContentBase.cs b/src/Umbraco.Web/Models/PublishedContentBase.cs index 6d805e9914..89a735688c 100644 --- a/src/Umbraco.Web/Models/PublishedContentBase.cs +++ b/src/Umbraco.Web/Models/PublishedContentBase.cs @@ -7,6 +7,7 @@ using Newtonsoft.Json.Linq; using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; +using Umbraco.Core.PropertyEditors.ValueConverters; namespace Umbraco.Web.Models { @@ -58,6 +59,7 @@ namespace Umbraco.Web.Models var propType = ContentType.GetPropertyType(Constants.Conventions.Media.File); + // fixme this is horrible we need url providers for media too //This is a hack - since we now have 2 properties that support a URL: upload and cropper, we need to detect this since we always // want to return the normal URL and the cropper stores data as json switch (propType.EditorAlias) @@ -68,21 +70,13 @@ namespace Umbraco.Web.Models case Constants.PropertyEditors.Aliases.ImageCropper: //get the url from the json format - var stronglyTyped = prop.GetValue() as ImageCropDataSet; + var stronglyTyped = prop.GetValue() as ImageCropperValue; if (stronglyTyped != null) { _url = stronglyTyped.Src; break; } - - var json = prop.GetValue() as JObject; - if (json != null) - { - _url = json.ToObject(new JsonSerializer { Culture = CultureInfo.InvariantCulture, FloatParseHandling = FloatParseHandling.Decimal }).Src; - break; - } - - _url = prop.GetValue().ToString(); + _url = prop.GetValue()?.ToString(); break; } break; diff --git a/src/Umbraco.Web/PropertyEditors/CheckBoxListPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/CheckBoxListPropertyEditor.cs index f8bf8760d0..e4624bfee6 100644 --- a/src/Umbraco.Web/PropertyEditors/CheckBoxListPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/CheckBoxListPropertyEditor.cs @@ -13,7 +13,7 @@ namespace Umbraco.Web.PropertyEditors /// as INT and we have logic in here to ensure it is formatted correctly including ensuring that the string value is published /// in cache and not the int ID. /// - [PropertyEditor(Constants.PropertyEditors.Aliases.CheckBoxList, "Checkbox list", "checkboxlist", Icon="icon-bulleted-list", Group="lists")] + [ValueEditor(Constants.PropertyEditors.Aliases.CheckBoxList, "Checkbox list", "checkboxlist", Icon="icon-bulleted-list", Group="lists")] public class CheckBoxListPropertyEditor : PropertyEditor { private readonly ILocalizedTextService _textService; @@ -21,31 +21,16 @@ namespace Umbraco.Web.PropertyEditors /// /// The constructor will setup the property editor based on the attribute if one is found /// - public CheckBoxListPropertyEditor(ILogger logger, ILocalizedTextService textService) : base(logger) + public CheckBoxListPropertyEditor(ILogger logger, ILocalizedTextService textService) + : base(logger) { _textService = textService; } - /// - /// Return a custom pre-value editor - /// - /// - /// - /// We are just going to re-use the ValueListPreValueEditor - /// - protected override ConfigurationEditor CreateConfigurationEditor() - { - return new ValueListConfigurationEditor(_textService, Logger); - } - - /// - /// We need to override the value editor so that we can ensure the string value is published in cache and not the integer ID value. - /// - /// - protected override ValueEditor CreateValueEditor() - { - return new PublishValuesMultipleValueEditor(false, base.CreateValueEditor()); - } + /// + protected override ConfigurationEditor CreateConfigurationEditor() => new ValueListConfigurationEditor(_textService); + /// + protected override ValueEditor CreateValueEditor() => new PublishValuesMultipleValueEditor(false, Attribute); } } diff --git a/src/Umbraco.Web/PropertyEditors/ColorListConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/ColorListConfigurationEditor.cs index c49aa48a1a..25fc6a7a2f 100644 --- a/src/Umbraco.Web/PropertyEditors/ColorListConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ColorListConfigurationEditor.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Text.RegularExpressions; using Newtonsoft.Json.Linq; using Umbraco.Core; -using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; @@ -12,8 +11,8 @@ namespace Umbraco.Web.PropertyEditors { internal class ColorListConfigurationEditor : ValueListConfigurationEditor { - public ColorListConfigurationEditor(ILocalizedTextService textService, ILogger logger) - : base(textService, logger) + public ColorListConfigurationEditor(ILocalizedTextService textService) + : base(textService) { var field = Fields.First(); @@ -27,13 +26,6 @@ namespace Umbraco.Web.PropertyEditors field.Validators.Add(new ColorListValidator()); } - public override object ToEditor(object defaultConfiguration, object configuration) - { - var dictionary = persistedPreVals.FormatAsDictionary(); - var arrayOfVals = dictionary.Select(item => item.Value).ToList(); - return new Dictionary { { "items", arrayOfVals.ToDictionary(x => x.Id, x => x.Value) } }; - } - internal class ColorListValidator : IValueValidator { public IEnumerable Validate(object value, string valueType, object dataTypeConfiguration) @@ -44,8 +36,7 @@ namespace Umbraco.Web.PropertyEditors for (var index = 0; index < json.Count; index++) { var i = json[index]; - var jItem = i as JObject; - if (jItem == null || jItem["value"] == null) continue; + if (!(i is JObject jItem) || jItem["value"] == null) continue; //NOTE: we will be removing empty values when persisting so no need to validate var asString = jItem["value"].ToString(); diff --git a/src/Umbraco.Web/PropertyEditors/ColorPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/ColorPickerPropertyEditor.cs index feea0d52e0..b4a9322802 100644 --- a/src/Umbraco.Web/PropertyEditors/ColorPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ColorPickerPropertyEditor.cs @@ -5,7 +5,7 @@ using Umbraco.Core.Services; namespace Umbraco.Web.PropertyEditors { - [PropertyEditor(Constants.PropertyEditors.Aliases.ColorPicker, "Color Picker", "colorpicker", Icon="icon-colorpicker", Group="Pickers")] + [ValueEditor(Constants.PropertyEditors.Aliases.ColorPicker, "Color Picker", "colorpicker", Icon="icon-colorpicker", Group="Pickers")] public class ColorPickerPropertyEditor : PropertyEditor { private readonly ILocalizedTextService _textService; @@ -13,22 +13,13 @@ namespace Umbraco.Web.PropertyEditors /// /// The constructor will setup the property editor based on the attribute if one is found /// - public ColorPickerPropertyEditor(ILogger logger, ILocalizedTextService textService) : base(logger) + public ColorPickerPropertyEditor(ILogger logger, ILocalizedTextService textService) + : base(logger) { _textService = textService; } - /// - /// Return a custom pre-value editor - /// - /// - /// - /// ColorListPreValueEditor uses the ValueListPreValueEditor with a custom view and controller. - /// - protected override ConfigurationEditor CreateConfigurationEditor() - { - return new ColorListConfigurationEditor(_textService, Logger); - } - + /// + protected override ConfigurationEditor CreateConfigurationEditor() => new ColorListConfigurationEditor(_textService); } } diff --git a/src/Umbraco.Web/PropertyEditors/ContentPicker2PropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/ContentPicker2PropertyEditor.cs index 0a1eda912a..47e670081f 100644 --- a/src/Umbraco.Web/PropertyEditors/ContentPicker2PropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ContentPicker2PropertyEditor.cs @@ -8,7 +8,7 @@ namespace Umbraco.Web.PropertyEditors /// /// Content property editor that stores UDI /// - [PropertyEditor(Constants.PropertyEditors.Aliases.ContentPicker2Alias, "Content Picker", "contentpicker", ValueTypes.String, IsMacroParameterEditor = true, Group = "Pickers")] + [ValueEditor(Constants.PropertyEditors.Aliases.ContentPicker2Alias, "Content Picker", "contentpicker", ValueTypes.String, IsMacroParameterEditor = true, Group = "Pickers")] public class ContentPicker2PropertyEditor : PropertyEditor { public ContentPicker2PropertyEditor(ILogger logger) diff --git a/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs index 2f51f768de..9600c96f92 100644 --- a/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Text.RegularExpressions; -using Newtonsoft.Json.Linq; using Umbraco.Core; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -10,7 +8,7 @@ using Umbraco.Core.Services; namespace Umbraco.Web.PropertyEditors { - [PropertyEditor(Constants.PropertyEditors.Aliases.Date, "Date", "datepicker", ValueTypes.Date, Icon="icon-calendar")] + [ValueEditor(Constants.PropertyEditors.Aliases.Date, "Date", "datepicker", ValueTypes.Date, Icon="icon-calendar")] public class DatePropertyEditor : PropertyEditor { public DatePropertyEditor(ILogger logger): base(logger) @@ -30,18 +28,20 @@ namespace Umbraco.Web.PropertyEditors set { _defaultPreVals = value; } } - protected override ValueEditor CreateValueEditor() - { - return new DatePropertyValueEditor(base.CreateValueEditor()); - } + /// + protected override ValueEditor CreateValueEditor() => new DatePropertyValueEditor(Attribute); + + /// + protected override ConfigurationEditor CreateConfigurationEditor() => new DateConfigurationEditor(); /// /// CUstom value editor so we can serialize with the correct date format (excluding time) /// and includes the date validator /// - internal class DatePropertyValueEditor : PropertyValueEditorWrapper + internal class DatePropertyValueEditor : ValueEditor { - public DatePropertyValueEditor(ValueEditor wrapped) : base(wrapped) + public DatePropertyValueEditor(ValueEditorAttribute attribute) + : base(attribute) { Validators.Add(new DateTimeValidator()); } @@ -58,10 +58,5 @@ namespace Umbraco.Web.PropertyEditors } } - - protected override ConfigurationEditor CreateConfigurationEditor() - { - return new DateConfigurationEditor(); - } } } diff --git a/src/Umbraco.Web/PropertyEditors/DateTimePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DateTimePropertyEditor.cs index 08cece156c..943f41ffb7 100644 --- a/src/Umbraco.Web/PropertyEditors/DateTimePropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DateTimePropertyEditor.cs @@ -9,7 +9,7 @@ using Umbraco.Core.Services; namespace Umbraco.Web.PropertyEditors { - [PropertyEditor(Constants.PropertyEditors.Aliases.DateTime, "Date/Time", "datepicker", ValueType = ValueTypes.DateTime, Icon="icon-time")] + [ValueEditor(Constants.PropertyEditors.Aliases.DateTime, "Date/Time", "datepicker", ValueType = ValueTypes.DateTime, Icon="icon-time")] public class DateTimePropertyEditor : PropertyEditor { public DateTimePropertyEditor(ILogger logger): base(logger) diff --git a/src/Umbraco.Web/PropertyEditors/DecimalPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DecimalPropertyEditor.cs index b06b1ccc08..9785bdcfc5 100644 --- a/src/Umbraco.Web/PropertyEditors/DecimalPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DecimalPropertyEditor.cs @@ -5,7 +5,7 @@ using Umbraco.Core.PropertyEditors.Validators; namespace Umbraco.Web.PropertyEditors { - [PropertyEditor(Constants.PropertyEditors.Aliases.Decimal, "Decimal", "decimal", ValueTypes.Decimal, IsMacroParameterEditor = true)] + [ValueEditor(Constants.PropertyEditors.Aliases.Decimal, "Decimal", "decimal", ValueTypes.Decimal, IsMacroParameterEditor = true)] public class DecimalPropertyEditor : PropertyEditor { /// diff --git a/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs index 9105ff0b0b..960e39ba9e 100644 --- a/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs @@ -16,24 +16,17 @@ namespace Umbraco.Web.PropertyEditors [ParameterEditor("propertyTypePickerMultiple", "Name", "textbox")] [ParameterEditor("contentTypeMultiple", "Name", "textbox")] [ParameterEditor("tabPickerMultiple", "Name", "textbox")] - [PropertyEditor(Constants.PropertyEditors.Aliases.DropDownListMultiple, "Dropdown list multiple", "dropdown", Group = "lists", Icon="icon-bulleted-list")] + [ValueEditor(Constants.PropertyEditors.Aliases.DropDownListMultiple, "Dropdown list multiple", "dropdown", Group = "lists", Icon="icon-bulleted-list")] public class DropDownMultiplePropertyEditor : DropDownMultipleWithKeysPropertyEditor { /// /// The constructor will setup the property editor based on the attribute if one is found /// - public DropDownMultiplePropertyEditor(ILogger logger, ILocalizedTextService textService) : base(logger, textService) - { - } - - protected override ValueEditor CreateValueEditor() - { - return new PublishValuesMultipleValueEditor(false, base.CreateValueEditor()); - } + public DropDownMultiplePropertyEditor(ILogger logger, ILocalizedTextService textService) + : base(logger, textService) + { } + /// + protected override ValueEditor CreateValueEditor() => new PublishValuesMultipleValueEditor(false, Attribute); } - - - - } diff --git a/src/Umbraco.Web/PropertyEditors/DropDownMultipleWithKeysPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownMultipleWithKeysPropertyEditor.cs index 0cef6d22ae..3d9b0ce1aa 100644 --- a/src/Umbraco.Web/PropertyEditors/DropDownMultipleWithKeysPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DropDownMultipleWithKeysPropertyEditor.cs @@ -14,7 +14,7 @@ namespace Umbraco.Web.PropertyEditors /// Due to backwards compatibility, this editor stores the value as a CSV string listing /// the ids of individual items. /// - [PropertyEditor(Constants.PropertyEditors.Aliases.DropdownlistMultiplePublishKeys, "Dropdown list multiple, publish keys", "dropdown", Group = "lists", Icon = "icon-bulleted-list")] + [ValueEditor(Constants.PropertyEditors.Aliases.DropdownlistMultiplePublishKeys, "Dropdown list multiple, publish keys", "dropdown", Group = "lists", Icon = "icon-bulleted-list")] public class DropDownMultipleWithKeysPropertyEditor : DropDownPropertyEditor { private readonly ILocalizedTextService _textService; @@ -29,15 +29,9 @@ namespace Umbraco.Web.PropertyEditors } /// - protected override ValueEditor CreateValueEditor() - { - return new PublishValuesMultipleValueEditor(true, base.CreateValueEditor()); - } + protected override ValueEditor CreateValueEditor() => new PublishValuesMultipleValueEditor(true, Attribute); /// - protected override ConfigurationEditor CreateConfigurationEditor() - { - return new DropDownMultipleConfigurationEditor(_textService, Logger); - } + protected override ConfigurationEditor CreateConfigurationEditor() => new DropDownMultipleConfigurationEditor(_textService); } } diff --git a/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs index 0f0b2bdc1e..bc46ff7913 100644 --- a/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs @@ -18,24 +18,20 @@ namespace Umbraco.Web.PropertyEditors /// as INT and we have logic in here to ensure it is formatted correctly including ensuring that the string value is published /// in cache and not the int ID. /// - [PropertyEditor(Constants.PropertyEditors.Aliases.DropDownList, "Dropdown list", "dropdown", ValueType = ValueTypes.String, Group = "lists", Icon = "icon-indent")] + [ValueEditor(Constants.PropertyEditors.Aliases.DropDownList, "Dropdown list", "dropdown", ValueType = ValueTypes.String, Group = "lists", Icon = "icon-indent")] public class DropDownPropertyEditor : DropDownWithKeysPropertyEditor { /// /// The constructor will setup the property editor based on the attribute if one is found /// - public DropDownPropertyEditor(ILogger logger, ILocalizedTextService textService) : base(logger, textService) - { - } + public DropDownPropertyEditor(ILogger logger, ILocalizedTextService textService) + : base(logger, textService) + { } /// /// We need to override the value editor so that we can ensure the string value is published in cache and not the integer ID value. /// /// - protected override ValueEditor CreateValueEditor() - { - return new PublishValueValueEditor(base.CreateValueEditor(), Logger); - } - + protected override ValueEditor CreateValueEditor() => new PublishValueValueEditor(Attribute, Logger); } } diff --git a/src/Umbraco.Web/PropertyEditors/DropDownWithKeysPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownWithKeysPropertyEditor.cs index 1599032f47..38a8f5a232 100644 --- a/src/Umbraco.Web/PropertyEditors/DropDownWithKeysPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DropDownWithKeysPropertyEditor.cs @@ -13,7 +13,7 @@ namespace Umbraco.Web.PropertyEditors /// as INT and we have logic in here to ensure it is formatted correctly including ensuring that the INT ID value is published /// in cache and not the string value. /// - [PropertyEditor(Constants.PropertyEditors.Aliases.DropdownlistPublishKeys, "Dropdown list, publishing keys", "dropdown", ValueType = ValueTypes.Integer, Group = "lists", Icon = "icon-indent")] + [ValueEditor(Constants.PropertyEditors.Aliases.DropdownlistPublishKeys, "Dropdown list, publishing keys", "dropdown", ValueType = ValueTypes.Integer, Group = "lists", Icon = "icon-indent")] public class DropDownWithKeysPropertyEditor : PropertyEditor { private readonly ILocalizedTextService _textService; @@ -21,7 +21,8 @@ namespace Umbraco.Web.PropertyEditors /// /// The constructor will setup the property editor based on the attribute if one is found /// - public DropDownWithKeysPropertyEditor(ILogger logger, ILocalizedTextService textService) : base(logger) + public DropDownWithKeysPropertyEditor(ILogger logger, ILocalizedTextService textService) + : base(logger) { _textService = textService; } @@ -30,9 +31,6 @@ namespace Umbraco.Web.PropertyEditors /// Return a custom pre-value editor /// /// - protected override ConfigurationEditor CreateConfigurationEditor() - { - return new ValueListConfigurationEditor(_textService, Logger); - } + protected override ConfigurationEditor CreateConfigurationEditor() => new ValueListConfigurationEditor(_textService); } } diff --git a/src/Umbraco.Web/PropertyEditors/EmailAddressPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/EmailAddressPropertyEditor.cs index ff4f190d00..ac379ebf26 100644 --- a/src/Umbraco.Web/PropertyEditors/EmailAddressPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/EmailAddressPropertyEditor.cs @@ -5,7 +5,7 @@ using Umbraco.Core.PropertyEditors.Validators; namespace Umbraco.Web.PropertyEditors { - [PropertyEditor(Constants.PropertyEditors.Aliases.EmailAddress, "Email address", "email", Icon="icon-message")] + [ValueEditor(Constants.PropertyEditors.Aliases.EmailAddress, "Email address", "email", Icon="icon-message")] public class EmailAddressPropertyEditor : PropertyEditor { /// diff --git a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs index 42b660a2cc..58c3281b4f 100644 --- a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs @@ -4,7 +4,6 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using Newtonsoft.Json.Linq; using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -13,17 +12,15 @@ using Umbraco.Core.Services; namespace Umbraco.Web.PropertyEditors { - [PropertyEditor(Constants.PropertyEditors.Aliases.UploadField, "File upload", "fileupload", Icon = "icon-download-alt", Group = "media")] + [ValueEditor(Constants.PropertyEditors.Aliases.UploadField, "File upload", "fileupload", Icon = "icon-download-alt", Group = "media")] public class FileUploadPropertyEditor : PropertyEditor { private readonly MediaFileSystem _mediaFileSystem; private readonly ILocalizedTextService _textService; - public FileUploadPropertyEditor(ILogger logger, MediaFileSystem mediaFileSystem, IContentSection contentSettings, ILocalizedTextService textService) + public FileUploadPropertyEditor(ILogger logger, MediaFileSystem mediaFileSystem,ILocalizedTextService textService) : base(logger) { - if (contentSettings == null) throw new ArgumentNullException(nameof(contentSettings)); // fixme wtf? - _mediaFileSystem = mediaFileSystem ?? throw new ArgumentNullException(nameof(mediaFileSystem)); _textService = textService ?? throw new ArgumentNullException(nameof(textService)); } @@ -34,19 +31,16 @@ namespace Umbraco.Web.PropertyEditors /// The corresponding property value editor. protected override ValueEditor CreateValueEditor() { - var baseEditor = base.CreateValueEditor(); - baseEditor.Validators.Add(new UploadFileTypeValidator()); - return new FileUploadPropertyValueEditor(baseEditor, _mediaFileSystem); + var editor = new FileUploadPropertyValueEditor(Attribute, _mediaFileSystem); + editor.Validators.Add(new UploadFileTypeValidator()); + return editor; } /// /// Creates the corresponding preValue editor. /// /// The corresponding preValue editor. - protected override ConfigurationEditor CreateConfigurationEditor() - { - return new FileUploadConfigurationEditor(_textService, Logger); - } + protected override ConfigurationEditor CreateConfigurationEditor() => new FileUploadConfigurationEditor(_textService); /// /// Gets a value indicating whether a property is an upload field. @@ -173,8 +167,8 @@ namespace Umbraco.Web.PropertyEditors /// internal class FileUploadConfigurationEditor : ValueListConfigurationEditor { - public FileUploadConfigurationEditor(ILocalizedTextService textService, ILogger logger) - : base(textService, logger) + public FileUploadConfigurationEditor(ILocalizedTextService textService) + : base(textService) { var field = Fields.First(); field.Description = "Enter a max width/height for each thumbnail"; @@ -183,18 +177,13 @@ namespace Umbraco.Web.PropertyEditors field.Validators.Add(new ThumbnailListValidator()); } - /// - /// Format the persisted value to work with our multi-val editor. - /// - /// - /// - /// - public override IDictionary ConvertDbToEditor(IDictionary defaultPreVals, PreValueCollection persistedPreVals) + /// + public override Dictionary ToEditor(ValueListConfiguration defaultConfiguration, ValueListConfiguration configuration) { var result = new List(); //the pre-values just take up one field with a semi-colon delimiter so we'll just parse - var dictionary = persistedPreVals.FormatAsDictionary(); + var dictionary = configuration.FormatAsDictionary(); if (dictionary.Any()) { //there should only be one val @@ -215,11 +204,11 @@ namespace Umbraco.Web.PropertyEditors /// Take the posted values and convert them to a semi-colon separated list so that its backwards compatible /// /// - /// + /// /// - public override IDictionary ConvertEditorToDb(IDictionary editorValue, PreValueCollection currentValue) + public override ValueListConfiguration FromEditor(Dictionary editorValue, ValueListConfiguration configuration) { - var result = base.ConvertEditorToDb(editorValue, currentValue); + var result = base.ConvertEditorToDb(editorValue, configuration); //this should just be a dictionary of values, we want to re-format this so that it is just one value in the dictionary that is // semi-colon delimited diff --git a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyValueEditor.cs b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyValueEditor.cs index 23a6b4a185..66f89c1e4e 100644 --- a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyValueEditor.cs @@ -12,12 +12,12 @@ namespace Umbraco.Web.PropertyEditors /// /// The value editor for the file upload property editor. /// - internal class FileUploadPropertyValueEditor : PropertyValueEditorWrapper + internal class FileUploadPropertyValueEditor : ValueEditor { private readonly MediaFileSystem _mediaFileSystem; - public FileUploadPropertyValueEditor(ValueEditor wrapped, MediaFileSystem mediaFileSystem) - : base(wrapped) + public FileUploadPropertyValueEditor(ValueEditorAttribute attribute, MediaFileSystem mediaFileSystem) + : base(attribute) { _mediaFileSystem = mediaFileSystem ?? throw new ArgumentNullException(nameof(mediaFileSystem)); } diff --git a/src/Umbraco.Web/PropertyEditors/FolderBrowserPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/FolderBrowserPropertyEditor.cs index 8cb0875f43..5742271f37 100644 --- a/src/Umbraco.Web/PropertyEditors/FolderBrowserPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/FolderBrowserPropertyEditor.cs @@ -6,7 +6,7 @@ using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { [Obsolete("This is no longer used by default, use the ListViewPropertyEditor instead")] - [PropertyEditor(Constants.PropertyEditors.Aliases.FolderBrowser, "(Obsolete) Folder Browser", "folderbrowser", HideLabel=true, Icon="icon-folder", Group="media", IsDeprecated = true)] + [ValueEditor(Constants.PropertyEditors.Aliases.FolderBrowser, "(Obsolete) Folder Browser", "folderbrowser", HideLabel=true, Icon="icon-folder", Group="media", IsDeprecated = true)] public class FolderBrowserPropertyEditor : PropertyEditor { /// diff --git a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs index ac9efefe81..7e775d3473 100644 --- a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs @@ -15,7 +15,7 @@ namespace Umbraco.Web.PropertyEditors { using Examine = global::Examine; - [PropertyEditor(Constants.PropertyEditors.Aliases.Grid, "Grid layout", "grid", HideLabel = true, IsMacroParameterEditor = false, ValueType = ValueTypes.Json, Group="rich content", Icon="icon-layout")] + [ValueEditor(Constants.PropertyEditors.Aliases.Grid, "Grid layout", "grid", HideLabel = true, IsMacroParameterEditor = false, ValueType = ValueTypes.Json, Group="rich content", Icon="icon-layout")] public class GridPropertyEditor : PropertyEditor { public GridPropertyEditor(ILogger logger) @@ -109,24 +109,15 @@ namespace Umbraco.Web.PropertyEditors /// Overridden to ensure that the value is validated /// /// - protected override ValueEditor CreateValueEditor() - { - var baseEditor = base.CreateValueEditor(); - return new GridPropertyValueEditor(baseEditor); - } + protected override ValueEditor CreateValueEditor() => new GridPropertyValueEditor(Attribute); - protected override ConfigurationEditor CreateConfigurationEditor() - { - return new GridConfigurationEditor(); - } + protected override ConfigurationEditor CreateConfigurationEditor() => new GridConfigurationEditor(); - internal class GridPropertyValueEditor : PropertyValueEditorWrapper + internal class GridPropertyValueEditor : ValueEditor { - public GridPropertyValueEditor(ValueEditor wrapped) - : base(wrapped) - { - } - + public GridPropertyValueEditor(ValueEditorAttribute attribute) + : base(attribute) + { } } } } diff --git a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs index 2d59325067..3f3b6f6e6f 100644 --- a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs @@ -14,7 +14,7 @@ using Umbraco.Core.Services; namespace Umbraco.Web.PropertyEditors { - [PropertyEditor(Constants.PropertyEditors.Aliases.ImageCropper, "Image Cropper", "imagecropper", ValueType = ValueTypes.Json, HideLabel = false, Group="media", Icon="icon-crop")] + [ValueEditor(Constants.PropertyEditors.Aliases.ImageCropper, "Image Cropper", "imagecropper", ValueType = ValueTypes.Json, HideLabel = false, Group="media", Icon="icon-crop")] public class ImageCropperPropertyEditor : PropertyEditor { private readonly MediaFileSystem _mediaFileSystem; diff --git a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs index a36a92249f..53c55c31ed 100644 --- a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs @@ -16,13 +16,13 @@ namespace Umbraco.Web.PropertyEditors /// /// The value editor for the image cropper property editor. /// - internal class ImageCropperPropertyValueEditor : PropertyValueEditorWrapper + internal class ImageCropperPropertyValueEditor : ValueEditor // fixme core vs web? { private readonly ILogger _logger; private readonly MediaFileSystem _mediaFileSystem; - public ImageCropperPropertyValueEditor(ValueEditor wrapped, ILogger logger, MediaFileSystem mediaFileSystem) - : base(wrapped) + public ImageCropperPropertyValueEditor(ValueEditorAttribute attribute, ILogger logger, MediaFileSystem mediaFileSystem) + : base(attribute) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _mediaFileSystem = mediaFileSystem ?? throw new ArgumentNullException(nameof(mediaFileSystem)); @@ -46,8 +46,8 @@ namespace Umbraco.Web.PropertyEditors } var dataType = dataTypeService.GetDataType(propertyType.DataTypeId); - // fixme nullref? - ImageCropperValueConverter.MergeConfiguration(value, dataType); + if (dataType?.Configuration != null) + value.ApplyConfiguration(dataType.ConfigurationAs()); return value; } @@ -161,16 +161,19 @@ namespace Umbraco.Web.PropertyEditors if (value == null || string.IsNullOrEmpty(value.ToString())) return null; - // if we dont have a json structure, we will get it from the property type - var val = value.ToString(); - if (val.DetectIsJson()) - return val; + // fixme - no idea of what we should do here, and ConvertDbToString should die anyways + throw new NotImplementedException(); - // more magic here ;-( - var config = dataTypeService.GetPreValuesByDataTypeId(propertyType.DataTypeId).FirstOrDefault(); - var crops = string.IsNullOrEmpty(config) ? "[]" : config; - var newVal = "{src: '" + val + "', crops: " + crops + "}"; - return newVal; + //// if we dont have a json structure, we will get it from the property type + //var val = value.ToString(); + //if (val.DetectIsJson()) + // return val; + + //// more magic here ;-( + //var config = dataTypeService.GetPreValuesByDataTypeId(propertyType.DataTypeId).FirstOrDefault(); + //var crops = string.IsNullOrEmpty(config) ? "[]" : config; + //var newVal = "{src: '" + val + "', crops: " + crops + "}"; + //return newVal; } } } diff --git a/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs index 4170033eab..b2718912e3 100644 --- a/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs @@ -5,7 +5,7 @@ using Umbraco.Core.PropertyEditors.Validators; namespace Umbraco.Web.PropertyEditors { - [PropertyEditor(Constants.PropertyEditors.Aliases.Integer, "Numeric", "integer", IsMacroParameterEditor = true, ValueType = ValueTypes.Integer)] + [ValueEditor(Constants.PropertyEditors.Aliases.Integer, "Numeric", "integer", IsMacroParameterEditor = true, ValueType = ValueTypes.Integer)] public class IntegerPropertyEditor : PropertyEditor { public IntegerPropertyEditor(ILogger logger) diff --git a/src/Umbraco.Web/PropertyEditors/LabelPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/LabelPropertyEditor.cs index 4fd5276fdc..632afbcff9 100644 --- a/src/Umbraco.Web/PropertyEditors/LabelPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/LabelPropertyEditor.cs @@ -7,34 +7,27 @@ namespace Umbraco.Web.PropertyEditors /// /// Represents a property editor for label properties. /// - [PropertyEditor(Constants.PropertyEditors.Aliases.NoEdit, "Label", "readonlyvalue", Icon = "icon-readonly")] + [ValueEditor(Constants.PropertyEditors.Aliases.NoEdit, "Label", "readonlyvalue", Icon = "icon-readonly")] public class LabelPropertyEditor : PropertyEditor { /// /// Initializes a new instance of the class. /// - /// public LabelPropertyEditor(ILogger logger) : base(logger) { } /// - protected override ValueEditor CreateValueEditor() - { - return new LabelPropertyValueEditor(base.CreateValueEditor()); - } + protected override ValueEditor CreateValueEditor() => new LabelPropertyValueEditor(Attribute); /// - protected override ConfigurationEditor CreateConfigurationEditor() - { - return new LabelConfigurationEditor(); - } + protected override ConfigurationEditor CreateConfigurationEditor() => new LabelConfigurationEditor(); // provides the property value editor - internal class LabelPropertyValueEditor : PropertyValueEditorWrapper + internal class LabelPropertyValueEditor : ValueEditor { - public LabelPropertyValueEditor(ValueEditor wrapped) - : base(wrapped) + public LabelPropertyValueEditor(ValueEditorAttribute attribute) + : base(attribute) { } /// diff --git a/src/Umbraco.Web/PropertyEditors/ListViewPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/ListViewPropertyEditor.cs index 01819a25f5..39b1969dd6 100644 --- a/src/Umbraco.Web/PropertyEditors/ListViewPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ListViewPropertyEditor.cs @@ -8,7 +8,7 @@ namespace Umbraco.Web.PropertyEditors /// /// Represents a list-view editor. /// - [PropertyEditor(Constants.PropertyEditors.Aliases.ListView, "List view", "listview", HideLabel = true, Group = "lists", Icon = "icon-item-arrangement")] + [ValueEditor(Constants.PropertyEditors.Aliases.ListView, "List view", "listview", HideLabel = true, Group = "lists", Icon = "icon-item-arrangement")] public class ListViewPropertyEditor : PropertyEditor { /// diff --git a/src/Umbraco.Web/PropertyEditors/MacroContainerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MacroContainerPropertyEditor.cs index 747e1ae86e..679f8f86c7 100644 --- a/src/Umbraco.Web/PropertyEditors/MacroContainerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MacroContainerPropertyEditor.cs @@ -4,7 +4,7 @@ using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { - [PropertyEditor(Constants.PropertyEditors.Aliases.MacroContainer, "(Obsolete) Macro Picker", "macrocontainer", ValueType = ValueTypes.Text, Group="rich content", Icon="icon-settings-alt", IsDeprecated = true)] + [ValueEditor(Constants.PropertyEditors.Aliases.MacroContainer, "(Obsolete) Macro Picker", "macrocontainer", ValueType = ValueTypes.Text, Group="rich content", Icon="icon-settings-alt", IsDeprecated = true)] public class MacroContainerPropertyEditor : PropertyEditor { public MacroContainerPropertyEditor(ILogger logger) diff --git a/src/Umbraco.Web/PropertyEditors/MarkdownPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MarkdownPropertyEditor.cs index 7d1537447b..fa36a15f04 100644 --- a/src/Umbraco.Web/PropertyEditors/MarkdownPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MarkdownPropertyEditor.cs @@ -7,7 +7,7 @@ namespace Umbraco.Web.PropertyEditors /// /// Represents a markdown editor. /// - [PropertyEditor(Constants.PropertyEditors.Aliases.MarkdownEditor, "Markdown editor", "markdowneditor", ValueType = ValueTypes.Text, Icon="icon-code", Group="rich content")] + [ValueEditor(Constants.PropertyEditors.Aliases.MarkdownEditor, "Markdown editor", "markdowneditor", ValueType = ValueTypes.Text, Icon="icon-code", Group="rich content")] public class MarkdownPropertyEditor : PropertyEditor { /// diff --git a/src/Umbraco.Web/PropertyEditors/MediaPicker2PropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MediaPicker2PropertyEditor.cs index 541a09068d..b2b2cd2965 100644 --- a/src/Umbraco.Web/PropertyEditors/MediaPicker2PropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MediaPicker2PropertyEditor.cs @@ -8,7 +8,7 @@ namespace Umbraco.Web.PropertyEditors /// /// Media picker property editors that stores UDI /// - [PropertyEditor(Constants.PropertyEditors.Aliases.MediaPicker2, "Media Picker", "mediapicker", ValueTypes.Text, IsMacroParameterEditor = true, Group = "media", Icon = "icon-picture")] + [ValueEditor(Constants.PropertyEditors.Aliases.MediaPicker2, "Media Picker", "mediapicker", ValueTypes.Text, IsMacroParameterEditor = true, Group = "media", Icon = "icon-picture")] public class MediaPicker2PropertyEditor : PropertyEditor { public MediaPicker2PropertyEditor(ILogger logger) diff --git a/src/Umbraco.Web/PropertyEditors/MemberGroupPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MemberGroupPickerPropertyEditor.cs index 1bcf96b4bb..11b26c678d 100644 --- a/src/Umbraco.Web/PropertyEditors/MemberGroupPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MemberGroupPickerPropertyEditor.cs @@ -9,7 +9,7 @@ using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { - [PropertyEditor(Constants.PropertyEditors.Aliases.MemberGroupPicker, "Member Group Picker", "membergrouppicker", Group="People", Icon="icon-users")] + [ValueEditor(Constants.PropertyEditors.Aliases.MemberGroupPicker, "Member Group Picker", "membergrouppicker", Group="People", Icon="icon-users")] public class MemberGroupPickerPropertyEditor : PropertyEditor { /// diff --git a/src/Umbraco.Web/PropertyEditors/MemberPicker2PropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MemberPicker2PropertyEditor.cs index bf4deba458..e70ee1fae5 100644 --- a/src/Umbraco.Web/PropertyEditors/MemberPicker2PropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MemberPicker2PropertyEditor.cs @@ -5,7 +5,7 @@ using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { - [PropertyEditor(Constants.PropertyEditors.Aliases.MemberPicker2, "Member Picker", "memberpicker", ValueTypes.String, Group = "People", Icon = "icon-user")] + [ValueEditor(Constants.PropertyEditors.Aliases.MemberPicker2, "Member Picker", "memberpicker", ValueTypes.String, Group = "People", Icon = "icon-user")] public class MemberPicker2PropertyEditor : PropertyEditor { public MemberPicker2PropertyEditor(ILogger logger) diff --git a/src/Umbraco.Web/PropertyEditors/MultiNodeTreePicker2PropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MultiNodeTreePicker2PropertyEditor.cs index 411f42d80b..07b498349e 100644 --- a/src/Umbraco.Web/PropertyEditors/MultiNodeTreePicker2PropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultiNodeTreePicker2PropertyEditor.cs @@ -5,7 +5,7 @@ using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { - [PropertyEditor(Constants.PropertyEditors.Aliases.MultiNodeTreePicker2, "Multinode Treepicker", "contentpicker", ValueTypes.Text, Group = "pickers", Icon = "icon-page-add")] + [ValueEditor(Constants.PropertyEditors.Aliases.MultiNodeTreePicker2, "Multinode Treepicker", "contentpicker", ValueTypes.Text, Group = "pickers", Icon = "icon-page-add")] public class MultiNodeTreePicker2PropertyEditor : PropertyEditor { public MultiNodeTreePicker2PropertyEditor(ILogger logger) diff --git a/src/Umbraco.Web/PropertyEditors/MultipleTestStringConfiguration.cs b/src/Umbraco.Web/PropertyEditors/MultipleTestStringConfiguration.cs new file mode 100644 index 0000000000..028bc9c13d --- /dev/null +++ b/src/Umbraco.Web/PropertyEditors/MultipleTestStringConfiguration.cs @@ -0,0 +1,14 @@ +namespace Umbraco.Web.PropertyEditors +{ + /// + /// Represents the configuration for a multiple testring value editor. + /// + public class MultipleTestStringConfiguration + { + // fields are configured in the editor + + public int Minimum { get; set; } + + public int Maximum {get; set; } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/PropertyEditors/MultipleTextStringConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/MultipleTextStringConfigurationEditor.cs index fdf41f29bc..3c3741abe2 100644 --- a/src/Umbraco.Web/PropertyEditors/MultipleTextStringConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultipleTextStringConfigurationEditor.cs @@ -1,33 +1,24 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; +using System.Collections.Generic; using Umbraco.Core; -using Umbraco.Core.Logging; -using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Core.PropertyEditors.Validators; namespace Umbraco.Web.PropertyEditors { /// - /// A custom pre-value editor class to deal with the legacy way that the pre-value data is stored. + /// Represents the configuration editor for a multiple testring value editor. /// - internal class MultipleTextStringConfigurationEditor : ConfigurationEditor + internal class MultipleTextStringConfigurationEditor : ConfigurationEditor { - private readonly ILogger _logger; - - public MultipleTextStringConfigurationEditor(ILogger logger) + public MultipleTextStringConfigurationEditor() { - _logger = logger; - Fields.Add(new ConfigurationField(new IntegerValidator()) { Description = "Enter the minimum amount of text boxes to be displayed", Key = "min", View = "requiredfield", - Name = "Minimum" + Name = "Minimum", + PropertyName = nameof(MultipleTestStringConfiguration.Minimum) }); Fields.Add(new ConfigurationField(new IntegerValidator()) @@ -35,62 +26,35 @@ namespace Umbraco.Web.PropertyEditors Description = "Enter the maximum amount of text boxes to be displayed, enter 0 for unlimited", Key = "max", View = "requiredfield", - Name = "Maximum" + Name = "Maximum", + PropertyName = nameof(MultipleTestStringConfiguration.Maximum) }); } - /// - /// Need to change how we persist the values so they are compatible with the legacy way we store values - /// - /// - /// - /// - public override IDictionary ConvertEditorToDb(IDictionary editorValue, PreValueCollection currentValue) + /// + public override MultipleTestStringConfiguration FromEditor(Dictionary editorValue, MultipleTestStringConfiguration configuration) { + // fixme this isn't pretty //the values from the editor will be min/max fieds and we need to format to json in one field + // is the editor sending strings or ints or?! var min = (editorValue.ContainsKey("min") ? editorValue["min"].ToString() : "0").TryConvertTo(); var max = (editorValue.ContainsKey("max") ? editorValue["max"].ToString() : "0").TryConvertTo(); - var json = JObject.FromObject(new {Minimum = min.Success ? min.Result : 0, Maximum = max.Success ? max.Result : 0}); - - return new Dictionary { { "0", new PreValue(json.ToString(Formatting.None)) } }; + return new MultipleTestStringConfiguration + { + Minimum = min ? min.Result : 0, + Maximum = max ? max.Result : 0 + }; } - /// - /// Need to deal with the legacy way of storing pre-values and turn them into nice values for the editor - /// - /// - /// - /// - public override IDictionary ConvertDbToEditor(IDictionary defaultPreVals, PreValueCollection persistedPreVals) + /// + public override Dictionary ToEditor(MultipleTestStringConfiguration defaultConfiguration, MultipleTestStringConfiguration configuration) { - var preVals = persistedPreVals.FormatAsDictionary(); - var stringVal = preVals.Any() ? preVals.First().Value.Value : ""; - var returnVal = new Dictionary { { "min", 0 }, { "max", 0 } }; - if (stringVal.IsNullOrWhiteSpace() == false) + return new Dictionary { - try - { - var json = JsonConvert.DeserializeObject(stringVal); - if (json["Minimum"] != null) - { - //by default pre-values are sent out with an id/value pair - returnVal["min"] = json["Minimum"].Value(); - } - if (json["Maximum"] != null) - { - returnVal["max"] = json["Maximum"].Value(); - } - } - catch (Exception e) - { - // this shouldn't happen unless there's already a bad formatted pre-value - _logger.Warn(e, "Could not deserialize value to json " + stringVal); - return returnVal; - } - } - - return returnVal; + { "min", configuration.Minimum }, + { "max", configuration.Maximum } + }; } } } \ No newline at end of file diff --git a/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs index ed20ee9d53..6b2b935941 100644 --- a/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs @@ -11,7 +11,7 @@ using Umbraco.Core.Services; namespace Umbraco.Web.PropertyEditors { - [PropertyEditor(Constants.PropertyEditors.Aliases.MultipleTextstring, "Repeatable textstrings", "multipletextbox", ValueType = ValueTypes.Text, Icon="icon-ordered-list", Group="lists")] + [ValueEditor(Constants.PropertyEditors.Aliases.MultipleTextstring, "Repeatable textstrings", "multipletextbox", ValueType = ValueTypes.Text, Icon="icon-ordered-list", Group="lists")] public class MultipleTextStringPropertyEditor : PropertyEditor { /// @@ -20,24 +20,18 @@ namespace Umbraco.Web.PropertyEditors public MultipleTextStringPropertyEditor(ILogger logger) : base(logger) { } - protected override ValueEditor CreateValueEditor() - { - return new MultipleTextStringPropertyValueEditor(base.CreateValueEditor()); - } + protected override ValueEditor CreateValueEditor() => new MultipleTextStringPropertyValueEditor(Attribute); - protected override ConfigurationEditor CreateConfigurationEditor() - { - return new MultipleTextStringConfigurationEditor(Logger); - } + protected override ConfigurationEditor CreateConfigurationEditor() => new MultipleTextStringConfigurationEditor(); /// /// Custom value editor so we can format the value for the editor and the database /// - internal class MultipleTextStringPropertyValueEditor : PropertyValueEditorWrapper + internal class MultipleTextStringPropertyValueEditor : ValueEditor { - public MultipleTextStringPropertyValueEditor(ValueEditor wrapped) : base(wrapped) - { - } + public MultipleTextStringPropertyValueEditor(ValueEditorAttribute attribute) + : base(attribute) + { } /// /// The value passed in from the editor will be an array of simple objects so we'll need to parse them to get the string diff --git a/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs index a41930e6aa..3e5b25106d 100644 --- a/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs @@ -15,7 +15,7 @@ using Umbraco.Core.Services; namespace Umbraco.Web.PropertyEditors { - [PropertyEditor(Constants.PropertyEditors.Aliases.NestedContent, "Nested Content", "nestedcontent", ValueType = "JSON", Group = "lists", Icon = "icon-thumbnail-list")] + [ValueEditor(Constants.PropertyEditors.Aliases.NestedContent, "Nested Content", "nestedcontent", ValueType = "JSON", Group = "lists", Icon = "icon-thumbnail-list")] public class NestedContentPropertyEditor : PropertyEditor { private readonly Lazy _propertyEditors; @@ -110,17 +110,14 @@ namespace Umbraco.Web.PropertyEditors #region Value Editor - protected override ValueEditor CreateValueEditor() - { - return new NestedContentPropertyValueEditor(base.CreateValueEditor(), PropertyEditors); - } + protected override ValueEditor CreateValueEditor() => new NestedContentPropertyValueEditor(Attribute, PropertyEditors); - internal class NestedContentPropertyValueEditor : PropertyValueEditorWrapper + internal class NestedContentPropertyValueEditor : ValueEditor { private readonly PropertyEditorCollection _propertyEditors; - public NestedContentPropertyValueEditor(ValueEditor wrapped, PropertyEditorCollection propertyEditors) - : base(wrapped) + public NestedContentPropertyValueEditor(ValueEditorAttribute attribute, PropertyEditorCollection propertyEditors) + : base(attribute) { _propertyEditors = propertyEditors; Validators.Add(new NestedContentValidator(propertyEditors)); diff --git a/src/Umbraco.Web/PropertyEditors/PropertyValueEditorWrapper.cs b/src/Umbraco.Web/PropertyEditors/PropertyValueEditorWrapper.cs deleted file mode 100644 index 0e62bfc1e6..0000000000 --- a/src/Umbraco.Web/PropertyEditors/PropertyValueEditorWrapper.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Umbraco.Core.PropertyEditors; - -namespace Umbraco.Web.PropertyEditors -{ - /// - /// Useful when returning a custom value editor when your property editor is attributed, it ensures the attribute - /// values are copied across to your custom value editor. - /// -#error wtf - public class PropertyValueEditorWrapper : ValueEditor // fixme but WHAT is this exactly?! - { - public PropertyValueEditorWrapper(ValueEditor wrapped) - { - this.HideLabel = wrapped.HideLabel; - this.View = wrapped.View; - this.ValueType = wrapped.ValueType; - foreach (var v in wrapped.Validators) - { - Validators.Add(v); - } - } - } -} diff --git a/src/Umbraco.Web/PropertyEditors/PublishValueValueEditor.cs b/src/Umbraco.Web/PropertyEditors/PublishValueValueEditor.cs index a396dbd480..e734ed5eb3 100644 --- a/src/Umbraco.Web/PropertyEditors/PublishValueValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/PublishValueValueEditor.cs @@ -16,20 +16,20 @@ namespace Umbraco.Web.PropertyEditors /// This is required for legacy/backwards compatibility, otherwise we'd just store the string version and cache the string version without /// needing additional lookups. /// - internal class PublishValueValueEditor : PropertyValueEditorWrapper + internal class PublishValueValueEditor : ValueEditor { private readonly IDataTypeService _dataTypeService; private readonly ILogger _logger; - internal PublishValueValueEditor(IDataTypeService dataTypeService, ValueEditor wrapped, ILogger logger) - : base(wrapped) + internal PublishValueValueEditor(IDataTypeService dataTypeService, ValueEditorAttribute attribute, ILogger logger) + : base(attribute) { _dataTypeService = dataTypeService; _logger = logger; } - public PublishValueValueEditor(ValueEditor wrapped, ILogger logger) - : this(Current.Services.DataTypeService, wrapped, logger) + public PublishValueValueEditor(ValueEditorAttribute attribute, ILogger logger) + : this(Current.Services.DataTypeService, attribute, logger) { } diff --git a/src/Umbraco.Web/PropertyEditors/PublishValuesMultipleValueEditor.cs b/src/Umbraco.Web/PropertyEditors/PublishValuesMultipleValueEditor.cs index f9bb1b0059..91687c17de 100644 --- a/src/Umbraco.Web/PropertyEditors/PublishValuesMultipleValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/PublishValuesMultipleValueEditor.cs @@ -21,14 +21,14 @@ namespace Umbraco.Web.PropertyEditors { private readonly bool _publishIds; - internal PublishValuesMultipleValueEditor(bool publishIds, IDataTypeService dataTypeService, ILogger logger, ValueEditor wrapped) - : base(dataTypeService, wrapped, logger) + internal PublishValuesMultipleValueEditor(bool publishIds, IDataTypeService dataTypeService, ILogger logger, ValueEditorAttribute attribute) + : base(dataTypeService, attribute, logger) { _publishIds = publishIds; } - public PublishValuesMultipleValueEditor(bool publishIds, ValueEditor wrapped) - : this(publishIds, Current.Services.DataTypeService, Current.Logger, wrapped) + public PublishValuesMultipleValueEditor(bool publishIds, ValueEditorAttribute attribute) + : this(publishIds, Current.Services.DataTypeService, Current.Logger, attribute) { } /// diff --git a/src/Umbraco.Web/PropertyEditors/RadioButtonsPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/RadioButtonsPropertyEditor.cs index 3bac15e4d0..7bd1f70f07 100644 --- a/src/Umbraco.Web/PropertyEditors/RadioButtonsPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/RadioButtonsPropertyEditor.cs @@ -13,7 +13,7 @@ namespace Umbraco.Web.PropertyEditors /// as INT and we have logic in here to ensure it is formatted correctly including ensuring that the INT ID value is published /// in cache and not the string value. /// - [PropertyEditor(Constants.PropertyEditors.Aliases.RadioButtonList, "Radio button list", "radiobuttons", ValueType = ValueTypes.Integer, Group="lists", Icon="icon-target")] + [ValueEditor(Constants.PropertyEditors.Aliases.RadioButtonList, "Radio button list", "radiobuttons", ValueType = ValueTypes.Integer, Group="lists", Icon="icon-target")] public class RadioButtonsPropertyEditor : DropDownWithKeysPropertyEditor { /// diff --git a/src/Umbraco.Web/PropertyEditors/RelatedLinks2PropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/RelatedLinks2PropertyEditor.cs index 12907fcc94..73bddcb29f 100644 --- a/src/Umbraco.Web/PropertyEditors/RelatedLinks2PropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/RelatedLinks2PropertyEditor.cs @@ -5,7 +5,7 @@ using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { - [PropertyEditor(Constants.PropertyEditors.Aliases.RelatedLinks2, "Related links", "relatedlinks", ValueType = ValueTypes.Json, Icon = "icon-thumbnail-list", Group = "pickers")] + [ValueEditor(Constants.PropertyEditors.Aliases.RelatedLinks2, "Related links", "relatedlinks", ValueType = ValueTypes.Json, Icon = "icon-thumbnail-list", Group = "pickers")] public class RelatedLinks2PropertyEditor : PropertyEditor { public RelatedLinks2PropertyEditor(ILogger logger) diff --git a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs index 33995efd6b..2cf68af071 100644 --- a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs @@ -8,7 +8,7 @@ using Umbraco.Core.Services; namespace Umbraco.Web.PropertyEditors { - [PropertyEditor(Constants.PropertyEditors.Aliases.TinyMce, "Rich Text Editor", "rte", ValueType = ValueTypes.Text, HideLabel = false, Group="Rich Content", Icon="icon-browser-window")] + [ValueEditor(Constants.PropertyEditors.Aliases.TinyMce, "Rich Text Editor", "rte", ValueType = ValueTypes.Text, HideLabel = false, Group="Rich Content", Icon="icon-browser-window")] public class RichTextPropertyEditor : PropertyEditor { /// @@ -22,26 +22,19 @@ namespace Umbraco.Web.PropertyEditors /// Create a custom value editor /// /// - protected override ValueEditor CreateValueEditor() - { - return new RichTextPropertyValueEditor(base.CreateValueEditor()); - } + protected override ValueEditor CreateValueEditor() => new RichTextPropertyValueEditor(Attribute); - protected override ConfigurationEditor CreateConfigurationEditor() - { - return new RichTextConfigurationEditor(); - } + protected override ConfigurationEditor CreateConfigurationEditor() => new RichTextConfigurationEditor(); /// /// A custom value editor to ensure that macro syntax is parsed when being persisted and formatted correctly for display in the editor /// - internal class RichTextPropertyValueEditor : PropertyValueEditorWrapper + internal class RichTextPropertyValueEditor : ValueEditor { - public RichTextPropertyValueEditor(ValueEditor wrapped) - : base(wrapped) - { - } + public RichTextPropertyValueEditor(ValueEditorAttribute attribute) + : base(attribute) + { } /// /// override so that we can hide the label based on the pre-value diff --git a/src/Umbraco.Web/PropertyEditors/SliderPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/SliderPropertyEditor.cs index 8e21865484..4a065c42b6 100644 --- a/src/Umbraco.Web/PropertyEditors/SliderPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/SliderPropertyEditor.cs @@ -7,7 +7,7 @@ namespace Umbraco.Web.PropertyEditors /// /// Represents a slider editor. /// - [PropertyEditor(Constants.PropertyEditors.Aliases.Slider, "Slider", "slider", Icon="icon-navigation-horizontal")] + [ValueEditor(Constants.PropertyEditors.Aliases.Slider, "Slider", "slider", Icon="icon-navigation-horizontal")] public class SliderPropertyEditor : PropertyEditor { /// diff --git a/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs index 5b38f55e63..8976292baa 100644 --- a/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs @@ -11,7 +11,7 @@ using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { [SupportTags(typeof(TagPropertyEditorTagDefinition), ValueType = TagValueType.CustomTagList)] - [PropertyEditor(Constants.PropertyEditors.Aliases.Tags, "Tags", "tags", Icon="icon-tags")] + [ValueEditor(Constants.PropertyEditors.Aliases.Tags, "Tags", "tags", Icon="icon-tags")] public class TagsPropertyEditor : PropertyEditor { private ManifestValidatorCollection _validators; @@ -38,20 +38,14 @@ namespace Umbraco.Web.PropertyEditors set { _defaultPreVals = value; } } - protected override ValueEditor CreateValueEditor() - { - return new TagPropertyValueEditor(base.CreateValueEditor()); - } + protected override ValueEditor CreateValueEditor() => new TagPropertyValueEditor(Attribute); - protected override ConfigurationEditor CreateConfigurationEditor() - { - return new TagConfigurationEditor(_validators); - } + protected override ConfigurationEditor CreateConfigurationEditor() => new TagConfigurationEditor(_validators); - internal class TagPropertyValueEditor : PropertyValueEditorWrapper + internal class TagPropertyValueEditor : ValueEditor { - public TagPropertyValueEditor(ValueEditor wrapped) - : base(wrapped) + public TagPropertyValueEditor(ValueEditorAttribute attribute) + : base(attribute) { } /// diff --git a/src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs index d07945ad1d..68eb2089ed 100644 --- a/src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs @@ -7,7 +7,7 @@ namespace Umbraco.Web.PropertyEditors /// /// Represents a textarea editor. /// - [PropertyEditor(Constants.PropertyEditors.Aliases.TextboxMultiple, "Textarea", "textarea", IsMacroParameterEditor = true, ValueType = ValueTypes.Text, Icon="icon-application-window-alt")] + [ValueEditor(Constants.PropertyEditors.Aliases.TextboxMultiple, "Textarea", "textarea", IsMacroParameterEditor = true, ValueType = ValueTypes.Text, Icon="icon-application-window-alt")] public class TextAreaPropertyEditor : PropertyEditor { /// @@ -18,7 +18,7 @@ namespace Umbraco.Web.PropertyEditors { } /// - protected override ValueEditor CreateValueEditor() => new TextOnlyValueEditor(base.CreateValueEditor()); + protected override ValueEditor CreateValueEditor() => new TextOnlyValueEditor(Attribute); /// protected override ConfigurationEditor CreateConfigurationEditor() => new TextAreaConfigurationEditor(); diff --git a/src/Umbraco.Web/PropertyEditors/TextOnlyValueEditor.cs b/src/Umbraco.Web/PropertyEditors/TextOnlyValueEditor.cs index a18aa835ee..7951906b3b 100644 --- a/src/Umbraco.Web/PropertyEditors/TextOnlyValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TextOnlyValueEditor.cs @@ -9,11 +9,11 @@ namespace Umbraco.Web.PropertyEditors /// Custom value editor which ensures that the value stored is just plain text and that /// no magic json formatting occurs when translating it to and from the database values /// - public class TextOnlyValueEditor : PropertyValueEditorWrapper + public class TextOnlyValueEditor : ValueEditor { - public TextOnlyValueEditor(ValueEditor wrapped) : base(wrapped) - { - } + public TextOnlyValueEditor(ValueEditorAttribute attribute) + : base(attribute) + { } /// /// A method used to format the database value to a value that can be used by the editor diff --git a/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs index 2168bafdea..a380e0a077 100644 --- a/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs @@ -7,7 +7,7 @@ namespace Umbraco.Web.PropertyEditors /// /// Represents a textbox editor. /// - [PropertyEditor(Constants.PropertyEditors.Aliases.Textbox, "Textbox", "textbox", IsMacroParameterEditor = true, Group = "Common")] + [ValueEditor(Constants.PropertyEditors.Aliases.Textbox, "Textbox", "textbox", IsMacroParameterEditor = true, Group = "Common")] public class TextboxPropertyEditor : PropertyEditor { /// @@ -18,15 +18,9 @@ namespace Umbraco.Web.PropertyEditors { } /// - protected override ValueEditor CreateValueEditor() - { - return new TextOnlyValueEditor(base.CreateValueEditor()); - } + protected override ValueEditor CreateValueEditor() => new TextOnlyValueEditor(Attribute); /// - protected override ConfigurationEditor CreateConfigurationEditor() - { - return new TextboxConfigurationEditor(); - } + protected override ConfigurationEditor CreateConfigurationEditor() => new TextboxConfigurationEditor(); } } diff --git a/src/Umbraco.Web/PropertyEditors/TrueFalsePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TrueFalsePropertyEditor.cs index 5890a2df47..e7ce1fb0f0 100644 --- a/src/Umbraco.Web/PropertyEditors/TrueFalsePropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TrueFalsePropertyEditor.cs @@ -7,7 +7,7 @@ namespace Umbraco.Web.PropertyEditors /// /// Represents a boolean editor. /// - [PropertyEditor(Constants.PropertyEditors.Aliases.Boolean, "True/False", "boolean", ValueTypes.Integer, IsMacroParameterEditor = true, Group = "Common", Icon="icon-checkbox")] + [ValueEditor(Constants.PropertyEditors.Aliases.Boolean, "True/False", "boolean", ValueTypes.Integer, IsMacroParameterEditor = true, Group = "Common", Icon="icon-checkbox")] public class TrueFalsePropertyEditor : PropertyEditor { /// diff --git a/src/Umbraco.Web/PropertyEditors/UserPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/UserPickerPropertyEditor.cs index 3dbbfb4870..cb4bc211a1 100644 --- a/src/Umbraco.Web/PropertyEditors/UserPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/UserPickerPropertyEditor.cs @@ -7,7 +7,7 @@ using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { - [PropertyEditor(Constants.PropertyEditors.Aliases.UserPicker, "User picker", "entitypicker", ValueTypes.Integer, Group="People", Icon="icon-user")] + [ValueEditor(Constants.PropertyEditors.Aliases.UserPicker, "User picker", "entitypicker", ValueTypes.Integer, Group="People", Icon="icon-user")] public class UserPickerPropertyEditor : PropertyEditor { private IDictionary _defaultPreValues; diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/ContentPickerValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/ContentPickerValueConverter.cs index a2965e44ed..2bf1f6beba 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/ContentPickerValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/ContentPickerValueConverter.cs @@ -24,8 +24,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters } public override bool IsConverter(PublishedPropertyType propertyType) - => propertyType.EditorAlias.Equals(Constants.PropertyEditors.ContentPickerAlias) - || propertyType.EditorAlias.Equals(Constants.PropertyEditors.Aliases.ContentPicker2Alias); + => propertyType.EditorAlias.Equals(Constants.PropertyEditors.Aliases.ContentPicker2Alias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (IPublishedContent); diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/NestedContentManyValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/NestedContentManyValueConverter.cs index debf633a4b..078625547b 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/NestedContentManyValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/NestedContentManyValueConverter.cs @@ -62,14 +62,11 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters if (objects.Count == 0) return Enumerable.Empty(); - // fixme - var x = propertyType.DataType.Configuration as NestedContentConfiguration; - var y = NestedContentPropertyEditor.CastConfiguration(propertyType.DataType.Configuration); - #error - var contentTypes = propertyType.DataType.GetConfiguration().ContentTypes; + var configuration = propertyType.DataType.ConfigurationAs(); + var contentTypes = configuration.ContentTypes; var elements = contentTypes.Length > 1 ? new List() - : PublishedModelFactory.CreateModelList(contentTypes[0].Alias); + : PublishedModelFactory.CreateModelList(contentTypes[0]); foreach (var sourceObject in objects) { diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 041c1c9304..ce976fd000 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -265,6 +265,7 @@ + @@ -709,7 +710,6 @@ -