From d30842e1bf369d37671a64b8132f193b0d2c142a Mon Sep 17 00:00:00 2001 From: Stephan Date: Wed, 14 Feb 2018 16:55:42 +0100 Subject: [PATCH] Cleanup editing --- .../Manifest/ParameterEditorConverter.cs | 19 +++++++--- .../Manifest/PropertyEditorConverter.cs | 33 ++++++++++++----- .../PublishedContentTypeFactory.cs | 2 +- .../PropertyEditors/ConfigurationEditor.cs | 5 ++- .../PropertyEditors/IValueEditor.cs | 34 +++++++++++++++++- .../PropertyEditors/ParameterEditor.cs | 13 +++++++ .../PropertyEditors/ParameterValueEditor.cs | 3 ++ .../PropertyEditors/PropertyEditor.cs | 36 ++++++++++--------- .../ValueConverters/GridValueConverter.cs | 4 +++ .../PropertyEditors/ValueEditor.cs | 22 +++++------- .../PropertyEditors/ValueTypes.cs | 1 - .../Services/EntityXmlSerializer.cs | 1 + .../Manifest/ManifestParserTests.cs | 2 +- .../Editors/ContentTypeController.cs | 2 +- src/Umbraco.Web/Editors/DataTypeController.cs | 7 ++-- .../ContentPropertyDisplayConverter.cs | 9 ++++- ...taTypeConfigurationFieldDisplayResolver.cs | 9 ++--- .../Models/Mapping/DataTypeMapperProfile.cs | 14 +++++--- .../Models/Mapping/DatabaseTypeResolver.cs | 5 ++- .../CheckBoxListPropertyEditor.cs | 2 +- .../PropertyEditors/DatePropertyEditor.cs | 2 +- .../PropertyEditors/DateTimePropertyEditor.cs | 2 +- .../PropertyEditors/DecimalPropertyEditor.cs | 2 +- .../DropDownMultiplePropertyEditor.cs | 4 +-- .../DropDownMultipleWithKeysPropertyEditor.cs | 2 +- .../PropertyEditors/DropDownPropertyEditor.cs | 2 +- .../EmailAddressPropertyEditor.cs | 2 +- .../FileUploadPropertyEditor.cs | 2 +- .../PropertyEditors/GridPropertyEditor.cs | 2 +- .../ImageCropperPropertyEditor.cs | 2 +- .../PropertyEditors/IntegerPropertyEditor.cs | 2 +- .../PropertyEditors/LabelPropertyEditor.cs | 2 +- .../MultipleTextStringPropertyEditor.cs | 2 +- .../NestedContentPropertyEditor.cs | 2 +- .../PropertyEditors/RichTextPropertyEditor.cs | 2 +- .../PropertyEditors/TagsPropertyEditor.cs | 2 +- .../PropertyEditors/TextAreaPropertyEditor.cs | 2 +- .../PropertyEditors/TextOnlyValueEditor.cs | 2 +- .../PropertyEditors/TextboxPropertyEditor.cs | 2 +- .../Filters/ContentItemValidationHelper.cs | 3 +- 40 files changed, 179 insertions(+), 87 deletions(-) diff --git a/src/Umbraco.Core/Manifest/ParameterEditorConverter.cs b/src/Umbraco.Core/Manifest/ParameterEditorConverter.cs index 3f2055129b..51799d3fd5 100644 --- a/src/Umbraco.Core/Manifest/ParameterEditorConverter.cs +++ b/src/Umbraco.Core/Manifest/ParameterEditorConverter.cs @@ -20,15 +20,24 @@ namespace Umbraco.Core.Manifest /// 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) { - // the deserializer will first try to get the property, and that would throw since - // the editor would try to create a new value editor, so we have to set a - // value editor by ourselves, which will then be populated by the deserializer. + // explicitely assign a value editor of type ParameterValueEditor target.ValueEditor = new ParameterValueEditor(); - // the 'view' property in the manifest is at top-level, and needs to be moved - // down one level to the actual value editor. + // move the 'view' property jobject["editor"] = new JObject { ["view"] = jobject["view"] }; jobject.Property("view").Remove(); } diff --git a/src/Umbraco.Core/Manifest/PropertyEditorConverter.cs b/src/Umbraco.Core/Manifest/PropertyEditorConverter.cs index e965d3e50d..13896efadb 100644 --- a/src/Umbraco.Core/Manifest/PropertyEditorConverter.cs +++ b/src/Umbraco.Core/Manifest/PropertyEditorConverter.cs @@ -33,9 +33,9 @@ namespace Umbraco.Core.Manifest { if (jobject["editor"] != null) { - // the deserializer will first try to get the property, and that would throw since - // the editor would try to create a new value editor, so we have to set a - // value editor by ourselves, which will then be populated by the deserializer. + // 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 @@ -49,14 +49,29 @@ namespace Umbraco.Core.Manifest jobject["editor"]["validation"] = RewriteValidators(validation); } - // see note about validators, above - same applies to field validators - if (jobject["prevalues"]?["fields"] is JArray jarray) + if (jobject["prevalues"] is JObject prevalues) { - foreach (var field in jarray) + // 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) { - // see note above, for editor - if (field["validation"] is JObject validation) - field["validation"] = RewriteValidators(validation); + 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"); } } diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentTypeFactory.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentTypeFactory.cs index 1387b00ae8..a98dca4f29 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentTypeFactory.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentTypeFactory.cs @@ -102,7 +102,7 @@ namespace Umbraco.Core.Models.PublishedContent _publishedDataTypes.Remove(id); var dataTypes = _dataTypeService.GetAll(ids); foreach (var dataType in dataTypes) - _publishedDataTypes[dataType.Id] = new PublishedDataType(dataType.Id, dataType.EditorAlias, dataType is DataType d ? d.GetLazyConfiguration() : new Lazy(() => dataType.Configuration))); + _publishedDataTypes[dataType.Id] = new PublishedDataType(dataType.Id, dataType.EditorAlias, dataType is DataType d ? d.GetLazyConfiguration() : new Lazy(() => dataType.Configuration)); } } } diff --git a/src/Umbraco.Core/PropertyEditors/ConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/ConfigurationEditor.cs index 0b82322513..7c089a3f99 100644 --- a/src/Umbraco.Core/PropertyEditors/ConfigurationEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/ConfigurationEditor.cs @@ -53,7 +53,10 @@ namespace Umbraco.Core.PropertyEditors /// /// Gets the default configuration. /// - /// The default configuration is used to initialize new datatypes. + /// + /// The default configuration is used to initialize new datatypes. + /// + [JsonProperty("defaultConfig")] public virtual IDictionary DefaultConfiguration => new Dictionary(); /// diff --git a/src/Umbraco.Core/PropertyEditors/IValueEditor.cs b/src/Umbraco.Core/PropertyEditors/IValueEditor.cs index b16672dec8..675619682c 100644 --- a/src/Umbraco.Core/PropertyEditors/IValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/IValueEditor.cs @@ -1,4 +1,10 @@ -namespace Umbraco.Core.PropertyEditors +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. @@ -9,5 +15,31 @@ /// 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; } } } diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditor.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditor.cs index 7952a85a71..2e52c2703c 100644 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/ParameterEditor.cs @@ -53,6 +53,19 @@ namespace Umbraco.Core.PropertyEditors [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 { diff --git a/src/Umbraco.Core/PropertyEditors/ParameterValueEditor.cs b/src/Umbraco.Core/PropertyEditors/ParameterValueEditor.cs index 5f9066ee54..c28bc64f33 100644 --- a/src/Umbraco.Core/PropertyEditors/ParameterValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/ParameterValueEditor.cs @@ -34,5 +34,8 @@ namespace Umbraco.Core.PropertyEditors get => _view; set => _view = IOHelper.ResolveVirtualUrl(value); } + + /// + public string ValueType { get; set; } } } diff --git a/src/Umbraco.Core/PropertyEditors/PropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/PropertyEditor.cs index be73c984e3..f2a9af3299 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyEditor.cs @@ -17,7 +17,7 @@ namespace Umbraco.Core.PropertyEditors [DebuggerDisplay("{" + nameof(DebuggerDisplay) + "(),nq}")] public class PropertyEditor : IParameterEditor { - private ValueEditor _valueEditorAssigned; + private IPropertyValueEditor _valueEditorAssigned; private ConfigurationEditor _configurationEditorAssigned; /// @@ -105,12 +105,12 @@ namespace Umbraco.Core.PropertyEditors /// 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 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. + /// 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, ObjectCreationHandling = ObjectCreationHandling.Replace)] - public ValueEditor ValueEditor + [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 @@ -119,8 +119,9 @@ namespace Umbraco.Core.PropertyEditors set => _valueEditorAssigned = value; } + /// [JsonIgnore] - IValueEditor IParameterEditor.ValueEditor => ValueEditor; // fixme - because we must, but - bah + IValueEditor IParameterEditor.ValueEditor => ValueEditor; /// /// Gets or sets the configuration editor. @@ -134,27 +135,28 @@ namespace Umbraco.Core.PropertyEditors /// 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 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. + /// 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", ObjectCreationHandling = ObjectCreationHandling.Replace)] // changing the name would break manifests + [JsonProperty("prevalues")] // changing the name would break manifests public ConfigurationEditor ConfigurationEditor { get => CreateConfigurationEditor(); set => _configurationEditorAssigned = value; } - [JsonProperty("defaultConfig")] - public IDictionary DefaultConfiguration => ConfigurationEditor.DefaultConfiguration; - - [JsonIgnore] // fixme - but is parameterEditor.Configuration the same thing as preValues? - IDictionary IParameterEditor.Configuration => DefaultConfiguration; // fixme - because we must, but - bah + // 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 ValueEditor CreateValueEditor() + protected virtual IPropertyValueEditor CreateValueEditor() { // handle assigned editor // or create a new editor diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs index 2350c73567..5efd40778b 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs @@ -19,6 +19,10 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters [DefaultPropertyValueConverter(typeof(JsonValueConverter))] //this shadows the JsonValueConverter public class GridValueConverter : JsonValueConverter { + public GridValueConverter(PropertyEditorCollection propertyEditors) + : base(propertyEditors) + { } + public override bool IsConverter(PublishedPropertyType propertyType) => propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.Grid); diff --git a/src/Umbraco.Core/PropertyEditors/ValueEditor.cs b/src/Umbraco.Core/PropertyEditors/ValueEditor.cs index 0d8aa4c2d6..f56842f912 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueEditor.cs @@ -16,14 +16,14 @@ namespace Umbraco.Core.PropertyEditors /// /// Represents a value editor for content properties. /// - public class ValueEditor : IValueEditor + public class ValueEditor : IPropertyValueEditor { private string _view; /// /// Initializes a new instance of the class. /// - public ValueEditor() + public ValueEditor() // for tests, and manifest { ValueType = ValueTypes.String; Validators = new List(); @@ -32,7 +32,7 @@ namespace Umbraco.Core.PropertyEditors /// /// Initializes a new instance of the class. /// - public ValueEditor(string view, params IValueValidator[] validators) + public ValueEditor(string view, params IValueValidator[] validators) // not used : this() { View = view; @@ -146,12 +146,6 @@ namespace Umbraco.Core.PropertyEditors /// public virtual ManifestValidator RegexValidator => new RegexValidator(); - /// - /// Gets the corresponding to the value type. - /// - /// - public ValueStorageType GetDatabaseType() => ValueTypes.ToStorageType(ValueType); - /// /// If this is is true than the editor will be displayed full width without a label /// @@ -176,7 +170,7 @@ namespace Umbraco.Core.PropertyEditors Type valueType; //convert the string to a known type - switch (GetDatabaseType()) + switch (ValueTypes.ToStorageType(ValueType)) { case ValueStorageType.Ntext: case ValueStorageType.Nvarchar: @@ -246,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 " + GetDatabaseType()); + Current.Logger.Warn("The value " + editorValue.Value + " cannot be converted to the type " + ValueTypes.ToStorageType(ValueType)); return null; } return result.Result; @@ -267,7 +261,7 @@ namespace Umbraco.Core.PropertyEditors { if (property.GetValue() == null) return string.Empty; - switch (GetDatabaseType()) + switch (ValueTypes.ToStorageType(ValueType)) { case ValueStorageType.Ntext: case ValueStorageType.Nvarchar: @@ -359,7 +353,7 @@ namespace Umbraco.Core.PropertyEditors return new XText(ConvertDbToString(propertyType, value, dataTypeService)); } - switch (GetDatabaseType()) + switch (ValueTypes.ToStorageType(ValueType)) { case ValueStorageType.Date: case ValueStorageType.Integer: @@ -382,7 +376,7 @@ namespace Umbraco.Core.PropertyEditors if (value == null) return string.Empty; - switch (GetDatabaseType()) + switch (ValueTypes.ToStorageType(ValueType)) { case ValueStorageType.Nvarchar: case ValueStorageType.Ntext: diff --git a/src/Umbraco.Core/PropertyEditors/ValueTypes.cs b/src/Umbraco.Core/PropertyEditors/ValueTypes.cs index 8df9def440..88b1fb35f7 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueTypes.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueTypes.cs @@ -102,7 +102,6 @@ namespace Umbraco.Core.PropertyEditors default: throw new ArgumentOutOfRangeException(nameof(valueType), $"Value \"{valueType}\" is not a valid ValueTypes."); } - } } } diff --git a/src/Umbraco.Core/Services/EntityXmlSerializer.cs b/src/Umbraco.Core/Services/EntityXmlSerializer.cs index e7c91340f7..64e3089ea6 100644 --- a/src/Umbraco.Core/Services/EntityXmlSerializer.cs +++ b/src/Umbraco.Core/Services/EntityXmlSerializer.cs @@ -7,6 +7,7 @@ using System.Xml.Linq; using Newtonsoft.Json; using Umbraco.Core.Composing; using Umbraco.Core.Models; +using Umbraco.Core.PropertyEditors; using Umbraco.Core.Strings; namespace Umbraco.Core.Services diff --git a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs b/src/Umbraco.Tests/Manifest/ManifestParserTests.cs index f79953e13e..6d868a5ce4 100644 --- a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs +++ b/src/Umbraco.Tests/Manifest/ManifestParserTests.cs @@ -193,7 +193,7 @@ javascript: ['~/test.js',/*** some note about stuff asd09823-4**09234*/ '~/test2 Assert.AreEqual("\\d*", v.Config); // this is not part of the manifest - var preValues = editor.DefaultConfiguration; + var preValues = editor.ConfigurationEditor.DefaultConfiguration; Assert.IsEmpty(preValues); var preValueEditor = editor.ConfigurationEditor; diff --git a/src/Umbraco.Web/Editors/ContentTypeController.cs b/src/Umbraco.Web/Editors/ContentTypeController.cs index 61ef089b3f..e7a72fb462 100644 --- a/src/Umbraco.Web/Editors/ContentTypeController.cs +++ b/src/Umbraco.Web/Editors/ContentTypeController.cs @@ -130,7 +130,7 @@ namespace Umbraco.Web.Editors return new ContentPropertyDisplay() { Editor = dataTypeDiff.EditorAlias, - Validation = new PropertyTypeValidation() { }, + Validation = new PropertyTypeValidation(), View = editor.ValueEditor.View, Config = editor.ConfigurationEditor.ToConfigurationEditor(configuration) }; diff --git a/src/Umbraco.Web/Editors/DataTypeController.cs b/src/Umbraco.Web/Editors/DataTypeController.cs index 20e33d761e..8623545046 100644 --- a/src/Umbraco.Web/Editors/DataTypeController.cs +++ b/src/Umbraco.Web/Editors/DataTypeController.cs @@ -123,8 +123,7 @@ namespace Umbraco.Web.Editors if (dt == null) { var editor = _propertyEditors[Constants.PropertyEditors.Aliases.ListView]; - dt = new DataType(editor); - dt.Name = Constants.Conventions.DataTypes.ListViewPrefix + contentTypeAlias; + dt = new DataType(editor) { Name = Constants.Conventions.DataTypes.ListViewPrefix + contentTypeAlias }; Services.DataTypeService.Save(dt); } @@ -209,9 +208,9 @@ namespace Umbraco.Web.Editors // get the current configuration, // get the new configuration as a dictionary (this is how we get it from model) - // and map it to an actual configuration object + // and map to an actual configuration object var currentConfiguration = dataType.PersistedDataType.Configuration; - var configurationDictionary = dataType.ConfigurationFields.ToDictionary(x => x.Key, x => x.Value); // fixme tokens! + var configurationDictionary = dataType.ConfigurationFields.ToDictionary(x => x.Key, x => x.Value); var configuration = dataType.PropertyEditor.ConfigurationEditor.FromConfigurationEditor(configurationDictionary, currentConfiguration); dataType.PersistedDataType.Configuration = configuration; diff --git a/src/Umbraco.Web/Models/Mapping/ContentPropertyDisplayConverter.cs b/src/Umbraco.Web/Models/Mapping/ContentPropertyDisplayConverter.cs index c3488ddf48..d044669ac8 100644 --- a/src/Umbraco.Web/Models/Mapping/ContentPropertyDisplayConverter.cs +++ b/src/Umbraco.Web/Models/Mapping/ContentPropertyDisplayConverter.cs @@ -4,6 +4,7 @@ using AutoMapper; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Models; +using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; using Umbraco.Web.Models.ContentEditing; @@ -27,7 +28,13 @@ namespace Umbraco.Web.Models.Mapping //configure the editor for display with the pre-values var valEditor = display.PropertyEditor.ValueEditor; - valEditor.Configuration = config; + // fixme - the value editor REQUIRES the configuration to operate + // at the moment, only for richtext and nested, where it's used to set HideLabel + // 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; + ve.Configuration = config; //set the display properties after mapping display.Alias = originalProp.Alias; diff --git a/src/Umbraco.Web/Models/Mapping/DataTypeConfigurationFieldDisplayResolver.cs b/src/Umbraco.Web/Models/Mapping/DataTypeConfigurationFieldDisplayResolver.cs index c02cb497ff..9f71702d2c 100644 --- a/src/Umbraco.Web/Models/Mapping/DataTypeConfigurationFieldDisplayResolver.cs +++ b/src/Umbraco.Web/Models/Mapping/DataTypeConfigurationFieldDisplayResolver.cs @@ -16,7 +16,7 @@ namespace Umbraco.Web.Models.Mapping /// /// Maps pre-values in the dictionary to the values for the fields /// - internal static void MapPreValueValuesToPreValueFields(DataTypeConfigurationFieldDisplay[] fields, IDictionary configuration) + internal static void MapConfigurationFields(DataTypeConfigurationFieldDisplay[] fields, IDictionary configuration) { if (fields == null) throw new ArgumentNullException(nameof(fields)); if (configuration == null) throw new ArgumentNullException(nameof(configuration)); @@ -49,14 +49,15 @@ namespace Umbraco.Web.Models.Mapping // and convert configuration to editor if (editor != null) { - fields = editor.ConfigurationEditor.Fields.Select(Mapper.Map).ToArray(); - configurationDictionary = editor.ConfigurationEditor.ToConfigurationEditor(configuration); + var configurationEditor = editor.ConfigurationEditor; + fields = configurationEditor.Fields.Select(Mapper.Map).ToArray(); + configurationDictionary = configurationEditor.ToConfigurationEditor(configuration); } if (configurationDictionary == null) configurationDictionary = new Dictionary(); - MapPreValueValuesToPreValueFields(fields, configurationDictionary); + MapConfigurationFields(fields, configurationDictionary); return fields; } diff --git a/src/Umbraco.Web/Models/Mapping/DataTypeMapperProfile.cs b/src/Umbraco.Web/Models/Mapping/DataTypeMapperProfile.cs index 3177a5d355..d24644d89a 100644 --- a/src/Umbraco.Web/Models/Mapping/DataTypeMapperProfile.cs +++ b/src/Umbraco.Web/Models/Mapping/DataTypeMapperProfile.cs @@ -108,12 +108,18 @@ namespace Umbraco.Web.Models.Mapping CreateMap>() .ConvertUsing(src => { - // this is a new data type, so just return the field editors, with default values - there are no values yet - var fields = src.ConfigurationEditor.Fields.Select(Mapper.Map).ToArray(); + // this is a new data type, initialize default configuration + // get the configuration editor, + // get the configuration fields and map to UI, + // get the configuration default values and map to UI - var defaultConfiguration = src.DefaultConfiguration; + var configurationEditor = src.ConfigurationEditor; + + var fields = configurationEditor.Fields.Select(Mapper.Map).ToArray(); + + var defaultConfiguration = configurationEditor.DefaultConfiguration; if (defaultConfiguration != null) - DataTypeConfigurationFieldDisplayResolver.MapPreValueValuesToPreValueFields(fields, defaultConfiguration); + DataTypeConfigurationFieldDisplayResolver.MapConfigurationFields(fields, defaultConfiguration); return fields; }); diff --git a/src/Umbraco.Web/Models/Mapping/DatabaseTypeResolver.cs b/src/Umbraco.Web/Models/Mapping/DatabaseTypeResolver.cs index 05f55aa798..540217d493 100644 --- a/src/Umbraco.Web/Models/Mapping/DatabaseTypeResolver.cs +++ b/src/Umbraco.Web/Models/Mapping/DatabaseTypeResolver.cs @@ -1,5 +1,6 @@ using System; using Umbraco.Core.Models; +using Umbraco.Core.PropertyEditors; using Umbraco.Web.Composing; using Umbraco.Web.Models.ContentEditing; @@ -17,7 +18,9 @@ namespace Umbraco.Web.Models.Mapping { throw new InvalidOperationException("Could not find property editor with id " + source.EditorAlias); } - return propertyEditor.ValueEditor.GetDatabaseType(); + + var valueType = propertyEditor.ValueEditor.ValueType; + return ValueTypes.ToStorageType(valueType); } } } diff --git a/src/Umbraco.Web/PropertyEditors/CheckBoxListPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/CheckBoxListPropertyEditor.cs index e4624bfee6..7bfc01f9a3 100644 --- a/src/Umbraco.Web/PropertyEditors/CheckBoxListPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/CheckBoxListPropertyEditor.cs @@ -31,6 +31,6 @@ namespace Umbraco.Web.PropertyEditors protected override ConfigurationEditor CreateConfigurationEditor() => new ValueListConfigurationEditor(_textService); /// - protected override ValueEditor CreateValueEditor() => new PublishValuesMultipleValueEditor(false, Attribute); + protected override IPropertyValueEditor CreateValueEditor() => new PublishValuesMultipleValueEditor(false, Attribute); } } diff --git a/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs index 85680fce2a..e29284fd98 100644 --- a/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs @@ -12,7 +12,7 @@ namespace Umbraco.Web.PropertyEditors { } /// - protected override ValueEditor CreateValueEditor() => new DateValueEditor(Attribute); + protected override IPropertyValueEditor CreateValueEditor() => new DateValueEditor(Attribute); /// protected override ConfigurationEditor CreateConfigurationEditor() => new DateConfigurationEditor(); diff --git a/src/Umbraco.Web/PropertyEditors/DateTimePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DateTimePropertyEditor.cs index a3324bd636..c0e9205cf9 100644 --- a/src/Umbraco.Web/PropertyEditors/DateTimePropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DateTimePropertyEditor.cs @@ -11,7 +11,7 @@ namespace Umbraco.Web.PropertyEditors public DateTimePropertyEditor(ILogger logger): base(logger) { } - protected override ValueEditor CreateValueEditor() + protected override IPropertyValueEditor CreateValueEditor() { var editor = base.CreateValueEditor(); editor.Validators.Add(new DateTimeValidator()); diff --git a/src/Umbraco.Web/PropertyEditors/DecimalPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DecimalPropertyEditor.cs index 9785bdcfc5..ca5876ac3d 100644 --- a/src/Umbraco.Web/PropertyEditors/DecimalPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DecimalPropertyEditor.cs @@ -19,7 +19,7 @@ namespace Umbraco.Web.PropertyEditors /// Overridden to ensure that the value is validated /// /// - protected override ValueEditor CreateValueEditor() + protected override IPropertyValueEditor CreateValueEditor() { var editor = base.CreateValueEditor(); editor.Validators.Add(new DecimalValidator()); diff --git a/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs index 960e39ba9e..ae2dfdb71c 100644 --- a/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs @@ -13,7 +13,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")] + [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")] @@ -27,6 +27,6 @@ namespace Umbraco.Web.PropertyEditors { } /// - protected override ValueEditor CreateValueEditor() => new PublishValuesMultipleValueEditor(false, Attribute); + protected override IPropertyValueEditor CreateValueEditor() => new PublishValuesMultipleValueEditor(false, Attribute); } } diff --git a/src/Umbraco.Web/PropertyEditors/DropDownMultipleWithKeysPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownMultipleWithKeysPropertyEditor.cs index 3d9b0ce1aa..da587318e2 100644 --- a/src/Umbraco.Web/PropertyEditors/DropDownMultipleWithKeysPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DropDownMultipleWithKeysPropertyEditor.cs @@ -29,7 +29,7 @@ namespace Umbraco.Web.PropertyEditors } /// - protected override ValueEditor CreateValueEditor() => new PublishValuesMultipleValueEditor(true, Attribute); + protected override IPropertyValueEditor CreateValueEditor() => new PublishValuesMultipleValueEditor(true, Attribute); /// protected override ConfigurationEditor CreateConfigurationEditor() => new DropDownMultipleConfigurationEditor(_textService); diff --git a/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs index bc46ff7913..cd1162b129 100644 --- a/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs @@ -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 ValueEditor CreateValueEditor() => new PublishValueValueEditor(Attribute, Logger); + protected override IPropertyValueEditor CreateValueEditor() => new PublishValueValueEditor(Attribute, Logger); } } diff --git a/src/Umbraco.Web/PropertyEditors/EmailAddressPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/EmailAddressPropertyEditor.cs index ac379ebf26..3c466d6428 100644 --- a/src/Umbraco.Web/PropertyEditors/EmailAddressPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/EmailAddressPropertyEditor.cs @@ -15,7 +15,7 @@ namespace Umbraco.Web.PropertyEditors { } - protected override ValueEditor CreateValueEditor() + protected override IPropertyValueEditor CreateValueEditor() { var editor = base.CreateValueEditor(); //add an email address validator diff --git a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs index 12271e94af..0438d5f162 100644 --- a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs @@ -25,7 +25,7 @@ namespace Umbraco.Web.PropertyEditors /// Creates the corresponding property value editor. /// /// The corresponding property value editor. - protected override ValueEditor CreateValueEditor() + protected override IPropertyValueEditor CreateValueEditor() { var editor = new FileUploadPropertyValueEditor(Attribute, _mediaFileSystem); editor.Validators.Add(new UploadFileTypeValidator()); diff --git a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs index 7e775d3473..de32276073 100644 --- a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs @@ -109,7 +109,7 @@ namespace Umbraco.Web.PropertyEditors /// Overridden to ensure that the value is validated /// /// - protected override ValueEditor CreateValueEditor() => new GridPropertyValueEditor(Attribute); + protected override IPropertyValueEditor CreateValueEditor() => new GridPropertyValueEditor(Attribute); protected override ConfigurationEditor CreateConfigurationEditor() => new GridConfigurationEditor(); diff --git a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs index dfe7119607..3257e523ba 100644 --- a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs @@ -36,7 +36,7 @@ namespace Umbraco.Web.PropertyEditors /// Creates the corresponding property value editor. /// /// The corresponding property value editor. - protected override ValueEditor CreateValueEditor() => new ImageCropperPropertyValueEditor(Attribute, Logger, _mediaFileSystem); + protected override IPropertyValueEditor CreateValueEditor() => new ImageCropperPropertyValueEditor(Attribute, Logger, _mediaFileSystem); /// /// Creates the corresponding preValue editor. diff --git a/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs index b2718912e3..8cad3371e1 100644 --- a/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs @@ -13,7 +13,7 @@ namespace Umbraco.Web.PropertyEditors { } /// - protected override ValueEditor CreateValueEditor() + protected override IPropertyValueEditor CreateValueEditor() { var editor = base.CreateValueEditor(); editor.Validators.Add(new IntegerValidator()); // ensure the value is validated diff --git a/src/Umbraco.Web/PropertyEditors/LabelPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/LabelPropertyEditor.cs index 632afbcff9..6e72385ed7 100644 --- a/src/Umbraco.Web/PropertyEditors/LabelPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/LabelPropertyEditor.cs @@ -18,7 +18,7 @@ namespace Umbraco.Web.PropertyEditors { } /// - protected override ValueEditor CreateValueEditor() => new LabelPropertyValueEditor(Attribute); + protected override IPropertyValueEditor CreateValueEditor() => new LabelPropertyValueEditor(Attribute); /// protected override ConfigurationEditor CreateConfigurationEditor() => new LabelConfigurationEditor(); diff --git a/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs index e7a3cf1e4b..b03dfd741d 100644 --- a/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs @@ -19,7 +19,7 @@ namespace Umbraco.Web.PropertyEditors public MultipleTextStringPropertyEditor(ILogger logger) : base(logger) { } - protected override ValueEditor CreateValueEditor() => new MultipleTextStringPropertyValueEditor(Attribute); + protected override IPropertyValueEditor CreateValueEditor() => new MultipleTextStringPropertyValueEditor(Attribute); protected override ConfigurationEditor CreateConfigurationEditor() => new MultipleTextStringConfigurationEditor(); diff --git a/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs index b2c623f2a4..479c301327 100644 --- a/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs @@ -47,7 +47,7 @@ namespace Umbraco.Web.PropertyEditors #region Value Editor - protected override ValueEditor CreateValueEditor() => new NestedContentPropertyValueEditor(Attribute, PropertyEditors); + protected override IPropertyValueEditor CreateValueEditor() => new NestedContentPropertyValueEditor(Attribute, PropertyEditors); internal class NestedContentPropertyValueEditor : ValueEditor { diff --git a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs index 265572636f..0a772e26da 100644 --- a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs @@ -23,7 +23,7 @@ namespace Umbraco.Web.PropertyEditors /// Create a custom value editor /// /// - protected override ValueEditor CreateValueEditor() => new RichTextPropertyValueEditor(Attribute); + protected override IPropertyValueEditor CreateValueEditor() => new RichTextPropertyValueEditor(Attribute); protected override ConfigurationEditor CreateConfigurationEditor() => new RichTextConfigurationEditor(); diff --git a/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs index 8a5f4e547a..c2ca43ebad 100644 --- a/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs @@ -22,7 +22,7 @@ namespace Umbraco.Web.PropertyEditors _validators = validators; } - protected override ValueEditor CreateValueEditor() => new TagPropertyValueEditor(Attribute); + protected override IPropertyValueEditor CreateValueEditor() => new TagPropertyValueEditor(Attribute); protected override ConfigurationEditor CreateConfigurationEditor() => new TagConfigurationEditor(_validators); diff --git a/src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs index 68eb2089ed..d354ceeff3 100644 --- a/src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs @@ -18,7 +18,7 @@ namespace Umbraco.Web.PropertyEditors { } /// - protected override ValueEditor CreateValueEditor() => new TextOnlyValueEditor(Attribute); + protected override IPropertyValueEditor CreateValueEditor() => new TextOnlyValueEditor(Attribute); /// protected override ConfigurationEditor CreateConfigurationEditor() => new TextAreaConfigurationEditor(); diff --git a/src/Umbraco.Web/PropertyEditors/TextOnlyValueEditor.cs b/src/Umbraco.Web/PropertyEditors/TextOnlyValueEditor.cs index 8616fbcf97..2f07941fbd 100644 --- a/src/Umbraco.Web/PropertyEditors/TextOnlyValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TextOnlyValueEditor.cs @@ -29,7 +29,7 @@ namespace Umbraco.Web.PropertyEditors { if (property.GetValue() == null) return string.Empty; - switch (GetDatabaseType()) + switch (ValueTypes.ToStorageType(ValueType)) { case ValueStorageType.Ntext: case ValueStorageType.Nvarchar: diff --git a/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs index a380e0a077..099cd477bc 100644 --- a/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs @@ -18,7 +18,7 @@ namespace Umbraco.Web.PropertyEditors { } /// - protected override ValueEditor CreateValueEditor() => new TextOnlyValueEditor(Attribute); + protected override IPropertyValueEditor CreateValueEditor() => new TextOnlyValueEditor(Attribute); /// protected override ConfigurationEditor CreateConfigurationEditor() => new TextboxConfigurationEditor(); diff --git a/src/Umbraco.Web/WebApi/Filters/ContentItemValidationHelper.cs b/src/Umbraco.Web/WebApi/Filters/ContentItemValidationHelper.cs index 8afecbf423..aab19481b9 100644 --- a/src/Umbraco.Web/WebApi/Filters/ContentItemValidationHelper.cs +++ b/src/Umbraco.Web/WebApi/Filters/ContentItemValidationHelper.cs @@ -132,6 +132,7 @@ namespace Umbraco.Web.WebApi.Filters //get the pre-values for this property var preValues = p.DataType.Configuration; + // fixme what does this mean? //TODO: when we figure out how to 'override' certain pre-value properties we'll either need to: // * Combine the preValues with the overridden values stored with the document type property (but how to combine?) // * Or, pass in the overridden values stored with the doc type property separately @@ -167,7 +168,7 @@ namespace Umbraco.Web.WebApi.Filters //It's required || (p.IsRequired)) { - foreach (var result in p.PropertyEditor.ValueEditor.RegexValidator.Validate(postedValue, p.ValidationRegExp, preValues, editor)) + foreach (var result in p.PropertyEditor.ValueEditor.RegexValidator.Validate(postedValue, null, preValues, p.ValidationRegExp)) { actionContext.ModelState.AddPropertyError(result, p.Alias); }