diff --git a/src/Umbraco.Compat7/Core/PropertyEditors/PropertyEditorResolver.cs b/src/Umbraco.Compat7/Core/PropertyEditors/PropertyEditorResolver.cs index 3c63ada35e..d4d96226d8 100644 --- a/src/Umbraco.Compat7/Core/PropertyEditors/PropertyEditorResolver.cs +++ b/src/Umbraco.Compat7/Core/PropertyEditors/PropertyEditorResolver.cs @@ -7,7 +7,7 @@ using LightInject; // ReSharper disable once CheckNamespace namespace Umbraco.Core.PropertyEditors { - public class PropertyEditorResolver : LazyManyObjectsResolverBase + public class PropertyEditorResolver : LazyManyObjectsResolverBase { private PropertyEditorResolver(PropertyEditorCollectionBuilder builder) : base(builder) @@ -16,8 +16,8 @@ namespace Umbraco.Core.PropertyEditors public static PropertyEditorResolver Current { get; } = new PropertyEditorResolver(CoreCurrent.Container.GetInstance()); - public IEnumerable PropertyEditors => CoreCurrent.PropertyEditors; + public IEnumerable PropertyEditors => CoreCurrent.PropertyEditors; - public PropertyEditor GetByAlias(string alias) => CoreCurrent.PropertyEditors[alias]; + public ConfiguredDataEditor GetByAlias(string alias) => CoreCurrent.PropertyEditors[alias]; } } diff --git a/src/Umbraco.Core/Composing/TypeLoaderExtensions.cs b/src/Umbraco.Core/Composing/TypeLoaderExtensions.cs index 71a59c2d4d..6177151a00 100644 --- a/src/Umbraco.Core/Composing/TypeLoaderExtensions.cs +++ b/src/Umbraco.Core/Composing/TypeLoaderExtensions.cs @@ -12,35 +12,11 @@ namespace Umbraco.Core.Composing internal static class TypeLoaderExtensions { /// - /// Gets all classes inheriting from PropertyEditor. + /// Gets all classes implementing . /// - /// - /// Excludes the actual PropertyEditor base type. - /// - public static IEnumerable GetPropertyEditors(this TypeLoader mgr) + public static IEnumerable GetDataEditors(this TypeLoader mgr) { - // look for IParameterEditor (fast, IDiscoverable) then filter - - var propertyEditor = typeof (PropertyEditor); - - return mgr.GetTypes() - .Where(x => propertyEditor.IsAssignableFrom(x) && x != propertyEditor); - } - - /// - /// Gets all classes implementing IParameterEditor. - /// - /// - /// Includes property editors. - /// Excludes the actual ParameterEditor and PropertyEditor base types. - /// - public static IEnumerable GetParameterEditors(this TypeLoader mgr) - { - var propertyEditor = typeof (PropertyEditor); - var parameterEditor = typeof (ParameterEditor); - - return mgr.GetTypes() - .Where(x => x != propertyEditor && x != parameterEditor); + return mgr.GetTypes(); } /// diff --git a/src/Umbraco.Core/Manifest/DataEditorConverter.cs b/src/Umbraco.Core/Manifest/DataEditorConverter.cs new file mode 100644 index 0000000000..94536a18c4 --- /dev/null +++ b/src/Umbraco.Core/Manifest/DataEditorConverter.cs @@ -0,0 +1,155 @@ +using System; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Umbraco.Core.Logging; +using Umbraco.Core.PropertyEditors; +using Umbraco.Core.Serialization; + +namespace Umbraco.Core.Manifest +{ + /// + /// Provides a json read converter for in manifests. + /// + internal class DataEditorConverter : JsonReadConverter + { + private readonly ILogger _logger; + + /// + /// Initializes a new instance of the class. + /// + public DataEditorConverter(ILogger logger) + { + _logger = logger; + } + + /// + protected override IDataEditor Create(Type objectType, JObject jobject) + { + // in PackageManifest, property editors are IConfiguredDataEditor[] whereas + // parameter editors are IDataEditor[] - both will end up here because we handle + // IDataEditor and IConfiguredDataEditor implements it, but we can check the + // type to figure out what to create + + if (objectType == typeof(IConfiguredDataEditor)) + { + // property editor + var type = EditorType.PropertyValue; + if (jobject["isParameterEditor"] is JToken jToken && jToken.Value()) + type &= EditorType.MacroParameter; + return new ConfiguredDataEditor(_logger, type); + } + else + { + // parameter editor + return new DataEditor(EditorType.MacroParameter); + } + } + + /// + protected override void Deserialize(JObject jobject, IDataEditor target, JsonSerializer serializer) + { + // see Create above, target is either DataEditor (parameter) or ConfiguredDataEditor (property) + + if (target is ConfiguredDataEditor configuredEditor) + { + // property editor + PrepareForPropertyEditor(jobject, configuredEditor); + } + else if (target is DataEditor editor) + { + // parameter editor + PrepareForParameterEditor(jobject, editor); + } + else throw new Exception("panic."); + + base.Deserialize(jobject, target, serializer); + } + + private static void PrepareForPropertyEditor(JObject jobject, ConfiguredDataEditor target) + { + if (jobject["editor"] != null) + { + // explicitely assign a value editor of type ValueEditor + // (else the deserializer will try to read it before setting it) + // (and besides it's an interface) + target.ValueEditor = new DataValueEditor(); + + // in the manifest, validators are a simple dictionary eg + // { + // required: true, + // regex: '\\d*' + // } + // and we need to turn this into a list of IPropertyValidator + // so, rewrite the json structure accordingly + if (jobject["editor"]["validation"] is JObject validation) + jobject["editor"]["validation"] = RewriteValidators(validation); + } + + if (jobject["prevalues"] is JObject prevalues) + { + // explicitely assign a configuration editor of type ConfigurationEditor + // (else the deserializer will try to read it before setting it) + // (and besides it's an interface) + target.ConfigurationEditor = new ConfigurationEditor(); + + // see note about validators, above - same applies to field validators + if (jobject["prevalues"]?["fields"] is JArray jarray) + { + foreach (var field in jarray) + { + if (field["validation"] is JObject validation) + field["validation"] = RewriteValidators(validation); + } + } + + // in the manifest, default configuration is at editor level + // move it down to configuration editor level so it can be deserialized properly + if (jobject["defaultConfig"] is JObject defaultConfig) + { + prevalues["defaultConfig"] = defaultConfig; + jobject.Remove("defaultConfig"); + } + } + } + + private static void PrepareForParameterEditor(JObject jobject, DataEditor target) + { + // in a manifest, a parameter editor looks like: + // + // { + // "alias": "...", + // "name": "...", + // "view": "...", + // "config": { "key1": "value1", "key2": "value2" ... } + // } + // + // the view is at top level, but should be down one level to be propertly + // deserialized as a ParameterValueEditor property -> need to move it + + if (jobject.Property("view") != null) + { + // explicitely assign a value editor of type ParameterValueEditor + target.ValueEditor = new DataValueEditor(); + + // move the 'view' property + jobject["editor"] = new JObject { ["view"] = jobject["view"] }; + jobject.Property("view").Remove(); + } + } + + private static JArray RewriteValidators(JObject validation) + { + var jarray = new JArray(); + + foreach (var v in validation) + { + var key = v.Key; + var val = v.Value?.Type == JTokenType.Boolean ? string.Empty : v.Value; + var jo = new JObject { { "type", key }, { "config", val } }; + jarray.Add(jo); + } + + return jarray; + } + } +} diff --git a/src/Umbraco.Core/Manifest/ManifestParser.cs b/src/Umbraco.Core/Manifest/ManifestParser.cs index 2fd3a5f6ad..b8ff43ecd5 100644 --- a/src/Umbraco.Core/Manifest/ManifestParser.cs +++ b/src/Umbraco.Core/Manifest/ManifestParser.cs @@ -59,7 +59,7 @@ namespace Umbraco.Core.Manifest { var manifests = GetManifests(); return MergeManifests(manifests); - }); + }, new TimeSpan(0, 4, 0)); /// /// Gets all manifests. @@ -95,8 +95,8 @@ namespace Umbraco.Core.Manifest { var scripts = new HashSet(); var stylesheets = new HashSet(); - var propertyEditors = new List(); - var parameterEditors = new List(); + var propertyEditors = new List(); + var parameterEditors = new List(); var gridEditors = new List(); foreach (var manifest in manifests) @@ -140,8 +140,7 @@ namespace Umbraco.Core.Manifest throw new ArgumentNullOrEmptyException(nameof(text)); var manifest = JsonConvert.DeserializeObject(text, - new PropertyEditorConverter(_logger), - new ParameterEditorConverter(), + new DataEditorConverter(_logger), new ManifestValidatorConverter(_validators)); // scripts and stylesheets are raw string, must process here @@ -150,6 +149,12 @@ namespace Umbraco.Core.Manifest for (var i = 0; i < manifest.Stylesheets.Length; i++) manifest.Stylesheets[i] = IOHelper.ResolveVirtualUrl(manifest.Stylesheets[i]); + // add property editors that are also parameter editors, to the parameter editors list + // (the manifest format is kinda legacy) + var ppEditors = manifest.PropertyEditors.Where(x => (x.Type & EditorType.MacroParameter) > 0).ToList(); + if (ppEditors.Count > 0) + manifest.ParameterEditors = manifest.ParameterEditors.Union(ppEditors).ToArray(); + return manifest; } diff --git a/src/Umbraco.Core/Manifest/PackageManifest.cs b/src/Umbraco.Core/Manifest/PackageManifest.cs index 86028d91dd..a739151ff7 100644 --- a/src/Umbraco.Core/Manifest/PackageManifest.cs +++ b/src/Umbraco.Core/Manifest/PackageManifest.cs @@ -16,10 +16,10 @@ namespace Umbraco.Core.Manifest public string[] Stylesheets { get; set; }= Array.Empty(); [JsonProperty("propertyEditors")] - public PropertyEditor[] PropertyEditors { get; set; } = Array.Empty(); + public IConfiguredDataEditor[] PropertyEditors { get; set; } = Array.Empty(); [JsonProperty("parameterEditors")] - public ParameterEditor[] ParameterEditors { get; set; } = Array.Empty(); + public IDataEditor[] ParameterEditors { get; set; } = Array.Empty(); [JsonProperty("gridEditors")] public GridEditor[] GridEditors { get; set; } = Array.Empty(); diff --git a/src/Umbraco.Core/Manifest/ParameterEditorConverter.cs b/src/Umbraco.Core/Manifest/ParameterEditorConverter.cs deleted file mode 100644 index 51799d3fd5..0000000000 --- a/src/Umbraco.Core/Manifest/ParameterEditorConverter.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Umbraco.Core.PropertyEditors; -using Umbraco.Core.Serialization; - -namespace Umbraco.Core.Manifest -{ - /// - /// Implements a json read converter for . - /// - internal class ParameterEditorConverter : JsonReadConverter - { - /// - protected override ParameterEditor Create(Type objectType, JObject jObject) - { - return new ParameterEditor(); - - } - /// - protected override void Deserialize(JObject jobject, ParameterEditor target, JsonSerializer serializer) - { - // in a manifest, a parameter editor looks like: - // - // { - // "alias": "...", - // "name": "...", - // "view": "...", - // "config": { "key1": "value1", "key2": "value2" ... } - // } - // - // the view is at top level, but should be down one level to be propertly - // deserialized as a ParameterValueEditor property -> need to move it - - if (jobject.Property("view") != null) - { - // explicitely assign a value editor of type ParameterValueEditor - target.ValueEditor = new ParameterValueEditor(); - - // move the 'view' property - jobject["editor"] = new JObject { ["view"] = jobject["view"] }; - jobject.Property("view").Remove(); - } - - base.Deserialize(jobject, target, serializer); - } - } -} diff --git a/src/Umbraco.Core/Manifest/PropertyEditorConverter.cs b/src/Umbraco.Core/Manifest/PropertyEditorConverter.cs deleted file mode 100644 index 13896efadb..0000000000 --- a/src/Umbraco.Core/Manifest/PropertyEditorConverter.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Umbraco.Core.Logging; -using Umbraco.Core.PropertyEditors; -using Umbraco.Core.Serialization; - -namespace Umbraco.Core.Manifest -{ - /// - /// Implements a json read converter for . - /// - internal class PropertyEditorConverter : JsonReadConverter - { - private readonly ILogger _logger; - - /// - /// Initializes a new instance of the class. - /// - public PropertyEditorConverter(ILogger logger) - { - _logger = logger; - } - - /// - protected override PropertyEditor Create(Type objectType, JObject jObject) - { - return new PropertyEditor(_logger); - } - - /// - protected override void Deserialize(JObject jobject, PropertyEditor target, JsonSerializer serializer) - { - if (jobject["editor"] != null) - { - // explicitely assign a value editor of type ValueEditor - // (else the deserializer will try to read it before setting it) - // (and besides it's an interface) - target.ValueEditor = new ValueEditor(); - - // in the manifest, validators are a simple dictionary eg - // { - // required: true, - // regex: '\\d*' - // } - // and we need to turn this into a list of IPropertyValidator - // so, rewrite the json structure accordingly - if (jobject["editor"]["validation"] is JObject validation) - jobject["editor"]["validation"] = RewriteValidators(validation); - } - - if (jobject["prevalues"] is JObject prevalues) - { - // explicitely assign a configuration editor of type ConfigurationEditor - // (else the deserializer will try to read it before setting it) - // (and besides it's an interface) - target.ConfigurationEditor = new ConfigurationEditor(); - - // see note about validators, above - same applies to field validators - if (jobject["prevalues"]?["fields"] is JArray jarray) - { - foreach (var field in jarray) - { - if (field["validation"] is JObject validation) - field["validation"] = RewriteValidators(validation); - } - } - - // in the manifest, default configuration is at editor level - // move it down to configuration editor level so it can be deserialized properly - if (jobject["defaultConfig"] is JObject defaultConfig) - { - prevalues["defaultConfig"] = defaultConfig; - jobject.Remove("defaultConfig"); - } - } - - base.Deserialize(jobject, target, serializer); - } - - private static JArray RewriteValidators(JObject validation) - { - var jarray = new JArray(); - - foreach (var v in validation) - { - var key = v.Key; - var val = v.Value?.Type == JTokenType.Boolean ? string.Empty : v.Value; - var jo = new JObject { { "type", key }, { "config", val } }; - jarray.Add(jo); - } - - return jarray; - } - } -} diff --git a/src/Umbraco.Core/Models/DataType.cs b/src/Umbraco.Core/Models/DataType.cs index 0bb1515950..0732c51ec9 100644 --- a/src/Umbraco.Core/Models/DataType.cs +++ b/src/Umbraco.Core/Models/DataType.cs @@ -17,7 +17,7 @@ namespace Umbraco.Core.Models { private static PropertySelectors _selectors; - private PropertyEditor _editor; + private IConfiguredDataEditor _editor; private ValueStorageType _databaseType; private object _configuration; private bool _hasConfiguration; @@ -26,7 +26,7 @@ namespace Umbraco.Core.Models /// /// Initializes a new instance of the class. /// - public DataType(PropertyEditor editor, int parentId = -1) + public DataType(IConfiguredDataEditor editor, int parentId = -1) { _editor = editor ?? throw new ArgumentNullException(nameof(editor)); ParentId = parentId; @@ -36,14 +36,14 @@ namespace Umbraco.Core.Models private class PropertySelectors { - public readonly PropertyInfo Editor = ExpressionHelper.GetPropertyInfo(x => x.Editor); + public readonly PropertyInfo Editor = ExpressionHelper.GetPropertyInfo(x => x.Editor); public readonly PropertyInfo DatabaseType = ExpressionHelper.GetPropertyInfo(x => x.DatabaseType); public readonly PropertyInfo Configuration = ExpressionHelper.GetPropertyInfo(x => x.Configuration); } /// [IgnoreDataMember] - public PropertyEditor Editor + public IConfiguredDataEditor Editor { get => _editor; set diff --git a/src/Umbraco.Core/Models/IDataType.cs b/src/Umbraco.Core/Models/IDataType.cs index c44629a8c0..a365e05535 100644 --- a/src/Umbraco.Core/Models/IDataType.cs +++ b/src/Umbraco.Core/Models/IDataType.cs @@ -11,7 +11,7 @@ namespace Umbraco.Core.Models /// /// Gets or sets the property editor. /// - PropertyEditor Editor { get; set; } + IConfiguredDataEditor Editor { get; set; } /// /// Gets the property editor alias. diff --git a/src/Umbraco.Core/PropertyEditors/ConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/ConfigurationEditor.cs index 7c089a3f99..159dc5ec7d 100644 --- a/src/Umbraco.Core/PropertyEditors/ConfigurationEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/ConfigurationEditor.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.PropertyEditors /// /// Represents a data type configuration editor. /// - public class ConfigurationEditor + public class ConfigurationEditor : IConfigurationEditor { /// /// Initializes a new instance of the class. @@ -33,7 +33,7 @@ namespace Umbraco.Core.PropertyEditors public List Fields { get; } /// - /// Gets a field by property name. + /// Gets a field by its property name. /// /// Can be used in constructors to add infos to a field that has been defined /// by a property marked with the . @@ -50,41 +50,20 @@ namespace Umbraco.Core.PropertyEditors throw new InvalidCastException($"Cannot cast configuration of type {obj.GetType().Name} to {typeof(TConfiguration).Name}."); } - /// - /// Gets the default configuration. - /// - /// - /// The default configuration is used to initialize new datatypes. - /// + /// [JsonProperty("defaultConfig")] public virtual IDictionary DefaultConfiguration => new Dictionary(); - /// - /// Determines whether a configuration object is of the type expected by the configuration editor. - /// - public virtual bool IsConfiguration(object obj) - => obj is IDictionary; + /// + public virtual bool IsConfiguration(object obj) => obj is IDictionary; - // notes - // ToConfigurationEditor returns a dictionary, and FromConfigurationEditor accepts a dictionary. - // this is due to the way our front-end editors work, see DataTypeController.PostSave - // and DataTypeConfigurationFieldDisplayResolver - we are not going to change it now. - - /// - /// Converts the serialized database value into the actual configuration object. - /// - /// Converting the configuration object to the serialized database value is - /// achieved by simply serializing the configuration. + /// public virtual object FromDatabase(string configurationJson) => string.IsNullOrWhiteSpace(configurationJson) ? new Dictionary() : JsonConvert.DeserializeObject>(configurationJson); - /// - /// Converts the values posted by the configuration editor into the actual configuration object. - /// - /// The values posted by the configuration editor. - /// The current configuration object. + /// public virtual object FromConfigurationEditor(Dictionary editorValues, object configuration) { // by default, return the posted dictionary @@ -97,10 +76,7 @@ namespace Umbraco.Core.PropertyEditors return editorValues; } - /// - /// Converts the configuration object to values for the configuration editor. - /// - /// The configuration. + /// public virtual Dictionary ToConfigurationEditor(object configuration) { // editors that do not override ToEditor/FromEditor have their configuration @@ -120,10 +96,7 @@ namespace Umbraco.Core.PropertyEditors return d; } - /// - /// Converts the configuration object to values for the value editror. - /// - /// The configuration. + /// public virtual Dictionary ToValueEditor(object configuration) => ToConfigurationEditor(configuration); } diff --git a/src/Umbraco.Core/PropertyEditors/PropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/ConfiguredDataEditor.cs similarity index 70% rename from src/Umbraco.Core/PropertyEditors/PropertyEditor.cs rename to src/Umbraco.Core/PropertyEditors/ConfiguredDataEditor.cs index f2a9af3299..8c4d475088 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/ConfiguredDataEditor.cs @@ -1,208 +1,192 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using Newtonsoft.Json; -using Umbraco.Core.IO; -using Umbraco.Core.Logging; - -namespace Umbraco.Core.PropertyEditors -{ - /// - /// Provides a base class for property editors. - /// - /// - /// Editors can be deserialized from manifests, which is why the Json serialization - /// attributes are required, and the properties require an internal setter. - /// - [DebuggerDisplay("{" + nameof(DebuggerDisplay) + "(),nq}")] - public class PropertyEditor : IParameterEditor - { - private IPropertyValueEditor _valueEditorAssigned; - private ConfigurationEditor _configurationEditorAssigned; - - /// - /// Initializes a new instance of the class. - /// - public PropertyEditor(ILogger logger) - { - Logger = logger ?? throw new ArgumentNullException(nameof(logger)); - - // defaults - Icon = Constants.Icons.PropertyEditor; - Group = "common"; - - // assign properties based on the attribute, if it is found - 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; - } - - /// - /// Gets the editor attribute. - /// - protected ValueEditorAttribute Attribute { get; } - - /// - /// Gets a logger. - /// - protected ILogger Logger { get; } - - /// - /// Gets or sets a value indicating whether this editor can be used as a parameter editor. - /// - [JsonProperty("isParameterEditor")] - public bool IsParameterEditor { get; internal set; } // fixme understand + explain - - /// - /// Gets or sets the unique alias of the property editor. - /// - [JsonProperty("alias", Required = Required.Always)] - public string Alias { get; internal set; } - - /// - /// Gets or sets the name of the property editor. - /// - [JsonProperty("name", Required = Required.Always)] - public string Name { get; internal set; } - - /// - /// Gets or sets the icon of the property editor. - /// - [JsonProperty("icon")] - public string Icon { get; internal set; } - - /// - /// Gets or sets the group of the property editor. - /// - /// The group can be used to group editors by categories. - [JsonProperty("group")] - public string Group { get; internal set; } - - /// - /// Gets or sets a value indicating whether the property editor is deprecated. - /// - /// A deprecated editor does not show up in the list of available editors for a datatype, - /// unless it is the current editor for the datatype. - [JsonIgnore] - public bool IsDeprecated { get; internal set; } - - /// - /// Gets or sets the value editor. - /// - /// - /// If an instance of a value editor is assigned to the property, - /// then this instance is returned when getting the property value. Otherwise, a - /// new instance is created by CreateValueEditor. - /// The instance created by CreateValueEditor is not cached, i.e. - /// a new instance is created each time the property value is retrieved. The - /// property editor is a singleton, and the value editor cannot be a singleton - /// since it depends on the datatype configuration. - /// Technically, it could be cached by datatype but let's keep things - /// simple enough for now. - /// The property is *not* marked with json ObjectCreationHandling = ObjectCreationHandling.Replace, - /// so by default the deserializer will first try to read it before assigning it, which is why - /// all deserialization *should* set the property before anything (see manifest deserializer). - /// - [JsonProperty("editor", Required = Required.Always)] - public IPropertyValueEditor ValueEditor - { - // create a new value editor each time - the property editor can be a - // singleton, but the value editor will get a configuration which depends - // on the datatype, so it cannot be a singleton really - get => CreateValueEditor(); - set => _valueEditorAssigned = value; - } - - /// - [JsonIgnore] - IValueEditor IParameterEditor.ValueEditor => ValueEditor; - - /// - /// Gets or sets the configuration editor. - /// - /// - /// If an instance of a configuration editor is assigned to the property, - /// then this instance is returned when getting the property value. Otherwise, a - /// new instance is created by CreateConfigurationEditor. - /// The instance created by CreateConfigurationEditor is not cached, i.e. - /// a new instance is created each time the property value is retrieved. The - /// property editor is a singleton, and although the configuration editor could - /// technically be a singleton too, we'd rather not keep configuration editor - /// cached. - /// The property is *not* marked with json ObjectCreationHandling = ObjectCreationHandling.Replace, - /// so by default the deserializer will first try to read it before assigning it, which is why - /// all deserialization *should* set the property before anything (see manifest deserializer). - /// - [JsonProperty("prevalues")] // changing the name would break manifests - public ConfigurationEditor ConfigurationEditor - { - get => CreateConfigurationEditor(); - set => _configurationEditorAssigned = value; - } - - // a property editor has a configuration editor which is in charge of all configuration - // a parameter editor does not have a configuration editor and directly handles its configuration - // when a property editor can also be a parameter editor it needs to expose the configuration - // fixme but that's only for some property editors - [JsonIgnore] - IDictionary IParameterEditor.Configuration => ConfigurationEditor.DefaultConfiguration; - - /// - /// Creates a value editor instance. - /// - protected virtual IPropertyValueEditor CreateValueEditor() - { - // handle assigned editor - // or create a new editor - return _valueEditorAssigned ?? new ValueEditor(Attribute); - } - - /// - /// Creates a configuration editor instance. - /// - protected virtual ConfigurationEditor CreateConfigurationEditor() - { - // handle assigned editor - if (_configurationEditorAssigned != null) - return _configurationEditorAssigned; - - // else return an empty one - return new ConfigurationEditor(); - } - - protected bool Equals(PropertyEditor other) - { - return string.Equals(Alias, other.Alias); - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != GetType()) return false; - return Equals((PropertyEditor) obj); - } - - public override int GetHashCode() - { - // an internal setter is required for de-serialization from manifests - // but we are never going to change the alias once the editor exists - // ReSharper disable once NonReadonlyMemberInGetHashCode - return Alias.GetHashCode(); - } - - /// - /// Provides a summary of the PropertyEditor for use with the . - /// - protected virtual string DebuggerDisplay() - { - return $"Name: {Name}, Alias: {Alias}, IsParameterEditor: {IsParameterEditor}"; - } - } -} +using System; +using System.Collections.Generic; +using System.Diagnostics; +using Newtonsoft.Json; +using Umbraco.Core.Composing; +using Umbraco.Core.IO; +using Umbraco.Core.Logging; + +namespace Umbraco.Core.PropertyEditors +{ + /// + /// Provides a base class for property editors. fixme rewrite + /// + /// + /// Editors can be deserialized from manifests, which is why the Json serialization + /// attributes are required, and the properties require an internal setter. + /// + [DebuggerDisplay("{" + nameof(DebuggerDisplay) + "(),nq}")] + [HideFromTypeFinder] + public class ConfiguredDataEditor : IConfiguredDataEditor + { + private IDataValueEditor _valueEditorAssigned; + private IConfigurationEditor _configurationEditorAssigned; + + /// + /// Initializes a new instance of the class. + /// + public ConfiguredDataEditor(ILogger logger, EditorType type = EditorType.PropertyValue) + { + Logger = logger ?? throw new ArgumentNullException(nameof(logger)); + + // defaults + Type = type; + Icon = Constants.Icons.PropertyEditor; + Group = "common"; + + // assign properties based on the attribute, if it is found + Attribute = GetType().GetCustomAttribute(false); + if (Attribute == null) return; + + Alias = Attribute.Alias; + Type = Attribute.Type; + Name = Attribute.Name; + Icon = Attribute.Icon; + Group = Attribute.Group; + IsDeprecated = Attribute.IsDeprecated; + } + + /// + /// Gets the editor attribute. + /// + protected DataEditorAttribute Attribute { get; } + + /// + /// Gets a logger. + /// + protected ILogger Logger { get; } + + /// + [JsonProperty("alias", Required = Required.Always)] + public string Alias { get; internal set; } + + /// + [JsonIgnore] + public EditorType Type { get; } + + /// + [JsonProperty("name", Required = Required.Always)] + public string Name { get; internal set; } + + /// + [JsonProperty("icon")] + public string Icon { get; internal set; } + + /// + [JsonProperty("group")] + public string Group { get; internal set; } + + /// + /// Gets or sets a value indicating whether the property editor is deprecated. + /// + /// A deprecated editor does not show up in the list of available editors for a datatype, + /// unless it is the current editor for the datatype. + [JsonIgnore] + public bool IsDeprecated { get; internal set; } // fixme on interface? + + [JsonProperty("preValues")] + public IDictionary DefaultConfiguration => ConfigurationEditor.DefaultConfiguration; + + /// + /// Gets or sets the value editor. + /// + /// + /// If an instance of a value editor is assigned to the property, + /// then this instance is returned when getting the property value. Otherwise, a + /// new instance is created by CreateValueEditor. + /// The instance created by CreateValueEditor is not cached, i.e. + /// a new instance is created each time the property value is retrieved. The + /// property editor is a singleton, and the value editor cannot be a singleton + /// since it depends on the datatype configuration. + /// Technically, it could be cached by datatype but let's keep things + /// simple enough for now. + /// The property is *not* marked with json ObjectCreationHandling = ObjectCreationHandling.Replace, + /// so by default the deserializer will first try to read it before assigning it, which is why + /// all deserialization *should* set the property before anything (see manifest deserializer). + /// + [JsonProperty("editor", Required = Required.Always)] + public IDataValueEditor ValueEditor + { + // create a new value editor each time - the property editor can be a + // singleton, but the value editor will get a configuration which depends + // on the datatype, so it cannot be a singleton really + get => CreateValueEditor(); + set => _valueEditorAssigned = value; + } + + /// + /// Gets or sets the configuration editor. + /// + /// + /// If an instance of a configuration editor is assigned to the property, + /// then this instance is returned when getting the property value. Otherwise, a + /// new instance is created by CreateConfigurationEditor. + /// The instance created by CreateConfigurationEditor is not cached, i.e. + /// a new instance is created each time the property value is retrieved. The + /// property editor is a singleton, and although the configuration editor could + /// technically be a singleton too, we'd rather not keep configuration editor + /// cached. + /// The property is *not* marked with json ObjectCreationHandling = ObjectCreationHandling.Replace, + /// so by default the deserializer will first try to read it before assigning it, which is why + /// all deserialization *should* set the property before anything (see manifest deserializer). + /// + [JsonProperty("prevalues")] // changing the name would break manifests + public IConfigurationEditor ConfigurationEditor + { + get => CreateConfigurationEditor(); + set => _configurationEditorAssigned = value; + } + + /// + /// Creates a value editor instance. + /// + protected virtual IDataValueEditor CreateValueEditor() + { + // handle assigned editor + // or create a new editor + return _valueEditorAssigned ?? new DataValueEditor(Attribute); + } + + /// + /// Creates a configuration editor instance. + /// + protected virtual IConfigurationEditor CreateConfigurationEditor() + { + // handle assigned editor + if (_configurationEditorAssigned != null) + return _configurationEditorAssigned; + + // else return an empty one + return new ConfigurationEditor(); + } + + protected bool Equals(ConfiguredDataEditor other) + { + return string.Equals(Alias, other.Alias); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != GetType()) return false; + return Equals((ConfiguredDataEditor) obj); + } + + public override int GetHashCode() + { + // an internal setter is required for de-serialization from manifests + // but we are never going to change the alias once the editor exists + // ReSharper disable once NonReadonlyMemberInGetHashCode + return Alias.GetHashCode(); + } + + /// + /// Provides a summary of the PropertyEditor for use with the . + /// + protected virtual string DebuggerDisplay() + { + return $"Name: {Name}, Alias: {Alias}"; + } + } +} diff --git a/src/Umbraco.Core/PropertyEditors/DataEditor.cs b/src/Umbraco.Core/PropertyEditors/DataEditor.cs new file mode 100644 index 0000000000..eb51e26369 --- /dev/null +++ b/src/Umbraco.Core/PropertyEditors/DataEditor.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +using Newtonsoft.Json; +using Umbraco.Core.Composing; + +namespace Umbraco.Core.PropertyEditors +{ + /// + /// Represents a parameter editor. fixme rewrite + /// + /// + /// Is not abstract because can be instanciated from manifests. + /// + [HideFromTypeFinder] + public class DataEditor : IDataEditor + { + private IDataValueEditor _valueEditor; + private IDataValueEditor _valueEditorAssigned; + + /// + /// Initializes a new instance of the class. + /// + public DataEditor(EditorType type = EditorType.PropertyValue) + { + // defaults + Type = type; + Icon = Constants.Icons.PropertyEditor; + Group = "common"; + DefaultConfiguration = new Dictionary(); + + // assign properties based on the attribute, if it is found + Attribute = GetType().GetCustomAttribute(false); + if (Attribute == null) return; + + Alias = Attribute.Alias; + Type = Attribute.Type; + Name = Attribute.Name; + } + + /// + /// Gets the editor attribute. + /// + protected DataEditorAttribute Attribute { get; } + + /// + [JsonProperty("alias", Required = Required.Always)] + public string Alias { get; internal set; } + + /// + [JsonIgnore] + public EditorType Type { get; } + + /// + [JsonProperty("name", Required = Required.Always)] + public string Name { get; internal set; } + + /// + [JsonProperty("icon")] + public string Icon { get; } + + /// + [JsonProperty("group")] + public string Group { get; } + + /// + [JsonProperty("editor")] + public IDataValueEditor ValueEditor + { + get => _valueEditor ?? (_valueEditor = CreateValueEditor()); + set + { + _valueEditorAssigned = value; + _valueEditor = null; + } + } + + /// + [JsonProperty("config")] + public IDictionary DefaultConfiguration { get; set; } + + /// + /// Creates a value editor instance. + /// + /// + protected virtual IDataValueEditor CreateValueEditor() + { + // handle assigned editor + if (_valueEditorAssigned != null) + return _valueEditorAssigned; + + // create a new editor + var editor = new DataValueEditor(); + + var view = Attribute?.View; + if (string.IsNullOrWhiteSpace(view)) + throw new InvalidOperationException("The editor does not specify a view."); + editor.View = view; + + return editor; + } + } +} diff --git a/src/Umbraco.Core/PropertyEditors/DataEditorAttribute.cs b/src/Umbraco.Core/PropertyEditors/DataEditorAttribute.cs index 7c0cc6c8ef..30d0df1cb5 100644 --- a/src/Umbraco.Core/PropertyEditors/DataEditorAttribute.cs +++ b/src/Umbraco.Core/PropertyEditors/DataEditorAttribute.cs @@ -6,20 +6,63 @@ namespace Umbraco.Core.PropertyEditors /// /// Marks a class that represents a data editor. /// - public abstract class DataEditorAttribute : Attribute + [AttributeUsage(AttributeTargets.Class)] + public sealed class DataEditorAttribute : Attribute { + private string _valueType = ValueTypes.String; + /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class for a property editor. /// /// The unique identifier of the editor. /// The friendly name of the editor. + public DataEditorAttribute(string alias, string name) + : this(alias, EditorType.PropertyValue, name, NullView) + { } + + /// + /// Initializes a new instance of the class for a property editor. + /// + /// The unique identifier of the editor. + /// The friendly name of the editor. + /// The view to use to render the editor. + public DataEditorAttribute(string alias, string name, string view) + : this(alias, EditorType.PropertyValue, name, view) + { } + + /// + /// Initializes a new instance of the class. + /// + /// The unique identifier of the editor. + /// The type of the editor. + /// The friendly name of the editor. + public DataEditorAttribute(string alias, EditorType type, string name) + : this(alias, type, name, NullView) + { } + + /// + /// Initializes a new instance of the class. + /// + /// The unique identifier of the editor. + /// The type of the editor. + /// The friendly name of the editor. /// The view to use to render the editor. /// /// Set to to explicitely set the view to null. /// Otherwise, cannot be null nor empty. /// - protected DataEditorAttribute(string alias, string name, string view) + public DataEditorAttribute(string alias, EditorType type, string name, string view) { + switch (type) // Enum.IsDefined is slow + { + case EditorType.PropertyValue: + case EditorType.MacroParameter: + Type = type; + break; + default: + throw new ArgumentOutOfRangeException(nameof(type), $"Not a valid {typeof(EditorType)} value."); + } + if (string.IsNullOrWhiteSpace(alias)) throw new ArgumentNullOrEmptyException(nameof(alias)); Alias = alias; @@ -33,21 +76,63 @@ namespace Umbraco.Core.PropertyEditors /// /// Gets a special value indicating that the view should be null. /// - protected static string NullView = "EXPLICITELY-SET-VIEW-TO-NULL-2B5B0B73D3DD47B28DDB84E02C349DFB"; // just a random string + public const string NullView = "EXPLICITELY-SET-VIEW-TO-NULL-2B5B0B73D3DD47B28DDB84E02C349DFB"; // just a random string /// /// Gets the unique alias of the editor. /// public string Alias { get; } + /// + /// Gets the type of the editor. + /// + public EditorType Type { get; } + /// /// Gets the friendly name of the editor. /// public string Name { get; } /// - /// Gets the view to use to render the editor. + /// Gets the view to use to render the editor. fixme - but that's for the VALUE really? /// public string View { get; } + + /// + /// Gets or sets the type of the edited value. + /// + /// Must be a valid value. + public string ValueType { + get => _valueType; + set + { + if (string.IsNullOrWhiteSpace(value)) throw new ArgumentNullOrEmptyException(nameof(value)); + if (!ValueTypes.IsValue(value)) throw new ArgumentOutOfRangeException(nameof(value), $"Not a valid {typeof(ValueTypes)} value."); + _valueType = value; + } + } + + /// + /// 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; } = Constants.Icons.PropertyEditor; + + /// + /// Gets or sets an optional group. + /// + /// The group can be used for example to group the editors by category. + public string Group { get; set; } = "common"; + + /// + /// Gets or sets a value indicating whether the value editor is deprecated. + /// + /// A deprecated editor is still supported but not proposed in the UI. + public bool IsDeprecated { get; set; } } } \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/ValueEditor.cs b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs similarity index 96% rename from src/Umbraco.Core/PropertyEditors/ValueEditor.cs rename to src/Umbraco.Core/PropertyEditors/DataValueEditor.cs index f56842f912..34f2508587 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs @@ -14,25 +14,25 @@ using Umbraco.Core.Services; namespace Umbraco.Core.PropertyEditors { /// - /// Represents a value editor for content properties. + /// Represents a value editor. /// - public class ValueEditor : IPropertyValueEditor + public class DataValueEditor : IDataValueEditor { private string _view; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public ValueEditor() // for tests, and manifest + public DataValueEditor() // for tests, and manifest { ValueType = ValueTypes.String; Validators = new List(); } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public ValueEditor(string view, params IValueValidator[] validators) // not used + public DataValueEditor(string view, params IValueValidator[] validators) // not used : this() { View = view; @@ -40,9 +40,9 @@ namespace Umbraco.Core.PropertyEditors } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public ValueEditor(ValueEditorAttribute attribute) + public DataValueEditor(DataEditorAttribute attribute) : this() { if (attribute == null) return; @@ -240,7 +240,7 @@ namespace Umbraco.Core.PropertyEditors var result = TryConvertValueToCrlType(editorValue.Value); if (result.Success == false) { - Current.Logger.Warn("The value " + editorValue.Value + " cannot be converted to the type " + ValueTypes.ToStorageType(ValueType)); + Current.Logger.Warn("The value " + editorValue.Value + " cannot be converted to the type " + ValueTypes.ToStorageType(ValueType)); return null; } return result.Result; diff --git a/src/Umbraco.Core/PropertyEditors/IConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/IConfigurationEditor.cs new file mode 100644 index 0000000000..0bbd42a966 --- /dev/null +++ b/src/Umbraco.Core/PropertyEditors/IConfigurationEditor.cs @@ -0,0 +1,56 @@ +using System.Collections.Generic; + +namespace Umbraco.Core.PropertyEditors +{ + /// + /// Represents an editor for editing the configuration of editors. + /// + public interface IConfigurationEditor + { + /// + /// Gets the fields. + /// + List Fields { get; } + + /// + /// Gets the default configuration. + /// + IDictionary DefaultConfiguration { get; } + + /// + /// Determines whether a configuration object is of the type expected by the configuration editor. + /// + bool IsConfiguration(object obj); + + // notes + // ToConfigurationEditor returns a dictionary, and FromConfigurationEditor accepts a dictionary. + // this is due to the way our front-end editors work, see DataTypeController.PostSave + // and DataTypeConfigurationFieldDisplayResolver - we are not going to change it now. + + /// + /// Converts the serialized database value into the actual configuration object. + /// + /// Converting the configuration object to the serialized database value is + /// achieved by simply serializing the configuration. + object FromDatabase(string configurationJson); + + /// + /// Converts the values posted by the configuration editor into the actual configuration object. + /// + /// The values posted by the configuration editor. + /// The current configuration object. + object FromConfigurationEditor(Dictionary editorValues, object configuration); + + /// + /// Converts the configuration object to values for the configuration editor. + /// + /// The configuration. + Dictionary ToConfigurationEditor(object configuration); + + /// + /// Converts the configuration object to values for the value editror. + /// + /// The configuration. + Dictionary ToValueEditor(object configuration); + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/IConfiguredDataEditor.cs b/src/Umbraco.Core/PropertyEditors/IConfiguredDataEditor.cs new file mode 100644 index 0000000000..08eaf9697d --- /dev/null +++ b/src/Umbraco.Core/PropertyEditors/IConfiguredDataEditor.cs @@ -0,0 +1,13 @@ +namespace Umbraco.Core.PropertyEditors +{ + /// + /// Represents a data editor which can be configured. + /// + public interface IConfiguredDataEditor : IDataEditor + { + /// + /// Gets the editor to edit the value editor configuration. + /// + IConfigurationEditor ConfigurationEditor { get; } // fixme should be a method - but, deserialization? + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/IDataEditor.cs b/src/Umbraco.Core/PropertyEditors/IDataEditor.cs new file mode 100644 index 0000000000..639bd4ce49 --- /dev/null +++ b/src/Umbraco.Core/PropertyEditors/IDataEditor.cs @@ -0,0 +1,50 @@ +using System.Collections.Generic; +using Umbraco.Core.Composing; + +namespace Umbraco.Core.PropertyEditors +{ + /// + /// Represents a data editor. + /// + /// This is the base interface for parameter and property editors. + public interface IDataEditor : IDiscoverable + { + /// + /// Gets the alias of the editor. + /// + string Alias { get; } + + /// + /// Gets the type of the editor. + /// + /// An editor can be a property value editor, or a parameter editor. + EditorType Type { get; } + + /// + /// Gets the name of the editor. + /// + string Name { get; } + + /// + /// Gets the icon of the editor. + /// + /// Can be used to display editors when presenting them. + string Icon { get; } + + /// + /// Gets the group of the editor. + /// + /// Can be used to organize editors when presenting them. + string Group { get; } + + /// + /// Gets the value editor. + /// + IDataValueEditor ValueEditor { get; } // fixme should be a method - but, deserialization? + + /// + /// Gets the configuration for the value editor. + /// + IDictionary DefaultConfiguration { get; } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/IValueEditor.cs b/src/Umbraco.Core/PropertyEditors/IDataValueEditor.cs similarity index 71% rename from src/Umbraco.Core/PropertyEditors/IValueEditor.cs rename to src/Umbraco.Core/PropertyEditors/IDataValueEditor.cs index 675619682c..07a684486a 100644 --- a/src/Umbraco.Core/PropertyEditors/IValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/IDataValueEditor.cs @@ -1,45 +1,53 @@ -using System.Collections.Generic; -using System.Xml.Linq; -using Umbraco.Core.Models; -using Umbraco.Core.Models.Editors; -using Umbraco.Core.Services; - -namespace Umbraco.Core.PropertyEditors -{ - /// - /// Represents an editor for editing values. - /// - public interface IValueEditor - { - /// - /// Gets the editor view. - /// - string View { get; } - - /// - /// Gets the type of the value. - /// - /// The value has to be a valid value. - string ValueType { get; set; } - } - - // fixme - public interface IPropertyValueEditor : IValueEditor - { - // fixme services should be injected! - object ConvertEditorToDb(ContentPropertyData editorValue, object currentValue); - object ConvertDbToEditor(Property property, PropertyType propertyType, IDataTypeService dataTypeService); - IEnumerable ConvertDbToXml(Property property, IDataTypeService dataTypeService, ILocalizationService localizationService, bool published); - XNode ConvertDbToXml(PropertyType propertyType, object value, IDataTypeService dataTypeService); - string ConvertDbToString(PropertyType propertyType, object value, IDataTypeService dataTypeService); - - List Validators { get; } - - bool IsReadOnly { get; } - bool HideLabel { get; } - - // fixme what are these? - ManifestValidator RequiredValidator { get; } - ManifestValidator RegexValidator { get; } - } -} +using System.Collections.Generic; +using System.Xml.Linq; +using Umbraco.Core.Models; +using Umbraco.Core.Models.Editors; +using Umbraco.Core.Services; + +namespace Umbraco.Core.PropertyEditors +{ + /// + /// Represents an editor for editing data values. + /// + /// This is the base interface for parameter and property value editors. + public interface IDataValueEditor + { + /// + /// Gets the editor view. + /// + string View { get; } + + /// + /// Gets the type of the value. + /// + /// The value has to be a valid value. + string ValueType { get; set; } + + /// + /// Gets a value indicating whether the edited value is read-only. + /// + bool IsReadOnly { get; } + + /// + /// Gets a value indicating whether to display the associated label. + /// + bool HideLabel { get; } + + /// + /// Gets the validators to use to validate the edited value. + /// + List Validators { get; } + + // fixme what are these? + ManifestValidator RequiredValidator { get; } + ManifestValidator RegexValidator { get; } + + // fixme services should be injected! + // fixme document + object ConvertEditorToDb(ContentPropertyData editorValue, object currentValue); + object ConvertDbToEditor(Property property, PropertyType propertyType, IDataTypeService dataTypeService); + IEnumerable ConvertDbToXml(Property property, IDataTypeService dataTypeService, ILocalizationService localizationService, bool published); + XNode ConvertDbToXml(PropertyType propertyType, object value, IDataTypeService dataTypeService); + string ConvertDbToString(PropertyType propertyType, object value, IDataTypeService dataTypeService); + } +} diff --git a/src/Umbraco.Core/PropertyEditors/IParameterEditor.cs b/src/Umbraco.Core/PropertyEditors/IParameterEditor.cs deleted file mode 100644 index 30f4be9b5f..0000000000 --- a/src/Umbraco.Core/PropertyEditors/IParameterEditor.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Collections.Generic; -using Umbraco.Core.Composing; - -namespace Umbraco.Core.PropertyEditors -{ - public interface IParameterEditor : IDiscoverable - { - /// - /// Gets the unique identifier of the editor. - /// - string Alias { get; } - - /// - /// Gets the name of the editor. - /// - string Name { get; } - - /// - /// Allows a parameter editor to be re-used based on the configuration specified. FIXME WTF?! - /// - IDictionary Configuration { get; } - - IValueEditor ValueEditor { get; } - } -} diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditor.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditor.cs deleted file mode 100644 index 2e52c2703c..0000000000 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditor.cs +++ /dev/null @@ -1,104 +0,0 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; - -namespace Umbraco.Core.PropertyEditors -{ - /// - /// Basic definition of a macro parameter editor - /// - public class ParameterEditor : IParameterEditor - { - private readonly ParameterEditorAttribute _attribute; - - private ParameterValueEditor _valueEditor; - private ParameterValueEditor _valueEditorAssigned; - - /// - /// The constructor will setup the property editor based on the attribute if one is found - /// - public ParameterEditor() - { - Configuration = new Dictionary(); - - // fixme ParameterEditorAttribute is AllowMultiple - // then how can this ever make sense? - // only DropDownMultiplePropertyEditor has multiple [ParameterEditor] - // is exactly the same in v7 now - // makes no sense at all?! - - // assign properties based on the attribute, if it is found - _attribute = GetType().GetCustomAttribute(false); - if (_attribute == null) return; - - Alias = _attribute.Alias; - Name = _attribute.Name; - } - - /// - /// The id of the property editor - /// - [JsonProperty("alias", Required = Required.Always)] - public string Alias { get; internal set; } - - /// - /// The name of the property editor - /// - [JsonProperty("name", Required = Required.Always)] - public string Name { get; internal set; } - - /// - /// Allows a parameter editor to be re-used based on the configuration specified. - /// - [JsonProperty("config")] - public IDictionary Configuration { get; set; } - - /// - /// Gets or sets the value editor. - /// - /// - /// If an instance of a value editor is assigned to the property, - /// then this instance is returned when getting the property value. Otherwise, a - /// new instance is created by CreateValueEditor. - /// The instance created by CreateValueEditor is not cached, i.e. - /// a new instance is created each time the property value is retrieved. - /// The property is marked as a Json property with ObjectCreationHandling - /// set to Replace in order to prevent the Json deserializer to retrieve the - /// value of the property before setting it. - /// - [JsonProperty("editor")] - public ParameterValueEditor ValueEditor - { - get => _valueEditor ?? (_valueEditor = CreateValueEditor()); - set - { - _valueEditorAssigned = value; - _valueEditor = null; - } - } - - [JsonIgnore] - IValueEditor IParameterEditor.ValueEditor => ValueEditor; // fixme - because we must, but - bah - - /// - /// Creates a value editor instance - /// - /// - protected virtual ParameterValueEditor CreateValueEditor() - { - // handle assigned editor - if (_valueEditorAssigned != null) - return _valueEditorAssigned; - - // create a new editor - var editor = new ParameterValueEditor(); - - var view = _attribute?.View; - if (string.IsNullOrWhiteSpace(view)) - throw new InvalidOperationException("The editor does not specify a view."); - editor.View = view; - - return editor; - } - } -} diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditorAttribute.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditorAttribute.cs deleted file mode 100644 index b870747bd8..0000000000 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditorAttribute.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; - -namespace Umbraco.Core.PropertyEditors -{ - /// - /// Marks a class that represents a data editor. - /// - [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] // fixme allow multiple?! - public sealed class ParameterEditorAttribute : DataEditorAttribute - { - /// - /// Initializes a new instance of the class. - /// - /// The unique identifier of the editor. - /// The friendly name of the editor. - public ParameterEditorAttribute(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 ParameterEditorAttribute(string alias, string name, string view) - : base(alias, name, view) - { } - } -} diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditorCollection.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditorCollection.cs index ca966f9c9f..f4380c41f6 100644 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditorCollection.cs +++ b/src/Umbraco.Core/PropertyEditors/ParameterEditorCollection.cs @@ -4,81 +4,17 @@ using Umbraco.Core.Composing; namespace Umbraco.Core.PropertyEditors { - // fixme - now - // this collection is maintained but never used - yes! never injected, - // but Current.ParameterEditors is used - // - in MacroMapperProfile - // - in editMacro.aspx - // this is providing parameter editors for macros - // what's an IParameterEditor? - // - // fixme - now - // - also, grid editor - // - sort out the editors hierarchy - // - then prevalues! - // - // namespace: Umbraco.Core.DataEditors - // .Validators - // .Editors - // .ValueConverters - // - // IDataEditor - // .Alias (unique identifier) - // .Name - // .IsPropertyValueEditor - // .IsMacroParameterEditor - // .ParseConfiguration(string config) : object - // - // I - // .Icon - // .Group - // .IsDeprecated - // .DefaultConfiguration : object - // - // DataEditor - // .ValueEditor : IValueEditor - // .View : string - // .ConfigurationEditor : IDataEditorConfigurationEditor - // - // IDataType - // .EditorAlias - // .DataStorage (DataStorageType.Text, .Varchar, .Int, ...) - // .Configuration : object - // - // ParameterValueEditor : IValueEditor - // .View : string - // - // PropertyValueEditor : IValueEditor - // .View : string - // .HideLabel : bool - // .ValueType (ValueTypes.Xml, .String...) - // .Validators : IPropertyValidator* - // .convert... - // - // IDataEditorConfigurationEditor - // .Fields : DataEditorConfigurationField* - // .FromEditor() - should receive an JObject - need to convert to true configuration - // .ToEditor() - in most cases, just pass the configuration object - // - // load - // read config field as string from db - // read alias field as string from db - // find data editor corresponding to alias - // not found = deserialize config as IDictionary - // else = use editor to deserialize configuration - // PROBLEM should be a POCO not a dictionary anymore - - public class ParameterEditorCollection : BuilderCollectionBase + public class ParameterEditorCollection : BuilderCollectionBase { - public ParameterEditorCollection(IEnumerable items) + public ParameterEditorCollection(IEnumerable items) : base(items) { } // note: virtual so it can be mocked - public virtual IParameterEditor this[string alias] + public virtual IDataEditor this[string alias] => this.SingleOrDefault(x => x.Alias == alias); - public virtual bool TryGet(string alias, out IParameterEditor editor) + public virtual bool TryGet(string alias, out IDataEditor editor) { editor = this.FirstOrDefault(x => x.Alias == alias); return editor != null; diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditorCollectionBuilder.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditorCollectionBuilder.cs index 824d177541..52a447eb33 100644 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditorCollectionBuilder.cs +++ b/src/Umbraco.Core/PropertyEditors/ParameterEditorCollectionBuilder.cs @@ -6,7 +6,7 @@ using Umbraco.Core.Manifest; namespace Umbraco.Core.PropertyEditors { - public class ParameterEditorCollectionBuilder : LazyCollectionBuilderBase + public class ParameterEditorCollectionBuilder : LazyCollectionBuilderBase { private readonly ManifestParser _manifestParser; @@ -18,24 +18,11 @@ namespace Umbraco.Core.PropertyEditors protected override ParameterEditorCollectionBuilder This => this; - protected override IEnumerable CreateItems(params object[] args) + protected override IEnumerable CreateItems(params object[] args) { - //return base.CreateItems(args).Union(_manifestBuilder.PropertyEditors); - - // the buider's producer returns all IParameterEditor implementations - // this includes classes inheriting from both PropertyEditor and ParameterEditor - // but only some PropertyEditor inheritors are also parameter editors - // - // return items, - // that are NOT PropertyEditor OR that also have IsParameterEditor set to true - // union all manifest's parameter editors - // union all manifest's property editors that are ALSO parameter editors - return base.CreateItems(args) - .Where(x => (x is PropertyEditor) == false || ((PropertyEditor) x).IsParameterEditor) - .Union(_manifestParser.Manifest.ParameterEditors) - .Union(_manifestParser.Manifest.PropertyEditors.Where(x => x.IsParameterEditor)) - .ToList(); + .Where(x => (x.Type & EditorType.MacroParameter) > 0) + .Union(_manifestParser.Manifest.ParameterEditors); } } } diff --git a/src/Umbraco.Core/PropertyEditors/ParameterValueEditor.cs b/src/Umbraco.Core/PropertyEditors/ParameterValueEditor.cs deleted file mode 100644 index c28bc64f33..0000000000 --- a/src/Umbraco.Core/PropertyEditors/ParameterValueEditor.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Umbraco.Core.IO; - -namespace Umbraco.Core.PropertyEditors -{ - // fixme - can we kill this and use "ValueEditor" for both macro and all? - - /// - /// Represents a value editor for macro parameters. - /// - public class ParameterValueEditor : IValueEditor - { - private string _view; - - /// - /// Initializes a new instance of the class. - /// - public ParameterValueEditor() - { } - - /// - /// Initializes a new instance of the class. - /// - public ParameterValueEditor(string view) - : this() - { - View = view; - } - - /// - /// Gets or sets the editor view. - /// - public string View - { - get => _view; - set => _view = IOHelper.ResolveVirtualUrl(value); - } - - /// - public string ValueType { get; set; } - } -} diff --git a/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs b/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs index 9a10613dbb..e408ae7139 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs @@ -4,17 +4,17 @@ using Umbraco.Core.Composing; namespace Umbraco.Core.PropertyEditors { - public class PropertyEditorCollection : BuilderCollectionBase + public class PropertyEditorCollection : BuilderCollectionBase { - public PropertyEditorCollection(IEnumerable items) + public PropertyEditorCollection(IEnumerable items) : base(items) { } // note: virtual so it can be mocked - public virtual PropertyEditor this[string alias] + public virtual IConfiguredDataEditor this[string alias] => this.SingleOrDefault(x => x.Alias == alias); - public virtual bool TryGet(string alias, out PropertyEditor editor) + public virtual bool TryGet(string alias, out IConfiguredDataEditor editor) { editor = this.FirstOrDefault(x => x.Alias == alias); return editor != null; diff --git a/src/Umbraco.Core/PropertyEditors/PropertyEditorCollectionBuilder.cs b/src/Umbraco.Core/PropertyEditors/PropertyEditorCollectionBuilder.cs index cd91fa7077..ef798f768c 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyEditorCollectionBuilder.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyEditorCollectionBuilder.cs @@ -6,7 +6,7 @@ using Umbraco.Core.Manifest; namespace Umbraco.Core.PropertyEditors { - public class PropertyEditorCollectionBuilder : LazyCollectionBuilderBase + public class PropertyEditorCollectionBuilder : LazyCollectionBuilderBase { private readonly ManifestParser _manifestParser; @@ -18,9 +18,11 @@ namespace Umbraco.Core.PropertyEditors protected override PropertyEditorCollectionBuilder This => this; - protected override IEnumerable CreateItems(params object[] args) + protected override IEnumerable CreateItems(params object[] args) { - return base.CreateItems(args).Union(_manifestParser.Manifest.PropertyEditors); + return base.CreateItems(args) + .Where(x => (x.Type & EditorType.PropertyValue) > 0) + .Union(_manifestParser.Manifest.PropertyEditors); } } } diff --git a/src/Umbraco.Core/PropertyEditors/PropertyEditorTagsExtensions.cs b/src/Umbraco.Core/PropertyEditors/PropertyEditorTagsExtensions.cs index cd818b3447..8f01bcab5a 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyEditorTagsExtensions.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyEditorTagsExtensions.cs @@ -1,20 +1,20 @@ namespace Umbraco.Core.PropertyEditors { /// - /// Provides extension methods for the class to manage tags. + /// Provides extension methods for the interface to manage tags. /// public static class PropertyEditorTagsExtensions { /// /// Determines whether an editor supports tags. /// - public static bool IsTagsEditor(this PropertyEditor editor) + public static bool IsTagsEditor(this IDataEditor editor) => editor?.GetType().GetCustomAttribute(false) != null; /// /// Gets the tags configuration attribute of an editor. /// - public static TagsPropertyEditorAttribute GetTagAttribute(this PropertyEditor editor) + public static TagsPropertyEditorAttribute GetTagAttribute(this IDataEditor editor) => editor?.GetType().GetCustomAttribute(false); } } diff --git a/src/Umbraco.Core/PropertyEditors/ValueEditorAttribute.cs b/src/Umbraco.Core/PropertyEditors/ValueEditorAttribute.cs deleted file mode 100644 index 25afe2d628..0000000000 --- a/src/Umbraco.Core/PropertyEditors/ValueEditorAttribute.cs +++ /dev/null @@ -1,94 +0,0 @@ -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; - - /// - /// Gets or sets a value indicating whether the value editor is deprecated. - /// - /// A deprecated editor does not show up in the list of available editors for a datatype, - /// unless it is the current editor for the datatype. - public bool IsDeprecated { get; set; } - - /// - /// 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/PropertyEditors/VoidEditor.cs b/src/Umbraco.Core/PropertyEditors/VoidEditor.cs index 8da70c995d..657f8af5fe 100644 --- a/src/Umbraco.Core/PropertyEditors/VoidEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/VoidEditor.cs @@ -10,7 +10,7 @@ namespace Umbraco.Core.PropertyEditors /// editor is available. Not to be used otherwise. Not discovered, and therefore /// not part of the editors collection. [HideFromTypeFinder] - public class VoidEditor : PropertyEditor + public class VoidEditor : ConfiguredDataEditor { /// /// Initializes a new instance of the class. diff --git a/src/Umbraco.Core/Runtime/CoreRuntimeComponent.cs b/src/Umbraco.Core/Runtime/CoreRuntimeComponent.cs index 9265b30655..d7712c10a2 100644 --- a/src/Umbraco.Core/Runtime/CoreRuntimeComponent.cs +++ b/src/Umbraco.Core/Runtime/CoreRuntimeComponent.cs @@ -67,11 +67,11 @@ namespace Umbraco.Core.Runtime .Add() .Add(); + // both are initialized with data editors, and filter them out composition.Container.RegisterCollectionBuilder() - .Add(factory => factory.GetInstance().GetPropertyEditors()); - + .Add(factory => factory.GetInstance().GetDataEditors()); composition.Container.RegisterCollectionBuilder() - .Add(factory => factory.GetInstance().GetParameterEditors()); + .Add(factory => factory.GetInstance().GetDataEditors()); // register a server registrar, by default it's the db registrar unless the dev // has the legacy dist calls enabled - fixme - should obsolete the legacy thing diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 1f4f45ccfa..ac7bc37896 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -336,7 +336,10 @@ + + + @@ -513,8 +516,7 @@ - - + @@ -1186,29 +1188,25 @@ - - + - - + - - - + - + diff --git a/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs b/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs index b9eac41784..60f545d1b4 100644 --- a/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs +++ b/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs @@ -71,7 +71,7 @@ namespace Umbraco.Tests.Models.Mapping base.Compose(); // create and register a fake property editor collection to return fake property editors - var editors = new PropertyEditor[] { new TextboxPropertyEditor(Mock.Of()), }; + var editors = new ConfiguredDataEditor[] { new TextboxPropertyEditor(Mock.Of()), }; _editorsMock = new Mock(new object[] { editors }); _editorsMock.Setup(x => x[It.IsAny()]).Returns(editors[0]); Container.RegisterSingleton(f => _editorsMock.Object); diff --git a/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs b/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs index 536786f597..dfa7628858 100644 --- a/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs +++ b/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs @@ -30,7 +30,7 @@ namespace Umbraco.Tests.Models.Mapping } [ValueEditor("Test.Test", "Test", "~/Test.html")] - public class TestPropertyEditor : PropertyEditor + public class TestPropertyEditor : ConfiguredDataEditor { /// /// The constructor will setup the property editor based on the attribute if one is found diff --git a/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs index 1c5736c698..54eba023d2 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs @@ -48,7 +48,7 @@ namespace Umbraco.Tests.Persistence.Repositories TemplateRepository tr; var ctRepository = CreateRepository(scopeAccessor, out contentTypeRepository, out tr); - var editors = new PropertyEditorCollection(Enumerable.Empty()); + var editors = new PropertyEditorCollection(Enumerable.Empty()); dtdRepository = new DataTypeRepository(scopeAccessor, cacheHelper, new Lazy(() => editors), Logger); return ctRepository; } diff --git a/src/Umbraco.Tests/Persistence/Repositories/PartialViewRepositoryTests.cs b/src/Umbraco.Tests/Persistence/Repositories/PartialViewRepositoryTests.cs index b9503277d7..3ae3e6b887 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/PartialViewRepositoryTests.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/PartialViewRepositoryTests.cs @@ -29,7 +29,7 @@ namespace Umbraco.Tests.Persistence.Repositories { base.Compose(); - Container.RegisterSingleton(f => new PropertyEditorCollection(Enumerable.Empty())); + Container.RegisterSingleton(f => new PropertyEditorCollection(Enumerable.Empty())); } [Test] diff --git a/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs index 2be813d0d8..3034d0ff6c 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs @@ -37,7 +37,7 @@ namespace Umbraco.Tests.Persistence.Repositories { base.Compose(); - Container.RegisterSingleton(f => new PropertyEditorCollection(Enumerable.Empty())); + Container.RegisterSingleton(f => new PropertyEditorCollection(Enumerable.Empty())); } [Test] diff --git a/src/Umbraco.Tests/Plugins/PluginManagerTests.cs b/src/Umbraco.Tests/Plugins/PluginManagerTests.cs index 8c9bf351f6..8e9925134e 100644 --- a/src/Umbraco.Tests/Plugins/PluginManagerTests.cs +++ b/src/Umbraco.Tests/Plugins/PluginManagerTests.cs @@ -297,11 +297,11 @@ AnotherContentFinder { var types = new HashSet(); - var propEditors = new TypeLoader.TypeList(typeof (PropertyEditor), null); + var propEditors = new TypeLoader.TypeList(typeof (ConfiguredDataEditor), null); propEditors.Add(typeof(LabelPropertyEditor)); types.Add(propEditors); - var found = types.SingleOrDefault(x => x.BaseType == typeof (PropertyEditor) && x.AttributeType == null); + var found = types.SingleOrDefault(x => x.BaseType == typeof (ConfiguredDataEditor) && x.AttributeType == null); Assert.IsNotNull(found); diff --git a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs index 165130fef3..98ea6253f3 100644 --- a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs +++ b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs @@ -43,7 +43,7 @@ namespace Umbraco.Tests.PropertyEditors var prop = new Property(1, new PropertyType("test", ValueStorageType.Nvarchar)); prop.SetValue(value); - var valueEditor = new ValueEditor + var valueEditor = new DataValueEditor { ValueType = ValueTypes.String }; @@ -59,7 +59,7 @@ namespace Umbraco.Tests.PropertyEditors [TestCase("DATETIME", "", null)] //test empty string for date public void Value_Editor_Can_Convert_To_Clr_Type(string valueType, string val, object expected) { - var valueEditor = new ValueEditor + var valueEditor = new DataValueEditor { ValueType = valueType }; @@ -74,7 +74,7 @@ namespace Umbraco.Tests.PropertyEditors [Test] public void Value_Editor_Can_Convert_To_Decimal_Clr_Type() { - var valueEditor = new ValueEditor + var valueEditor = new DataValueEditor { ValueType = ValueTypes.Decimal }; @@ -87,7 +87,7 @@ namespace Umbraco.Tests.PropertyEditors [Test] public void Value_Editor_Can_Convert_To_Decimal_Clr_Type_With_Other_Separator() { - var valueEditor = new ValueEditor + var valueEditor = new DataValueEditor { ValueType = ValueTypes.Decimal }; @@ -100,7 +100,7 @@ namespace Umbraco.Tests.PropertyEditors [Test] public void Value_Editor_Can_Convert_To_Decimal_Clr_Type_With_Empty_String() { - var valueEditor = new ValueEditor + var valueEditor = new DataValueEditor { ValueType = ValueTypes.Decimal }; @@ -113,7 +113,7 @@ namespace Umbraco.Tests.PropertyEditors [Test] public void Value_Editor_Can_Convert_To_Date_Clr_Type() { - var valueEditor = new ValueEditor + var valueEditor = new DataValueEditor { ValueType = ValueTypes.Date }; @@ -133,7 +133,7 @@ namespace Umbraco.Tests.PropertyEditors var prop = new Property(1, new PropertyType("test", ValueStorageType.Nvarchar)); prop.SetValue(val); - var valueEditor = new ValueEditor + var valueEditor = new DataValueEditor { ValueType = valueType }; @@ -146,7 +146,7 @@ namespace Umbraco.Tests.PropertyEditors public void Value_Editor_Can_Serialize_Decimal_Value() { var value = 12.34M; - var valueEditor = new ValueEditor + var valueEditor = new DataValueEditor { ValueType = ValueTypes.Decimal }; @@ -161,7 +161,7 @@ namespace Umbraco.Tests.PropertyEditors [Test] public void Value_Editor_Can_Serialize_Decimal_Value_With_Empty_String() { - var valueEditor = new ValueEditor + var valueEditor = new DataValueEditor { ValueType = ValueTypes.Decimal }; @@ -177,7 +177,7 @@ namespace Umbraco.Tests.PropertyEditors public void Value_Editor_Can_Serialize_Date_Value() { var now = DateTime.Now; - var valueEditor = new ValueEditor + var valueEditor = new DataValueEditor { ValueType = ValueTypes.Date }; diff --git a/src/Umbraco.Tests/Published/NestedContentTests.cs b/src/Umbraco.Tests/Published/NestedContentTests.cs index 38832170a3..a11182ebc2 100644 --- a/src/Umbraco.Tests/Published/NestedContentTests.cs +++ b/src/Umbraco.Tests/Published/NestedContentTests.cs @@ -34,7 +34,7 @@ namespace Umbraco.Tests.Published PropertyEditorCollection editors = null; var editor = new NestedContentPropertyEditor(logger, new Lazy(() => editors)); - editors = new PropertyEditorCollection(new PropertyEditor[] { editor }); + editors = new PropertyEditorCollection(new ConfiguredDataEditor[] { editor }); var dataType1 = new DataType(editor) { diff --git a/src/Umbraco.Tests/Services/Importing/PackageImportTests.cs b/src/Umbraco.Tests/Services/Importing/PackageImportTests.cs index 9d3253e9cc..084022c36a 100644 --- a/src/Umbraco.Tests/Services/Importing/PackageImportTests.cs +++ b/src/Umbraco.Tests/Services/Importing/PackageImportTests.cs @@ -19,7 +19,7 @@ namespace Umbraco.Tests.Services.Importing public class PackageImportTests : TestWithSomeContentBase { [HideFromTypeFinder] - public class Editor1 : PropertyEditor + public class Editor1 : ConfiguredDataEditor { public Editor1(ILogger logger) : base(logger) @@ -29,7 +29,7 @@ namespace Umbraco.Tests.Services.Importing } [HideFromTypeFinder] - public class Editor2 : PropertyEditor + public class Editor2 : ConfiguredDataEditor { public Editor2(ILogger logger) : base(logger) diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects.cs b/src/Umbraco.Tests/TestHelpers/TestObjects.cs index 1256a7a130..62125cc64d 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects.cs @@ -177,7 +177,7 @@ namespace Umbraco.Tests.TestHelpers GetRepo(c))); var macroService = GetLazyService(container, c => new MacroService(scopeProvider, logger, eventMessagesFactory, GetRepo(c), GetRepo(c))); - var packagingService = GetLazyService(container, c => new PackagingService(logger, contentService.Value, contentTypeService.Value, mediaService.Value, macroService.Value, dataTypeService.Value, fileService.Value, localizationService.Value, entityService.Value, userService.Value, scopeProvider, urlSegmentProviders, GetRepo(c), GetRepo(c), new PropertyEditorCollection(Enumerable.Empty()))); + var packagingService = GetLazyService(container, c => new PackagingService(logger, contentService.Value, contentTypeService.Value, mediaService.Value, macroService.Value, dataTypeService.Value, fileService.Value, localizationService.Value, entityService.Value, userService.Value, scopeProvider, urlSegmentProviders, GetRepo(c), GetRepo(c), new PropertyEditorCollection(Enumerable.Empty()))); var relationService = GetLazyService(container, c => new RelationService(scopeProvider, logger, eventMessagesFactory, entityService.Value, GetRepo(c), GetRepo(c))); var treeService = GetLazyService(container, c => new ApplicationTreeService(logger, cache)); var tagService = GetLazyService(container, c => new TagService(scopeProvider, logger, eventMessagesFactory, GetRepo(c))); diff --git a/src/Umbraco.Web/Editors/DataTypeController.cs b/src/Umbraco.Web/Editors/DataTypeController.cs index 8623545046..a8d3bcb65e 100644 --- a/src/Umbraco.Web/Editors/DataTypeController.cs +++ b/src/Umbraco.Web/Editors/DataTypeController.cs @@ -147,7 +147,7 @@ namespace Umbraco.Web.Editors if (dataTypeId == -1) { //this is a new data type, so just return the field editors with default values - return Mapper.Map>(propEd); + return Mapper.Map>(propEd); } //we have a data type associated @@ -167,7 +167,7 @@ namespace Umbraco.Web.Editors } //these are new pre-values, so just return the field editors with default values - return Mapper.Map>(propEd); + return Mapper.Map>(propEd); } /// diff --git a/src/Umbraco.Web/Models/ContentEditing/ContentPropertyBasic.cs b/src/Umbraco.Web/Models/ContentEditing/ContentPropertyBasic.cs index ed340ae7cf..52f7db8592 100644 --- a/src/Umbraco.Web/Models/ContentEditing/ContentPropertyBasic.cs +++ b/src/Umbraco.Web/Models/ContentEditing/ContentPropertyBasic.cs @@ -35,7 +35,7 @@ namespace Umbraco.Web.Models.ContentEditing /// Used internally during model mapping /// [IgnoreDataMember] - internal PropertyEditor PropertyEditor { get; set; } + internal IConfiguredDataEditor PropertyEditor { get; set; } } } diff --git a/src/Umbraco.Web/Models/ContentEditing/DataTypeSave.cs b/src/Umbraco.Web/Models/ContentEditing/DataTypeSave.cs index dd671ab77e..47873fe751 100644 --- a/src/Umbraco.Web/Models/ContentEditing/DataTypeSave.cs +++ b/src/Umbraco.Web/Models/ContentEditing/DataTypeSave.cs @@ -47,7 +47,7 @@ namespace Umbraco.Web.Models.ContentEditing /// Gets or sets the property editor. /// [IgnoreDataMember] - internal PropertyEditor PropertyEditor { get; set; } + internal ConfiguredDataEditor PropertyEditor { get; set; } } } diff --git a/src/Umbraco.Web/Models/Mapping/ContentPropertyDisplayConverter.cs b/src/Umbraco.Web/Models/Mapping/ContentPropertyDisplayConverter.cs index d044669ac8..367fc89b1b 100644 --- a/src/Umbraco.Web/Models/Mapping/ContentPropertyDisplayConverter.cs +++ b/src/Umbraco.Web/Models/Mapping/ContentPropertyDisplayConverter.cs @@ -33,7 +33,7 @@ namespace Umbraco.Web.Models.Mapping // but, this is the ONLY place where it's assigned? it is also the only place where // .HideLabel is used - and basically all the rest kinda never depends on config, // but... it should? - var ve = (ValueEditor) valEditor; + var ve = (DataValueEditor) valEditor; ve.Configuration = config; //set the display properties after mapping diff --git a/src/Umbraco.Web/Models/Mapping/DataTypeConfigurationFieldDisplayResolver.cs b/src/Umbraco.Web/Models/Mapping/DataTypeConfigurationFieldDisplayResolver.cs index 9f71702d2c..d8fd8e44e4 100644 --- a/src/Umbraco.Web/Models/Mapping/DataTypeConfigurationFieldDisplayResolver.cs +++ b/src/Umbraco.Web/Models/Mapping/DataTypeConfigurationFieldDisplayResolver.cs @@ -36,10 +36,16 @@ namespace Umbraco.Web.Models.Mapping /// public IEnumerable Resolve(IDataType dataType) { - PropertyEditor editor = null; - if (!string.IsNullOrWhiteSpace(dataType.EditorAlias) && !Current.PropertyEditors.TryGet(dataType.EditorAlias, out editor)) - throw new InvalidOperationException($"Could not find a property editor with alias \"{dataType.EditorAlias}\"."); - + ConfiguredDataEditor editor = null; + if (!string.IsNullOrWhiteSpace(dataType.EditorAlias)) + { + if (!Current.PropertyEditors.TryGet(dataType.EditorAlias, out var e1)) + throw new InvalidOperationException($"Could not find a property editor with alias \"{dataType.EditorAlias}\"."); + if (!(e1 is ConfiguredDataEditor e2)) + throw new InvalidOperationException($"Property editor with alias \"{dataType.EditorAlias}\" is not configurable."); + editor = e2; + } + var configuration = dataType.Configuration; Dictionary configurationDictionary = null; var fields = Array.Empty(); diff --git a/src/Umbraco.Web/Models/Mapping/DataTypeMapperProfile.cs b/src/Umbraco.Web/Models/Mapping/DataTypeMapperProfile.cs index d24644d89a..847af79e65 100644 --- a/src/Umbraco.Web/Models/Mapping/DataTypeMapperProfile.cs +++ b/src/Umbraco.Web/Models/Mapping/DataTypeMapperProfile.cs @@ -23,7 +23,7 @@ namespace Umbraco.Web.Models.Mapping var configurationDisplayResolver = new DataTypeConfigurationFieldDisplayResolver(); var databaseTypeResolver = new DatabaseTypeResolver(); - CreateMap(); + CreateMap(); // map the standard properties, not the values CreateMap() @@ -36,7 +36,7 @@ namespace Umbraco.Web.Models.Mapping Constants.DataTypes.DefaultMembersListView }; - CreateMap() + CreateMap() .ForMember(dest => dest.Udi, opt => opt.Ignore()) .ForMember(dest => dest.HasPrevalues, opt => opt.Ignore()) .ForMember(dest => dest.IsSystemDataType, opt => opt.Ignore()) @@ -105,7 +105,7 @@ namespace Umbraco.Web.Models.Mapping .ForMember(dest => dest.Editor, opt => opt.MapFrom(src => propertyEditors[src.EditorAlias])); //Converts a property editor to a new list of pre-value fields - used when creating a new data type or changing a data type with new pre-vals - CreateMap>() + CreateMap>() .ConvertUsing(src => { // this is a new data type, initialize default configuration diff --git a/src/Umbraco.Web/PropertyEditors/CheckBoxListPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/CheckBoxListPropertyEditor.cs index 7bfc01f9a3..6a9ec78551 100644 --- a/src/Umbraco.Web/PropertyEditors/CheckBoxListPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/CheckBoxListPropertyEditor.cs @@ -13,8 +13,8 @@ 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. /// - [ValueEditor(Constants.PropertyEditors.Aliases.CheckBoxList, "Checkbox list", "checkboxlist", Icon="icon-bulleted-list", Group="lists")] - public class CheckBoxListPropertyEditor : PropertyEditor + [DataEditor(Constants.PropertyEditors.Aliases.CheckBoxList, "Checkbox list", "checkboxlist", Icon="icon-bulleted-list", Group="lists")] + public class CheckBoxListPropertyEditor : ConfiguredDataEditor { private readonly ILocalizedTextService _textService; @@ -28,9 +28,9 @@ namespace Umbraco.Web.PropertyEditors } /// - protected override ConfigurationEditor CreateConfigurationEditor() => new ValueListConfigurationEditor(_textService); + protected override IConfigurationEditor CreateConfigurationEditor() => new ValueListConfigurationEditor(_textService); /// - protected override IPropertyValueEditor CreateValueEditor() => new PublishValuesMultipleValueEditor(false, Attribute); + protected override IDataValueEditor CreateValueEditor() => new PublishValuesMultipleValueEditor(false, Attribute); } } diff --git a/src/Umbraco.Web/PropertyEditors/ColorPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/ColorPickerPropertyEditor.cs index 075ca20c22..52f6ffe240 100644 --- a/src/Umbraco.Web/PropertyEditors/ColorPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ColorPickerPropertyEditor.cs @@ -5,8 +5,8 @@ using Umbraco.Core.Services; namespace Umbraco.Web.PropertyEditors { - [ValueEditor(Constants.PropertyEditors.Aliases.ColorPicker, "Color Picker", "colorpicker", Icon="icon-colorpicker", Group="Pickers")] - public class ColorPickerPropertyEditor : PropertyEditor + [DataEditor(Constants.PropertyEditors.Aliases.ColorPicker, "Color Picker", "colorpicker", Icon="icon-colorpicker", Group="Pickers")] + public class ColorPickerPropertyEditor : ConfiguredDataEditor { private readonly ILocalizedTextService _textService; @@ -20,6 +20,6 @@ namespace Umbraco.Web.PropertyEditors } /// - protected override ConfigurationEditor CreateConfigurationEditor() => new ColorPickerConfigurationEditor(_textService); + protected override IConfigurationEditor CreateConfigurationEditor() => new ColorPickerConfigurationEditor(_textService); } } diff --git a/src/Umbraco.Web/PropertyEditors/ContentPicker2PropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/ContentPicker2PropertyEditor.cs index 6e6afb9f75..257eebe9c6 100644 --- a/src/Umbraco.Web/PropertyEditors/ContentPicker2PropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ContentPicker2PropertyEditor.cs @@ -8,14 +8,14 @@ namespace Umbraco.Web.PropertyEditors /// /// Content property editor that stores UDI /// - [ValueEditor(Constants.PropertyEditors.Aliases.ContentPicker2Alias, "Content Picker", "contentpicker", ValueTypes.String, IsMacroParameterEditor = true, Group = "Pickers")] - public class ContentPicker2PropertyEditor : PropertyEditor + [DataEditor(Constants.PropertyEditors.Aliases.ContentPicker2Alias, EditorType.PropertyValue | EditorType.MacroParameter, "Content Picker", "contentpicker", ValueType = ValueTypes.String, Group = "Pickers")] + public class ContentPicker2PropertyEditor : ConfiguredDataEditor { public ContentPicker2PropertyEditor(ILogger logger) : base(logger) { } - protected override ConfigurationEditor CreateConfigurationEditor() + protected override IConfigurationEditor CreateConfigurationEditor() { return new ContentPickerConfigurationEditor(); } diff --git a/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs index e29284fd98..1aadf0e8fa 100644 --- a/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs @@ -5,16 +5,16 @@ using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { - [ValueEditor(Constants.PropertyEditors.Aliases.Date, "Date", "datepicker", ValueTypes.Date, Icon="icon-calendar")] - public class DatePropertyEditor : PropertyEditor + [DataEditor(Constants.PropertyEditors.Aliases.Date, "Date", "datepicker", ValueType = ValueTypes.Date, Icon="icon-calendar")] + public class DatePropertyEditor : ConfiguredDataEditor { public DatePropertyEditor(ILogger logger): base(logger) { } /// - protected override IPropertyValueEditor CreateValueEditor() => new DateValueEditor(Attribute); + protected override IDataValueEditor CreateValueEditor() => new DateValueEditor(Attribute); /// - protected override ConfigurationEditor CreateConfigurationEditor() => new DateConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new DateConfigurationEditor(); } } diff --git a/src/Umbraco.Web/PropertyEditors/DateTimePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DateTimePropertyEditor.cs index c0e9205cf9..b9d5c404cd 100644 --- a/src/Umbraco.Web/PropertyEditors/DateTimePropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DateTimePropertyEditor.cs @@ -5,19 +5,29 @@ using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { - [ValueEditor(Constants.PropertyEditors.Aliases.DateTime, "Date/Time", "datepicker", ValueType = ValueTypes.DateTime, Icon="icon-time")] - public class DateTimePropertyEditor : PropertyEditor + /// + /// Represents a date and time property editor. + /// + [DataEditor(Constants.PropertyEditors.Aliases.DateTime, "Date/Time", "datepicker", ValueType = ValueTypes.DateTime, Icon="icon-time")] + public class DateTimePropertyEditor : ConfiguredDataEditor { - public DateTimePropertyEditor(ILogger logger): base(logger) + /// + /// Initializes a new instance of the class. + /// + /// + public DateTimePropertyEditor(ILogger logger) + : base(logger) { } - protected override IPropertyValueEditor CreateValueEditor() + /// + protected override IDataValueEditor CreateValueEditor() { var editor = base.CreateValueEditor(); editor.Validators.Add(new DateTimeValidator()); return editor; } - protected override ConfigurationEditor CreateConfigurationEditor() => new DateTimeConfigurationEditor(); + /// + protected override IConfigurationEditor CreateConfigurationEditor() => new DateTimeConfigurationEditor(); } } diff --git a/src/Umbraco.Web/PropertyEditors/DateValueEditor.cs b/src/Umbraco.Web/PropertyEditors/DateValueEditor.cs index c2d366be90..b47cd6a0e5 100644 --- a/src/Umbraco.Web/PropertyEditors/DateValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DateValueEditor.cs @@ -10,9 +10,9 @@ namespace Umbraco.Web.PropertyEditors /// CUstom value editor so we can serialize with the correct date format (excluding time) /// and includes the date validator /// - internal class DateValueEditor : ValueEditor + internal class DateValueEditor : DataValueEditor { - public DateValueEditor(ValueEditorAttribute attribute) + public DateValueEditor(DataEditorAttribute attribute) : base(attribute) { Validators.Add(new DateTimeValidator()); @@ -28,6 +28,5 @@ namespace Umbraco.Web.PropertyEditors //Dates will be formatted as yyyy-MM-dd return date.Result.Value.ToString("yyyy-MM-dd"); } - } } \ No newline at end of file diff --git a/src/Umbraco.Web/PropertyEditors/DecimalPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DecimalPropertyEditor.cs index ca5876ac3d..32b347f54b 100644 --- a/src/Umbraco.Web/PropertyEditors/DecimalPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DecimalPropertyEditor.cs @@ -5,30 +5,28 @@ using Umbraco.Core.PropertyEditors.Validators; namespace Umbraco.Web.PropertyEditors { - [ValueEditor(Constants.PropertyEditors.Aliases.Decimal, "Decimal", "decimal", ValueTypes.Decimal, IsMacroParameterEditor = true)] - public class DecimalPropertyEditor : PropertyEditor + /// + /// Represents a decimal property and parameter editor. + /// + [DataEditor(Constants.PropertyEditors.Aliases.Decimal, EditorType.PropertyValue | EditorType.MacroParameter, "Decimal", "decimal", ValueType = ValueTypes.Decimal)] + public class DecimalPropertyEditor : ConfiguredDataEditor { /// - /// The constructor will setup the property editor based on the attribute if one is found + /// Initializes a new instance of the class. /// - public DecimalPropertyEditor(ILogger logger) : base(logger) - { - } + public DecimalPropertyEditor(ILogger logger) + : base(logger) + { } - /// - /// Overridden to ensure that the value is validated - /// - /// - protected override IPropertyValueEditor CreateValueEditor() + /// + protected override IDataValueEditor CreateValueEditor() { var editor = base.CreateValueEditor(); editor.Validators.Add(new DecimalValidator()); return editor; } - protected override ConfigurationEditor CreateConfigurationEditor() - { - return new DecimalConfigurationEditor(); - } + /// + protected override IConfigurationEditor CreateConfigurationEditor() => new DecimalConfigurationEditor(); } } diff --git a/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs index ae2dfdb71c..09e62bc699 100644 --- a/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using System.Collections.Generic; +using Newtonsoft.Json; using Umbraco.Core; using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; @@ -13,10 +14,7 @@ namespace Umbraco.Web.PropertyEditors /// Due to maintaining backwards compatibility this data type stores the value as a string which is a comma separated value of the /// ids of the individual items so we have logic in here to deal with that. /// - [ParameterEditor("propertyTypePickerMultiple", "Name", "textbox")] // fixme multiple parameter editor attribute?! - [ParameterEditor("contentTypeMultiple", "Name", "textbox")] - [ParameterEditor("tabPickerMultiple", "Name", "textbox")] - [ValueEditor(Constants.PropertyEditors.Aliases.DropDownListMultiple, "Dropdown list multiple", "dropdown", Group = "lists", Icon="icon-bulleted-list")] + [DataEditor(Constants.PropertyEditors.Aliases.DropDownListMultiple, "Dropdown list multiple", "dropdown", Group = "lists", Icon="icon-bulleted-list")] public class DropDownMultiplePropertyEditor : DropDownMultipleWithKeysPropertyEditor { /// @@ -27,6 +25,6 @@ namespace Umbraco.Web.PropertyEditors { } /// - protected override IPropertyValueEditor CreateValueEditor() => new PublishValuesMultipleValueEditor(false, Attribute); + protected override IDataValueEditor CreateValueEditor() => new PublishValuesMultipleValueEditor(false, Attribute); } } diff --git a/src/Umbraco.Web/PropertyEditors/DropDownMultipleWithKeysPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownMultipleWithKeysPropertyEditor.cs index da587318e2..fa3e8c40a4 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. /// - [ValueEditor(Constants.PropertyEditors.Aliases.DropdownlistMultiplePublishKeys, "Dropdown list multiple, publish keys", "dropdown", Group = "lists", Icon = "icon-bulleted-list")] + [DataEditor(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,9 +29,9 @@ namespace Umbraco.Web.PropertyEditors } /// - protected override IPropertyValueEditor CreateValueEditor() => new PublishValuesMultipleValueEditor(true, Attribute); + protected override IDataValueEditor CreateValueEditor() => new PublishValuesMultipleValueEditor(true, Attribute); /// - protected override ConfigurationEditor CreateConfigurationEditor() => new DropDownMultipleConfigurationEditor(_textService); + protected override IConfigurationEditor CreateConfigurationEditor() => new DropDownMultipleConfigurationEditor(_textService); } } diff --git a/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs index cd1162b129..0bfa14503b 100644 --- a/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs @@ -18,7 +18,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. /// - [ValueEditor(Constants.PropertyEditors.Aliases.DropDownList, "Dropdown list", "dropdown", ValueType = ValueTypes.String, Group = "lists", Icon = "icon-indent")] + [DataEditor(Constants.PropertyEditors.Aliases.DropDownList, "Dropdown list", "dropdown", ValueType = ValueTypes.String, Group = "lists", Icon = "icon-indent")] public class DropDownPropertyEditor : DropDownWithKeysPropertyEditor { /// @@ -32,6 +32,6 @@ namespace Umbraco.Web.PropertyEditors /// 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 IPropertyValueEditor CreateValueEditor() => new PublishValueValueEditor(Attribute, Logger); + protected override IDataValueEditor CreateValueEditor() => new PublishValueValueEditor(Attribute, Logger); } } diff --git a/src/Umbraco.Web/PropertyEditors/DropDownWithKeysPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownWithKeysPropertyEditor.cs index 38a8f5a232..38ce4ef8d4 100644 --- a/src/Umbraco.Web/PropertyEditors/DropDownWithKeysPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DropDownWithKeysPropertyEditor.cs @@ -13,8 +13,8 @@ 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. /// - [ValueEditor(Constants.PropertyEditors.Aliases.DropdownlistPublishKeys, "Dropdown list, publishing keys", "dropdown", ValueType = ValueTypes.Integer, Group = "lists", Icon = "icon-indent")] - public class DropDownWithKeysPropertyEditor : PropertyEditor + [DataEditor(Constants.PropertyEditors.Aliases.DropdownlistPublishKeys, "Dropdown list, publishing keys", "dropdown", ValueType = ValueTypes.Integer, Group = "lists", Icon = "icon-indent")] + public class DropDownWithKeysPropertyEditor : ConfiguredDataEditor { private readonly ILocalizedTextService _textService; @@ -31,6 +31,6 @@ namespace Umbraco.Web.PropertyEditors /// Return a custom pre-value editor /// /// - protected override ConfigurationEditor CreateConfigurationEditor() => new ValueListConfigurationEditor(_textService); + protected override IConfigurationEditor CreateConfigurationEditor() => new ValueListConfigurationEditor(_textService); } } diff --git a/src/Umbraco.Web/PropertyEditors/EmailAddressPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/EmailAddressPropertyEditor.cs index 3c466d6428..bfd76e739b 100644 --- a/src/Umbraco.Web/PropertyEditors/EmailAddressPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/EmailAddressPropertyEditor.cs @@ -5,8 +5,8 @@ using Umbraco.Core.PropertyEditors.Validators; namespace Umbraco.Web.PropertyEditors { - [ValueEditor(Constants.PropertyEditors.Aliases.EmailAddress, "Email address", "email", Icon="icon-message")] - public class EmailAddressPropertyEditor : PropertyEditor + [DataEditor(Constants.PropertyEditors.Aliases.EmailAddress, "Email address", "email", Icon="icon-message")] + public class EmailAddressPropertyEditor : ConfiguredDataEditor { /// /// The constructor will setup the property editor based on the attribute if one is found @@ -15,7 +15,7 @@ namespace Umbraco.Web.PropertyEditors { } - protected override IPropertyValueEditor CreateValueEditor() + protected override IDataValueEditor CreateValueEditor() { var editor = base.CreateValueEditor(); //add an email address validator @@ -23,7 +23,7 @@ namespace Umbraco.Web.PropertyEditors return editor; } - protected override ConfigurationEditor CreateConfigurationEditor() + protected override IConfigurationEditor CreateConfigurationEditor() { return new EmailAddressConfigurationEditor(); } diff --git a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs index 0438d5f162..6c2e102de7 100644 --- a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs @@ -10,8 +10,8 @@ using Umbraco.Core.Services; namespace Umbraco.Web.PropertyEditors { - [ValueEditor(Constants.PropertyEditors.Aliases.UploadField, "File upload", "fileupload", Icon = "icon-download-alt", Group = "media")] - public class FileUploadPropertyEditor : PropertyEditor + [DataEditor(Constants.PropertyEditors.Aliases.UploadField, "File upload", "fileupload", Icon = "icon-download-alt", Group = "media")] + public class FileUploadPropertyEditor : ConfiguredDataEditor { private readonly MediaFileSystem _mediaFileSystem; @@ -25,7 +25,7 @@ namespace Umbraco.Web.PropertyEditors /// Creates the corresponding property value editor. /// /// The corresponding property value editor. - protected override IPropertyValueEditor CreateValueEditor() + protected override IDataValueEditor CreateValueEditor() { var editor = new FileUploadPropertyValueEditor(Attribute, _mediaFileSystem); editor.Validators.Add(new UploadFileTypeValidator()); diff --git a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyValueEditor.cs b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyValueEditor.cs index 66f89c1e4e..a4a682d95f 100644 --- a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyValueEditor.cs @@ -12,11 +12,11 @@ namespace Umbraco.Web.PropertyEditors /// /// The value editor for the file upload property editor. /// - internal class FileUploadPropertyValueEditor : ValueEditor + internal class FileUploadPropertyValueEditor : DataValueEditor { private readonly MediaFileSystem _mediaFileSystem; - public FileUploadPropertyValueEditor(ValueEditorAttribute attribute, MediaFileSystem mediaFileSystem) + public FileUploadPropertyValueEditor(DataEditorAttribute attribute, MediaFileSystem mediaFileSystem) : base(attribute) { _mediaFileSystem = mediaFileSystem ?? throw new ArgumentNullException(nameof(mediaFileSystem)); diff --git a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs index de32276073..82bd6038f8 100644 --- a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs @@ -15,8 +15,11 @@ namespace Umbraco.Web.PropertyEditors { using Examine = global::Examine; - [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 + /// + /// Represents a grid property and parameter editor. + /// + [DataEditor(Constants.PropertyEditors.Aliases.Grid, "Grid layout", "grid", HideLabel = true, ValueType = ValueTypes.Json, Group="rich content", Icon="icon-layout")] + public class GridPropertyEditor : ConfiguredDataEditor { public GridPropertyEditor(ILogger logger) : base(logger) @@ -109,13 +112,13 @@ namespace Umbraco.Web.PropertyEditors /// Overridden to ensure that the value is validated /// /// - protected override IPropertyValueEditor CreateValueEditor() => new GridPropertyValueEditor(Attribute); + protected override IDataValueEditor CreateValueEditor() => new GridPropertyValueEditor(Attribute); - protected override ConfigurationEditor CreateConfigurationEditor() => new GridConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new GridConfigurationEditor(); - internal class GridPropertyValueEditor : ValueEditor + internal class GridPropertyValueEditor : DataValueEditor { - public GridPropertyValueEditor(ValueEditorAttribute attribute) + public GridPropertyValueEditor(DataEditorAttribute attribute) : base(attribute) { } } diff --git a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs index 3257e523ba..352b88f2b9 100644 --- a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs @@ -14,8 +14,11 @@ using Umbraco.Core.Services; namespace Umbraco.Web.PropertyEditors { - [ValueEditor(Constants.PropertyEditors.Aliases.ImageCropper, "Image Cropper", "imagecropper", ValueType = ValueTypes.Json, HideLabel = false, Group="media", Icon="icon-crop")] - public class ImageCropperPropertyEditor : PropertyEditor + /// + /// Represents an image cropper property editor. + /// + [DataEditor(Constants.PropertyEditors.Aliases.ImageCropper, "Image Cropper", "imagecropper", ValueType = ValueTypes.Json, HideLabel = false, Group="media", Icon="icon-crop")] + public class ImageCropperPropertyEditor : ConfiguredDataEditor { private readonly MediaFileSystem _mediaFileSystem; private readonly UploadAutoFillProperties _autoFillProperties; @@ -36,13 +39,13 @@ namespace Umbraco.Web.PropertyEditors /// Creates the corresponding property value editor. /// /// The corresponding property value editor. - protected override IPropertyValueEditor CreateValueEditor() => new ImageCropperPropertyValueEditor(Attribute, Logger, _mediaFileSystem); + protected override IDataValueEditor CreateValueEditor() => new ImageCropperPropertyValueEditor(Attribute, Logger, _mediaFileSystem); /// /// Creates the corresponding preValue editor. /// /// The corresponding preValue editor. - protected override ConfigurationEditor CreateConfigurationEditor() => new ImageCropperConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new ImageCropperConfigurationEditor(); /// /// Gets a value indicating whether a property is an image cropper field. diff --git a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs index 794a27667b..ca7705aaa0 100644 --- a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs @@ -16,12 +16,12 @@ namespace Umbraco.Web.PropertyEditors /// /// The value editor for the image cropper property editor. /// - internal class ImageCropperPropertyValueEditor : ValueEditor // fixme core vs web? + internal class ImageCropperPropertyValueEditor : DataValueEditor // fixme core vs web? { private readonly ILogger _logger; private readonly MediaFileSystem _mediaFileSystem; - public ImageCropperPropertyValueEditor(ValueEditorAttribute attribute, ILogger logger, MediaFileSystem mediaFileSystem) + public ImageCropperPropertyValueEditor(DataEditorAttribute attribute, ILogger logger, MediaFileSystem mediaFileSystem) : base(attribute) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); diff --git a/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs index 8cad3371e1..e1a255b378 100644 --- a/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs @@ -5,15 +5,18 @@ using Umbraco.Core.PropertyEditors.Validators; namespace Umbraco.Web.PropertyEditors { - [ValueEditor(Constants.PropertyEditors.Aliases.Integer, "Numeric", "integer", IsMacroParameterEditor = true, ValueType = ValueTypes.Integer)] - public class IntegerPropertyEditor : PropertyEditor + /// + /// Represents an integer property and parameter editor. + /// + [DataEditor(Constants.PropertyEditors.Aliases.Integer, EditorType.PropertyValue | EditorType.MacroParameter, "Numeric", "integer", ValueType = ValueTypes.Integer)] + public class IntegerPropertyEditor : ConfiguredDataEditor { public IntegerPropertyEditor(ILogger logger) : base(logger) { } /// - protected override IPropertyValueEditor CreateValueEditor() + protected override IDataValueEditor CreateValueEditor() { var editor = base.CreateValueEditor(); editor.Validators.Add(new IntegerValidator()); // ensure the value is validated @@ -21,9 +24,6 @@ namespace Umbraco.Web.PropertyEditors } /// - protected override ConfigurationEditor CreateConfigurationEditor() - { - return new IntegerConfigurationEditor(); - } + protected override IConfigurationEditor CreateConfigurationEditor() => new IntegerConfigurationEditor(); } } diff --git a/src/Umbraco.Web/PropertyEditors/LabelPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/LabelPropertyEditor.cs index 6e72385ed7..14018c00bd 100644 --- a/src/Umbraco.Web/PropertyEditors/LabelPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/LabelPropertyEditor.cs @@ -7,8 +7,8 @@ namespace Umbraco.Web.PropertyEditors /// /// Represents a property editor for label properties. /// - [ValueEditor(Constants.PropertyEditors.Aliases.NoEdit, "Label", "readonlyvalue", Icon = "icon-readonly")] - public class LabelPropertyEditor : PropertyEditor + [DataEditor(Constants.PropertyEditors.Aliases.NoEdit, "Label", "readonlyvalue", Icon = "icon-readonly")] + public class LabelPropertyEditor : ConfiguredDataEditor { /// /// Initializes a new instance of the class. @@ -18,15 +18,15 @@ namespace Umbraco.Web.PropertyEditors { } /// - protected override IPropertyValueEditor CreateValueEditor() => new LabelPropertyValueEditor(Attribute); + protected override IDataValueEditor CreateValueEditor() => new LabelPropertyValueEditor(Attribute); /// - protected override ConfigurationEditor CreateConfigurationEditor() => new LabelConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new LabelConfigurationEditor(); // provides the property value editor - internal class LabelPropertyValueEditor : ValueEditor + internal class LabelPropertyValueEditor : DataValueEditor { - public LabelPropertyValueEditor(ValueEditorAttribute attribute) + public LabelPropertyValueEditor(DataEditorAttribute attribute) : base(attribute) { } diff --git a/src/Umbraco.Web/PropertyEditors/ListViewPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/ListViewPropertyEditor.cs index a441be5b5b..148a6f4b10 100644 --- a/src/Umbraco.Web/PropertyEditors/ListViewPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ListViewPropertyEditor.cs @@ -8,8 +8,8 @@ namespace Umbraco.Web.PropertyEditors /// /// Represents a list-view editor. /// - [ValueEditor(Constants.PropertyEditors.Aliases.ListView, "List view", "listview", HideLabel = true, Group = "lists", Icon = "icon-item-arrangement")] - public class ListViewPropertyEditor : PropertyEditor + [DataEditor(Constants.PropertyEditors.Aliases.ListView, "List view", "listview", HideLabel = true, Group = "lists", Icon = "icon-item-arrangement")] + public class ListViewPropertyEditor : ConfiguredDataEditor { /// /// Initializes a new instance of the class. @@ -20,6 +20,6 @@ namespace Umbraco.Web.PropertyEditors { } /// - protected override ConfigurationEditor CreateConfigurationEditor() => new ListViewConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new ListViewConfigurationEditor(); } } diff --git a/src/Umbraco.Web/PropertyEditors/MacroContainerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MacroContainerPropertyEditor.cs index 02b5203aff..ae3a9f2482 100644 --- a/src/Umbraco.Web/PropertyEditors/MacroContainerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MacroContainerPropertyEditor.cs @@ -5,16 +5,13 @@ using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { // fixme - if deprecated, what's the alternative? - [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 + [DataEditor(Constants.PropertyEditors.Aliases.MacroContainer, "(Obsolete) Macro Picker", "macrocontainer", ValueType = ValueTypes.Text, Group="rich content", Icon="icon-settings-alt", IsDeprecated = true)] + public class MacroContainerPropertyEditor : ConfiguredDataEditor { public MacroContainerPropertyEditor(ILogger logger) : base(logger) { } - protected override ConfigurationEditor CreateConfigurationEditor() - { - return new MacroContainerConfigurationEditor(); - } + protected override IConfigurationEditor CreateConfigurationEditor() => new MacroContainerConfigurationEditor(); } } diff --git a/src/Umbraco.Web/PropertyEditors/MarkdownPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MarkdownPropertyEditor.cs index fa36a15f04..af2e2d4cfc 100644 --- a/src/Umbraco.Web/PropertyEditors/MarkdownPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MarkdownPropertyEditor.cs @@ -7,8 +7,8 @@ namespace Umbraco.Web.PropertyEditors /// /// Represents a markdown editor. /// - [ValueEditor(Constants.PropertyEditors.Aliases.MarkdownEditor, "Markdown editor", "markdowneditor", ValueType = ValueTypes.Text, Icon="icon-code", Group="rich content")] - public class MarkdownPropertyEditor : PropertyEditor + [DataEditor(Constants.PropertyEditors.Aliases.MarkdownEditor, "Markdown editor", "markdowneditor", ValueType = ValueTypes.Text, Icon="icon-code", Group="rich content")] + public class MarkdownPropertyEditor : ConfiguredDataEditor { /// /// Initializes a new instance of the class. @@ -18,9 +18,6 @@ namespace Umbraco.Web.PropertyEditors { } /// - protected override ConfigurationEditor CreateConfigurationEditor() - { - return new MarkdownConfigurationEditor(); - } + protected override IConfigurationEditor CreateConfigurationEditor() => new MarkdownConfigurationEditor(); } } diff --git a/src/Umbraco.Web/PropertyEditors/MediaPicker2PropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MediaPicker2PropertyEditor.cs index 572644c3a6..7f4b55fea1 100644 --- a/src/Umbraco.Web/PropertyEditors/MediaPicker2PropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MediaPicker2PropertyEditor.cs @@ -1,20 +1,23 @@ -using System.Collections.Generic; -using Umbraco.Core; +using Umbraco.Core; using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { /// - /// Media picker property editors that stores UDI + /// Represents a media picker property editor. /// - [ValueEditor(Constants.PropertyEditors.Aliases.MediaPicker2, "Media Picker", "mediapicker", ValueTypes.Text, IsMacroParameterEditor = true, Group = "media", Icon = "icon-picture")] - public class MediaPicker2PropertyEditor : PropertyEditor + [DataEditor(Constants.PropertyEditors.Aliases.MediaPicker2, EditorType.PropertyValue | EditorType.MacroParameter, "mediapicker", ValueTypes.Text, Group = "media", Icon = "icon-picture")] + public class MediaPicker2PropertyEditor : ConfiguredDataEditor { + /// + /// Initializes a new instance of the class. + /// public MediaPicker2PropertyEditor(ILogger logger) : base(logger) { } - protected override ConfigurationEditor CreateConfigurationEditor() => new MediaPickerConfigurationEditor(); + /// + protected override IConfigurationEditor CreateConfigurationEditor() => new MediaPickerConfigurationEditor(); } } diff --git a/src/Umbraco.Web/PropertyEditors/MemberGroupPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MemberGroupPickerPropertyEditor.cs index 11b26c678d..aa2648db94 100644 --- a/src/Umbraco.Web/PropertyEditors/MemberGroupPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MemberGroupPickerPropertyEditor.cs @@ -1,22 +1,14 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Umbraco.Core; +using Umbraco.Core; using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { - [ValueEditor(Constants.PropertyEditors.Aliases.MemberGroupPicker, "Member Group Picker", "membergrouppicker", Group="People", Icon="icon-users")] - public class MemberGroupPickerPropertyEditor : PropertyEditor + [DataEditor(Constants.PropertyEditors.Aliases.MemberGroupPicker, "Member Group Picker", "membergrouppicker", Group="People", Icon="icon-users")] + public class MemberGroupPickerPropertyEditor : ConfiguredDataEditor { - /// - /// The constructor will setup the property editor based on the attribute if one is found - /// - public MemberGroupPickerPropertyEditor(ILogger logger) : base(logger) - { - } + public MemberGroupPickerPropertyEditor(ILogger logger) + : base(logger) + { } } } diff --git a/src/Umbraco.Web/PropertyEditors/MemberPicker2PropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MemberPicker2PropertyEditor.cs index 8eea269a38..cd4ef08050 100644 --- a/src/Umbraco.Web/PropertyEditors/MemberPicker2PropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MemberPicker2PropertyEditor.cs @@ -4,13 +4,13 @@ using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { - [ValueEditor(Constants.PropertyEditors.Aliases.MemberPicker2, "Member Picker", "memberpicker", ValueTypes.String, Group = "People", Icon = "icon-user")] - public class MemberPicker2PropertyEditor : PropertyEditor + [DataEditor(Constants.PropertyEditors.Aliases.MemberPicker2, "Member Picker", "memberpicker", ValueType = ValueTypes.String, Group = "People", Icon = "icon-user")] + public class MemberPicker2PropertyEditor : ConfiguredDataEditor { public MemberPicker2PropertyEditor(ILogger logger) : base(logger) { } - protected override ConfigurationEditor CreateConfigurationEditor() => new MemberPickerConfiguration(); + protected override IConfigurationEditor CreateConfigurationEditor() => new MemberPickerConfiguration(); } } diff --git a/src/Umbraco.Web/PropertyEditors/MultiNodeTreePicker2PropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MultiNodeTreePicker2PropertyEditor.cs index 1834d25814..d8624807b3 100644 --- a/src/Umbraco.Web/PropertyEditors/MultiNodeTreePicker2PropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultiNodeTreePicker2PropertyEditor.cs @@ -4,13 +4,13 @@ using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { - [ValueEditor(Constants.PropertyEditors.Aliases.MultiNodeTreePicker2, "Multinode Treepicker", "contentpicker", ValueTypes.Text, Group = "pickers", Icon = "icon-page-add")] - public class MultiNodeTreePicker2PropertyEditor : PropertyEditor + [DataEditor(Constants.PropertyEditors.Aliases.MultiNodeTreePicker2, "Multinode Treepicker", "contentpicker", ValueType = ValueTypes.Text, Group = "pickers", Icon = "icon-page-add")] + public class MultiNodeTreePicker2PropertyEditor : ConfiguredDataEditor { public MultiNodeTreePicker2PropertyEditor(ILogger logger) : base(logger) { } - protected override ConfigurationEditor CreateConfigurationEditor() => new MultiNodePickerConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new MultiNodePickerConfigurationEditor(); } } diff --git a/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs index b03dfd741d..95b4d55043 100644 --- a/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs @@ -10,25 +10,31 @@ using Umbraco.Core.Services; namespace Umbraco.Web.PropertyEditors { - [ValueEditor(Constants.PropertyEditors.Aliases.MultipleTextstring, "Repeatable textstrings", "multipletextbox", ValueType = ValueTypes.Text, Icon="icon-ordered-list", Group="lists")] - public class MultipleTextStringPropertyEditor : PropertyEditor + /// + /// Represents a multiple text string property editor. + /// + [DataEditor(Constants.PropertyEditors.Aliases.MultipleTextstring, "Repeatable textstrings", "multipletextbox", ValueType = ValueTypes.Text, Icon="icon-ordered-list", Group="lists")] + public class MultipleTextStringPropertyEditor : ConfiguredDataEditor { /// - /// The constructor will setup the property editor based on the attribute if one is found + /// Initializes a new instance of the class. /// - public MultipleTextStringPropertyEditor(ILogger logger) : base(logger) + public MultipleTextStringPropertyEditor(ILogger logger) + : base(logger) { } - protected override IPropertyValueEditor CreateValueEditor() => new MultipleTextStringPropertyValueEditor(Attribute); + /// + protected override IDataValueEditor CreateValueEditor() => new MultipleTextStringPropertyValueEditor(Attribute); - protected override ConfigurationEditor CreateConfigurationEditor() => new MultipleTextStringConfigurationEditor(); + /// + protected override IConfigurationEditor CreateConfigurationEditor() => new MultipleTextStringConfigurationEditor(); /// /// Custom value editor so we can format the value for the editor and the database /// - internal class MultipleTextStringPropertyValueEditor : ValueEditor + internal class MultipleTextStringPropertyValueEditor : DataValueEditor { - public MultipleTextStringPropertyValueEditor(ValueEditorAttribute attribute) + public MultipleTextStringPropertyValueEditor(DataEditorAttribute attribute) : base(attribute) { } diff --git a/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs index 479c301327..a24324275c 100644 --- a/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs @@ -15,8 +15,11 @@ using Umbraco.Core.Services; namespace Umbraco.Web.PropertyEditors { - [ValueEditor(Constants.PropertyEditors.Aliases.NestedContent, "Nested Content", "nestedcontent", ValueType = "JSON", Group = "lists", Icon = "icon-thumbnail-list")] - public class NestedContentPropertyEditor : PropertyEditor + /// + /// Represents a nested content property editor. + /// + [DataEditor(Constants.PropertyEditors.Aliases.NestedContent, "Nested Content", "nestedcontent", ValueType = "JSON", Group = "lists", Icon = "icon-thumbnail-list")] + public class NestedContentPropertyEditor : ConfiguredDataEditor { private readonly Lazy _propertyEditors; @@ -41,19 +44,19 @@ namespace Umbraco.Web.PropertyEditors #region Pre Value Editor - protected override ConfigurationEditor CreateConfigurationEditor() => new NestedContentConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new NestedContentConfigurationEditor(); #endregion #region Value Editor - protected override IPropertyValueEditor CreateValueEditor() => new NestedContentPropertyValueEditor(Attribute, PropertyEditors); + protected override IDataValueEditor CreateValueEditor() => new NestedContentPropertyValueEditor(Attribute, PropertyEditors); - internal class NestedContentPropertyValueEditor : ValueEditor + internal class NestedContentPropertyValueEditor : DataValueEditor { private readonly PropertyEditorCollection _propertyEditors; - public NestedContentPropertyValueEditor(ValueEditorAttribute attribute, PropertyEditorCollection propertyEditors) + public NestedContentPropertyValueEditor(DataEditorAttribute attribute, PropertyEditorCollection propertyEditors) : base(attribute) { _propertyEditors = propertyEditors; diff --git a/src/Umbraco.Web/PropertyEditors/ParameterEditors/ContentTypeParameterEditor.cs b/src/Umbraco.Web/PropertyEditors/ParameterEditors/ContentTypeParameterEditor.cs index 212f0351b1..f73911d861 100644 --- a/src/Umbraco.Web/PropertyEditors/ParameterEditors/ContentTypeParameterEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ParameterEditors/ContentTypeParameterEditor.cs @@ -1,20 +1,21 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Umbraco.Core; -using Umbraco.Core.PropertyEditors; +using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors.ParameterEditors { - [ParameterEditor("contentType", "Content Type Picker", "entitypicker")] - public class ContentTypeParameterEditor : ParameterEditor + /// + /// Represents a content type parameter editor. + /// + [DataEditor("contentType", EditorType.MacroParameter, "Content Type Picker", "entitypicker")] + public class ContentTypeParameterEditor : DataEditor { + /// + /// Initializes a new instance of the class. + /// public ContentTypeParameterEditor() { - Configuration.Add("multiple", "0"); - Configuration.Add("entityType", "DocumentType"); + // configure + DefaultConfiguration.Add("multiple", false); + DefaultConfiguration.Add("entityType", "DocumentType"); } } } diff --git a/src/Umbraco.Web/PropertyEditors/ParameterEditors/MultipleContentTypeParameterEditor.cs b/src/Umbraco.Web/PropertyEditors/ParameterEditors/MultipleContentTypeParameterEditor.cs index 0e887e10e4..4119b33dad 100644 --- a/src/Umbraco.Web/PropertyEditors/ParameterEditors/MultipleContentTypeParameterEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ParameterEditors/MultipleContentTypeParameterEditor.cs @@ -2,13 +2,14 @@ namespace Umbraco.Web.PropertyEditors.ParameterEditors { - [ParameterEditor("contentTypeMultiple", "Multiple Content Type Picker", "entitypicker")] - public class MultipleContentTypeParameterEditor : ParameterEditor + [DataEditor("contentTypeMultiple", EditorType.MacroParameter, "Multiple Content Type Picker", "entitypicker")] + public class MultipleContentTypeParameterEditor : DataEditor { public MultipleContentTypeParameterEditor() { - Configuration.Add("multiple", "1"); - Configuration.Add("entityType", "DocumentType"); + // configure + DefaultConfiguration.Add("multiple", true); + DefaultConfiguration.Add("entityType", "DocumentType"); } } } diff --git a/src/Umbraco.Web/PropertyEditors/ParameterEditors/MultiplePropertyGroupParameterEditor.cs b/src/Umbraco.Web/PropertyEditors/ParameterEditors/MultiplePropertyGroupParameterEditor.cs index fff2bfc92b..8a15aca65e 100644 --- a/src/Umbraco.Web/PropertyEditors/ParameterEditors/MultiplePropertyGroupParameterEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ParameterEditors/MultiplePropertyGroupParameterEditor.cs @@ -2,15 +2,16 @@ namespace Umbraco.Web.PropertyEditors.ParameterEditors { - [ParameterEditor("tabPickerMultiple", "Multiple Tab Picker", "entitypicker")] - public class MultiplePropertyGroupParameterEditor : ParameterEditor + [DataEditor("tabPickerMultiple", EditorType.MacroParameter, "Multiple Tab Picker", "entitypicker")] + public class MultiplePropertyGroupParameterEditor : DataEditor { public MultiplePropertyGroupParameterEditor() { - Configuration.Add("multiple", "1"); - Configuration.Add("entityType", "PropertyGroup"); - //don't publish the id for a property group, publish it's alias (which is actually just it's lower cased name) - Configuration.Add("publishBy", "alias"); + // configure + DefaultConfiguration.Add("multiple", true); + DefaultConfiguration.Add("entityType", "PropertyGroup"); + //don't publish the id for a property group, publish its alias, which is actually just its lower cased name + DefaultConfiguration.Add("publishBy", "alias"); } } } diff --git a/src/Umbraco.Web/PropertyEditors/ParameterEditors/MultiplePropertyTypeParameterEditor.cs b/src/Umbraco.Web/PropertyEditors/ParameterEditors/MultiplePropertyTypeParameterEditor.cs index 7d8ca48c60..e74bfb5400 100644 --- a/src/Umbraco.Web/PropertyEditors/ParameterEditors/MultiplePropertyTypeParameterEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ParameterEditors/MultiplePropertyTypeParameterEditor.cs @@ -2,15 +2,16 @@ namespace Umbraco.Web.PropertyEditors.ParameterEditors { - [ParameterEditor("propertyTypePickerMultiple", "Multiple Property Type Picker", "entitypicker")] - public class MultiplePropertyTypeParameterEditor : ParameterEditor + [DataEditor("propertyTypePickerMultiple", EditorType.MacroParameter, "Multiple Property Type Picker", "entitypicker")] + public class MultiplePropertyTypeParameterEditor : DataEditor { public MultiplePropertyTypeParameterEditor() { - Configuration.Add("multiple", "1"); - Configuration.Add("entityType", "PropertyType"); - //don't publish the id for a property type, publish it's alias - Configuration.Add("publishBy", "alias"); + // configure + DefaultConfiguration.Add("multiple", "1"); + DefaultConfiguration.Add("entityType", "PropertyType"); + //don't publish the id for a property type, publish its alias + DefaultConfiguration.Add("publishBy", "alias"); } } } diff --git a/src/Umbraco.Web/PropertyEditors/ParameterEditors/PropertyGroupParameterEditor.cs b/src/Umbraco.Web/PropertyEditors/ParameterEditors/PropertyGroupParameterEditor.cs index 17406f0f2b..013d52d8bb 100644 --- a/src/Umbraco.Web/PropertyEditors/ParameterEditors/PropertyGroupParameterEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ParameterEditors/PropertyGroupParameterEditor.cs @@ -2,15 +2,16 @@ namespace Umbraco.Web.PropertyEditors.ParameterEditors { - [ParameterEditor("tabPicker", "Tab Picker", "entitypicker")] - public class PropertyGroupParameterEditor : ParameterEditor + [DataEditor("tabPicker", EditorType.MacroParameter, "Tab Picker", "entitypicker")] + public class PropertyGroupParameterEditor : DataEditor { public PropertyGroupParameterEditor() { - Configuration.Add("multiple", "0"); - Configuration.Add("entityType", "PropertyGroup"); + // configure + DefaultConfiguration.Add("multiple", "0"); + DefaultConfiguration.Add("entityType", "PropertyGroup"); //don't publish the id for a property group, publish it's alias (which is actually just it's lower cased name) - Configuration.Add("publishBy", "alias"); + DefaultConfiguration.Add("publishBy", "alias"); } } } diff --git a/src/Umbraco.Web/PropertyEditors/ParameterEditors/PropertyTypeParameterEditor.cs b/src/Umbraco.Web/PropertyEditors/ParameterEditors/PropertyTypeParameterEditor.cs index 1d8d1e1c80..9b07bf0797 100644 --- a/src/Umbraco.Web/PropertyEditors/ParameterEditors/PropertyTypeParameterEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ParameterEditors/PropertyTypeParameterEditor.cs @@ -2,15 +2,16 @@ namespace Umbraco.Web.PropertyEditors.ParameterEditors { - [ParameterEditor("propertyTypePicker", "Property Type Picker", "entitypicker")] - public class PropertyTypeParameterEditor : ParameterEditor + [DataEditor("propertyTypePicker", EditorType.MacroParameter, "Property Type Picker", "entitypicker")] + public class PropertyTypeParameterEditor : DataEditor { public PropertyTypeParameterEditor() { - Configuration.Add("multiple", "0"); - Configuration.Add("entityType", "PropertyType"); - //don't publish the id for a property type, publish it's alias - Configuration.Add("publishBy", "alias"); + // configure + DefaultConfiguration.Add("multiple", "0"); + DefaultConfiguration.Add("entityType", "PropertyType"); + //don't publish the id for a property type, publish its alias + DefaultConfiguration.Add("publishBy", "alias"); } } } diff --git a/src/Umbraco.Web/PropertyEditors/PublishValueValueEditor.cs b/src/Umbraco.Web/PropertyEditors/PublishValueValueEditor.cs index a594252ef3..0d7e7dea3b 100644 --- a/src/Umbraco.Web/PropertyEditors/PublishValueValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/PublishValueValueEditor.cs @@ -16,11 +16,11 @@ 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 : ValueEditor + internal class PublishValueValueEditor : DataValueEditor { private readonly ILogger _logger; - internal PublishValueValueEditor(ValueEditorAttribute attribute, ILogger logger) + internal PublishValueValueEditor(DataEditorAttribute attribute, ILogger logger) : base(attribute) { _logger = logger; diff --git a/src/Umbraco.Web/PropertyEditors/PublishValuesMultipleValueEditor.cs b/src/Umbraco.Web/PropertyEditors/PublishValuesMultipleValueEditor.cs index 2a1788b93b..a05f04224a 100644 --- a/src/Umbraco.Web/PropertyEditors/PublishValuesMultipleValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/PublishValuesMultipleValueEditor.cs @@ -21,13 +21,13 @@ namespace Umbraco.Web.PropertyEditors { private readonly bool _publishIds; - internal PublishValuesMultipleValueEditor(bool publishIds, ILogger logger, ValueEditorAttribute attribute) + internal PublishValuesMultipleValueEditor(bool publishIds, ILogger logger, DataEditorAttribute attribute) : base(attribute, logger) { _publishIds = publishIds; } - public PublishValuesMultipleValueEditor(bool publishIds, ValueEditorAttribute attribute) + public PublishValuesMultipleValueEditor(bool publishIds, DataEditorAttribute attribute) : this(publishIds, Current.Logger, attribute) { } diff --git a/src/Umbraco.Web/PropertyEditors/RadioButtonsPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/RadioButtonsPropertyEditor.cs index 7bd1f70f07..75c8390d30 100644 --- a/src/Umbraco.Web/PropertyEditors/RadioButtonsPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/RadioButtonsPropertyEditor.cs @@ -13,14 +13,14 @@ 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. /// - [ValueEditor(Constants.PropertyEditors.Aliases.RadioButtonList, "Radio button list", "radiobuttons", ValueType = ValueTypes.Integer, Group="lists", Icon="icon-target")] + [DataEditor(Constants.PropertyEditors.Aliases.RadioButtonList, "Radio button list", "radiobuttons", ValueType = ValueTypes.Integer, Group="lists", Icon="icon-target")] public class RadioButtonsPropertyEditor : DropDownWithKeysPropertyEditor { /// /// The constructor will setup the property editor based on the attribute if one is found /// - public RadioButtonsPropertyEditor(ILogger logger, ILocalizedTextService textService) : base(logger, textService) - { - } + public RadioButtonsPropertyEditor(ILogger logger, ILocalizedTextService textService) + : base(logger, textService) + { } } } diff --git a/src/Umbraco.Web/PropertyEditors/RelatedLinks2PropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/RelatedLinks2PropertyEditor.cs index f4195b4974..3bc19d39a9 100644 --- a/src/Umbraco.Web/PropertyEditors/RelatedLinks2PropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/RelatedLinks2PropertyEditor.cs @@ -5,13 +5,13 @@ using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { - [ValueEditor(Constants.PropertyEditors.Aliases.RelatedLinks2, "Related links", "relatedlinks", ValueType = ValueTypes.Json, Icon = "icon-thumbnail-list", Group = "pickers")] - public class RelatedLinks2PropertyEditor : PropertyEditor + [DataEditor(Constants.PropertyEditors.Aliases.RelatedLinks2, "Related links", "relatedlinks", ValueType = ValueTypes.Json, Icon = "icon-thumbnail-list", Group = "pickers")] + public class RelatedLinks2PropertyEditor : ConfiguredDataEditor { public RelatedLinks2PropertyEditor(ILogger logger) : base(logger) { } - protected override ConfigurationEditor CreateConfigurationEditor() => new RelatedLinksConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new RelatedLinksConfigurationEditor(); } } diff --git a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs index 0a772e26da..c5536131ae 100644 --- a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs @@ -9,8 +9,11 @@ using Umbraco.Core.Services; namespace Umbraco.Web.PropertyEditors { - [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 + /// + /// Represents a rich text property editor. + /// + [DataEditor(Constants.PropertyEditors.Aliases.TinyMce, "Rich Text Editor", "rte", ValueType = ValueTypes.Text, HideLabel = false, Group="Rich Content", Icon="icon-browser-window")] + public class RichTextPropertyEditor : ConfiguredDataEditor { /// /// The constructor will setup the property editor based on the attribute if one is found @@ -23,17 +26,17 @@ namespace Umbraco.Web.PropertyEditors /// Create a custom value editor /// /// - protected override IPropertyValueEditor CreateValueEditor() => new RichTextPropertyValueEditor(Attribute); + protected override IDataValueEditor CreateValueEditor() => new RichTextPropertyValueEditor(Attribute); - protected override ConfigurationEditor CreateConfigurationEditor() => new RichTextConfigurationEditor(); + protected override IConfigurationEditor 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 : ValueEditor + internal class RichTextPropertyValueEditor : DataValueEditor { - public RichTextPropertyValueEditor(ValueEditorAttribute attribute) + public RichTextPropertyValueEditor(DataEditorAttribute attribute) : base(attribute) { } diff --git a/src/Umbraco.Web/PropertyEditors/SliderPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/SliderPropertyEditor.cs index 4a065c42b6..4c3f07681d 100644 --- a/src/Umbraco.Web/PropertyEditors/SliderPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/SliderPropertyEditor.cs @@ -7,8 +7,8 @@ namespace Umbraco.Web.PropertyEditors /// /// Represents a slider editor. /// - [ValueEditor(Constants.PropertyEditors.Aliases.Slider, "Slider", "slider", Icon="icon-navigation-horizontal")] - public class SliderPropertyEditor : PropertyEditor + [DataEditor(Constants.PropertyEditors.Aliases.Slider, "Slider", "slider", Icon = "icon-navigation-horizontal")] + public class SliderPropertyEditor : ConfiguredDataEditor { /// /// Initializes a new instance of the class. @@ -18,7 +18,7 @@ namespace Umbraco.Web.PropertyEditors { } /// - protected override ConfigurationEditor CreateConfigurationEditor() + protected override IConfigurationEditor CreateConfigurationEditor() { return new SliderConfigurationEditor(); } diff --git a/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs index c2ca43ebad..126a0592e7 100644 --- a/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs @@ -10,9 +10,12 @@ using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { + /// + /// Represents a tags property editor. + /// [TagsPropertyEditor] - [ValueEditor(Constants.PropertyEditors.Aliases.Tags, "Tags", "tags", Icon="icon-tags")] - public class TagsPropertyEditor : PropertyEditor + [DataEditor(Constants.PropertyEditors.Aliases.Tags, "Tags", "tags", Icon="icon-tags")] + public class TagsPropertyEditor : ConfiguredDataEditor { private readonly ManifestValidatorCollection _validators; @@ -22,13 +25,13 @@ namespace Umbraco.Web.PropertyEditors _validators = validators; } - protected override IPropertyValueEditor CreateValueEditor() => new TagPropertyValueEditor(Attribute); + protected override IDataValueEditor CreateValueEditor() => new TagPropertyValueEditor(Attribute); - protected override ConfigurationEditor CreateConfigurationEditor() => new TagConfigurationEditor(_validators); + protected override IConfigurationEditor CreateConfigurationEditor() => new TagConfigurationEditor(_validators); - internal class TagPropertyValueEditor : ValueEditor + internal class TagPropertyValueEditor : DataValueEditor { - public TagPropertyValueEditor(ValueEditorAttribute attribute) + public TagPropertyValueEditor(DataEditorAttribute attribute) : base(attribute) { } diff --git a/src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs index d354ceeff3..3bfc4c2fd9 100644 --- a/src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs @@ -5,10 +5,10 @@ using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { /// - /// Represents a textarea editor. + /// Represents a textarea property and parameter editor. /// - [ValueEditor(Constants.PropertyEditors.Aliases.TextboxMultiple, "Textarea", "textarea", IsMacroParameterEditor = true, ValueType = ValueTypes.Text, Icon="icon-application-window-alt")] - public class TextAreaPropertyEditor : PropertyEditor + [DataEditor(Constants.PropertyEditors.Aliases.TextboxMultiple, EditorType.PropertyValue | EditorType.MacroParameter, "Textarea", "textarea", ValueType = ValueTypes.Text, Icon="icon-application-window-alt")] + public class TextAreaPropertyEditor : ConfiguredDataEditor { /// /// Initializes a new instance of the class. @@ -18,9 +18,9 @@ namespace Umbraco.Web.PropertyEditors { } /// - protected override IPropertyValueEditor CreateValueEditor() => new TextOnlyValueEditor(Attribute); + protected override IDataValueEditor CreateValueEditor() => new TextOnlyValueEditor(Attribute); /// - protected override ConfigurationEditor CreateConfigurationEditor() => new TextAreaConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new TextAreaConfigurationEditor(); } } diff --git a/src/Umbraco.Web/PropertyEditors/TextOnlyValueEditor.cs b/src/Umbraco.Web/PropertyEditors/TextOnlyValueEditor.cs index 2f07941fbd..6f6598576a 100644 --- a/src/Umbraco.Web/PropertyEditors/TextOnlyValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TextOnlyValueEditor.cs @@ -9,9 +9,9 @@ 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 : ValueEditor + public class TextOnlyValueEditor : DataValueEditor { - public TextOnlyValueEditor(ValueEditorAttribute attribute) + public TextOnlyValueEditor(DataEditorAttribute attribute) : base(attribute) { } diff --git a/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs index 099cd477bc..1864d11115 100644 --- a/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs @@ -5,10 +5,10 @@ using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { /// - /// Represents a textbox editor. + /// Represents a textbox property and parameter editor. /// - [ValueEditor(Constants.PropertyEditors.Aliases.Textbox, "Textbox", "textbox", IsMacroParameterEditor = true, Group = "Common")] - public class TextboxPropertyEditor : PropertyEditor + [DataEditor(Constants.PropertyEditors.Aliases.Textbox, EditorType.PropertyValue | EditorType.MacroParameter, "Textbox", "textbox", Group = "Common")] + public class TextboxPropertyEditor : ConfiguredDataEditor { /// /// Initializes a new instance of the class. @@ -18,9 +18,9 @@ namespace Umbraco.Web.PropertyEditors { } /// - protected override IPropertyValueEditor CreateValueEditor() => new TextOnlyValueEditor(Attribute); + protected override IDataValueEditor CreateValueEditor() => new TextOnlyValueEditor(Attribute); /// - protected override ConfigurationEditor CreateConfigurationEditor() => new TextboxConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new TextboxConfigurationEditor(); } } diff --git a/src/Umbraco.Web/PropertyEditors/TrueFalsePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TrueFalsePropertyEditor.cs index e7ce1fb0f0..379867ad4b 100644 --- a/src/Umbraco.Web/PropertyEditors/TrueFalsePropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TrueFalsePropertyEditor.cs @@ -5,10 +5,10 @@ using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { /// - /// Represents a boolean editor. + /// Represents a boolean property and parameter editor. /// - [ValueEditor(Constants.PropertyEditors.Aliases.Boolean, "True/False", "boolean", ValueTypes.Integer, IsMacroParameterEditor = true, Group = "Common", Icon="icon-checkbox")] - public class TrueFalsePropertyEditor : PropertyEditor + [DataEditor(Constants.PropertyEditors.Aliases.Boolean, EditorType.PropertyValue | EditorType.MacroParameter, "True/False", "boolean", ValueType = ValueTypes.Integer, Group = "Common", Icon="icon-checkbox")] + public class TrueFalsePropertyEditor : ConfiguredDataEditor { /// /// Initializes a new instance of the class. @@ -18,9 +18,6 @@ namespace Umbraco.Web.PropertyEditors { } /// - protected override ConfigurationEditor CreateConfigurationEditor() - { - return new TrueFalseConfigurationEditor(); - } + protected override IConfigurationEditor CreateConfigurationEditor() => new TrueFalseConfigurationEditor(); } } diff --git a/src/Umbraco.Web/PropertyEditors/UserPickerConfiguration.cs b/src/Umbraco.Web/PropertyEditors/UserPickerConfiguration.cs new file mode 100644 index 0000000000..f7bd0ceb7d --- /dev/null +++ b/src/Umbraco.Web/PropertyEditors/UserPickerConfiguration.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using Umbraco.Core.PropertyEditors; + +namespace Umbraco.Web.PropertyEditors +{ + public class UserPickerConfiguration : ConfigurationEditor + { + public override IDictionary DefaultConfiguration => new Dictionary + { + {"entityType", "User"} + }; + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/PropertyEditors/UserPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/UserPickerPropertyEditor.cs index dee115e023..931e0864e7 100644 --- a/src/Umbraco.Web/PropertyEditors/UserPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/UserPickerPropertyEditor.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.ComponentModel; +using System.ComponentModel; using System.Web.Mvc; using Umbraco.Core; using Umbraco.Core.Logging; @@ -7,21 +6,13 @@ using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { - [ValueEditor(Constants.PropertyEditors.Aliases.UserPicker, "User picker", "entitypicker", ValueTypes.Integer, Group="People", Icon="icon-user")] - public class UserPickerPropertyEditor : PropertyEditor + [DataEditor(Constants.PropertyEditors.Aliases.UserPicker, "User picker", "entitypicker", ValueType = ValueTypes.Integer, Group = "People", Icon = "icon-user")] + public class UserPickerPropertyEditor : ConfiguredDataEditor { public UserPickerPropertyEditor(ILogger logger) : base(logger) { } - protected override ConfigurationEditor CreateConfigurationEditor() => new UserPickerConfiguration(); - } - - public class UserPickerConfiguration : ConfigurationEditor - { - public override IDictionary DefaultConfiguration => new Dictionary - { - {"entityType", "User"} - }; + protected override IConfigurationEditor CreateConfigurationEditor() => new UserPickerConfiguration(); } } diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 813715ba2a..b4bc19fca9 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -289,6 +289,7 @@ + diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Macros/editMacro.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Macros/editMacro.aspx.cs index 2187acb520..a3ff49e545 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Macros/editMacro.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Macros/editMacro.aspx.cs @@ -177,7 +177,7 @@ namespace umbraco.cms.presentation.developer return Convert.IsDBNull(test) ? 0 : test; } - protected IEnumerable GetMacroParameterEditors() + protected IEnumerable GetMacroParameterEditors() { // we need to show the depracated ones for backwards compatibility // FIXME not managing deprecated here?!