diff --git a/src/Umbraco.Core/CoreBootManager.cs b/src/Umbraco.Core/CoreBootManager.cs index 6f195c6404..51317049e1 100644 --- a/src/Umbraco.Core/CoreBootManager.cs +++ b/src/Umbraco.Core/CoreBootManager.cs @@ -262,7 +262,6 @@ namespace Umbraco.Core { new Lazy(() => typeof (RequiredValueValidator)), new Lazy(() => typeof (RegexValueValidator)), - new Lazy(() => typeof (ValueTypeValueValidator)), new Lazy(() => typeof (DelimitedValueValidator)) }); diff --git a/src/Umbraco.Core/Models/Editors/ContentPropertyData.cs b/src/Umbraco.Core/Models/Editors/ContentPropertyData.cs index 6676a7c3a7..30693834ef 100644 --- a/src/Umbraco.Core/Models/Editors/ContentPropertyData.cs +++ b/src/Umbraco.Core/Models/Editors/ContentPropertyData.cs @@ -16,7 +16,7 @@ namespace Umbraco.Core.Models.Editors /// public class ContentPropertyData { - public ContentPropertyData(string value, IDictionary additionalData) + public ContentPropertyData(object value, IDictionary additionalData) { Value = value; AdditionalData = new ReadOnlyDictionary(additionalData); @@ -27,7 +27,7 @@ namespace Umbraco.Core.Models.Editors /// /// The string value submitted for the property /// - public string Value { get; private set; } + public object Value { get; private set; } /// /// A dictionary containing any additional objects that are related to this property when saving diff --git a/src/Umbraco.Core/PropertyEditors/DelimitedValueValidator.cs b/src/Umbraco.Core/PropertyEditors/DelimitedValueValidator.cs index 459038829d..c2c13aa9af 100644 --- a/src/Umbraco.Core/PropertyEditors/DelimitedValueValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/DelimitedValueValidator.cs @@ -21,45 +21,48 @@ namespace Umbraco.Core.PropertyEditors /// The current pre-values stored for the data type /// /// - public override IEnumerable Validate(string value, string config, string preValues, PropertyEditor editor) + public override IEnumerable Validate(object value, string config, string preValues, PropertyEditor editor) { //TODO: localize these! - - var delimiter = ","; - Regex regex = null; - if (config.IsNullOrWhiteSpace() == false) + if (value != null) { - var json = JsonConvert.DeserializeObject(config); - if (json["delimiter"] != null) + var delimiter = ","; + Regex regex = null; + if (config.IsNullOrWhiteSpace() == false) { - delimiter = json["delimiter"].ToString(); - } - if (json["pattern"] != null) - { - var regexPattern = json["pattern"].ToString(); - regex = new Regex(regexPattern); - } - } - - var stringVal = value; - var split = stringVal.Split(new[] {delimiter}, StringSplitOptions.RemoveEmptyEntries); - for (var i = 0; i < split.Length; i++) - { - var s = split[i]; - //next if we have a regex statement validate with that - if (regex != null) - { - if (regex.IsMatch(s) == false) + var json = JsonConvert.DeserializeObject(config); + if (json["delimiter"] != null) { - yield return new ValidationResult("The item at index " + i + " did not match the expression " + regex, - new[] + delimiter = json["delimiter"].ToString(); + } + if (json["pattern"] != null) + { + var regexPattern = json["pattern"].ToString(); + regex = new Regex(regexPattern); + } + } + + var stringVal = value.ToString(); + var split = stringVal.Split(new[] { delimiter }, StringSplitOptions.RemoveEmptyEntries); + for (var i = 0; i < split.Length; i++) + { + var s = split[i]; + //next if we have a regex statement validate with that + if (regex != null) + { + if (regex.IsMatch(s) == false) + { + yield return new ValidationResult("The item at index " + i + " did not match the expression " + regex, + new[] { //make the field name called 'value0' where 0 is the index "value" + i }); + } } } } + } } } \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/ManifestValidator.cs b/src/Umbraco.Core/PropertyEditors/ManifestValidator.cs index 0252bd9abf..c8938be9d4 100644 --- a/src/Umbraco.Core/PropertyEditors/ManifestValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/ManifestValidator.cs @@ -56,7 +56,7 @@ namespace Umbraco.Core.PropertyEditors /// The current pre-values stored for the data type /// The property editor instance that we are validating for /// - public override IEnumerable Validate(string value, string preValues, PropertyEditor editor) + public override IEnumerable Validate(object value, string preValues, PropertyEditor editor) { return ValidatorInstance.Validate(value, Config, preValues, editor); } diff --git a/src/Umbraco.Core/PropertyEditors/RegexValueValidator.cs b/src/Umbraco.Core/PropertyEditors/RegexValueValidator.cs index 705db74e84..10ac6842dd 100644 --- a/src/Umbraco.Core/PropertyEditors/RegexValueValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/RegexValueValidator.cs @@ -11,16 +11,21 @@ namespace Umbraco.Core.PropertyEditors [ValueValidator("Regex")] internal sealed class RegexValueValidator : ValueValidator { - public override IEnumerable Validate(string value, string config, string preValues, PropertyEditor editor) + public override IEnumerable Validate(object value, string config, string preValues, PropertyEditor editor) { //TODO: localize these! - - var regex = new Regex(config); - - if (!regex.IsMatch(value)) + if (config.IsNullOrWhiteSpace() == false && value != null) { - yield return new ValidationResult("Value is invalid, it does not match the correct pattern", new[] {"value"}); - } + var asString = value.ToString(); + + var regex = new Regex(config); + + if (regex.IsMatch(asString) == false) + { + yield return new ValidationResult("Value is invalid, it does not match the correct pattern", new[] { "value" }); + } + } + } } } \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/RequiredValueValidator.cs b/src/Umbraco.Core/PropertyEditors/RequiredValueValidator.cs index e40ae002d6..362952243f 100644 --- a/src/Umbraco.Core/PropertyEditors/RequiredValueValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/RequiredValueValidator.cs @@ -9,18 +9,24 @@ namespace Umbraco.Core.PropertyEditors [ValueValidator("Required")] internal sealed class RequiredValueValidator : ValueValidator { - public override IEnumerable Validate(string value, string config, string preValues, PropertyEditor editor) + public override IEnumerable Validate(object value, string config, string preValues, PropertyEditor editor) { //TODO: localize these! if (value == null) { - yield return new ValidationResult("Value cannot be null", new[] { "value" }); + yield return new ValidationResult("Value cannot be null", new[] {"value"}); } - if (value.IsNullOrWhiteSpace()) + else { - yield return new ValidationResult("Value cannot be empty", new[] { "value" }); + var asString = value.ToString(); + if (asString.IsNullOrWhiteSpace()) + { + yield return new ValidationResult("Value cannot be empty", new[] { "value" }); + } } + + } } } \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/ValidatorBase.cs b/src/Umbraco.Core/PropertyEditors/ValidatorBase.cs index 16bb4b8c6e..7f3c4f0c0d 100644 --- a/src/Umbraco.Core/PropertyEditors/ValidatorBase.cs +++ b/src/Umbraco.Core/PropertyEditors/ValidatorBase.cs @@ -12,7 +12,7 @@ namespace Umbraco.Core.PropertyEditors /// Validates the object with the resolved ValueValidator found for this type /// /// - /// Depending on what is being validated, this value can be a json structure representing an editor's model, it could be a single + /// Depending on what is being validated, this value can be a json structure (JObject, JArray, etc...) representing an editor's model, it could be a single /// string representing an editor's model, this class structure is also used to validate pre-values and in that case this value /// could be a json structure or a single value representing a pre-value field. /// @@ -22,6 +22,6 @@ namespace Umbraco.Core.PropertyEditors /// /// The property editor instance that we are validating for /// - public abstract IEnumerable Validate(string value, string preValues, PropertyEditor editor); + public abstract IEnumerable Validate(object value, string preValues, PropertyEditor editor); } } \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/ValueEditor.cs b/src/Umbraco.Core/PropertyEditors/ValueEditor.cs index aba131ab9b..a646ac2f08 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueEditor.cs @@ -121,7 +121,7 @@ namespace Umbraco.Core.PropertyEditors /// /// /// - internal Attempt TryConvertValueToCrlType(string value) + internal Attempt TryConvertValueToCrlType(object value) { Type valueType; //convert the string to a known type @@ -174,12 +174,15 @@ namespace Umbraco.Core.PropertyEditors //TODO: Change the result to object so we can pass back JSON or json converted clr types if we want! /// - /// A method used to serialize the databse value to a string value which is then used to be sent - /// to the editor in JSON format. + /// A method used to format the databse value to a value that can be used by the editor /// /// /// - public virtual string FormatDataForEditor(object dbValue) + /// + /// The object returned will automatically be serialized into json notation. For most property editors + /// the value returned is probably just a string but in some cases a json structure will be returned. + /// + public virtual object FormatDataForEditor(object dbValue) { if (dbValue == null) return string.Empty; diff --git a/src/Umbraco.Core/PropertyEditors/ValueTypeValueValidator.cs b/src/Umbraco.Core/PropertyEditors/ValueTypeValueValidator.cs deleted file mode 100644 index 5b50ba3ccf..0000000000 --- a/src/Umbraco.Core/PropertyEditors/ValueTypeValueValidator.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using Umbraco.Core.Models; - -namespace Umbraco.Core.PropertyEditors -{ - /// - /// A validator that validates that the value is of a certain type - /// - /// - /// This is a special validator type that is executed against all property editors no matter if they've defined this validator or not. - /// - [ValueValidator("ValueType")] - internal sealed class ValueTypeValueValidator : ValueValidator - { - public override IEnumerable Validate(string value, string config, string preValues, PropertyEditor editor) - { - var attempt = editor.ValueEditor.TryConvertValueToCrlType(value); - if (attempt.Success == false) - { - //TODO: localize these! - yield return new ValidationResult(string.Format("Value is not of type {0} and cannot be converted", editor.ValueEditor.GetDatabaseType())); - } - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/ValueValidator.cs b/src/Umbraco.Core/PropertyEditors/ValueValidator.cs index def5dc333d..830dc026d8 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueValidator.cs @@ -24,7 +24,10 @@ namespace Umbraco.Core.PropertyEditors /// /// Performs the validation against the value /// - /// + /// + /// Depending on what is being validated, this value can be a json structure (JObject, JArray, etc...) representing an editor's model, it could be a single + /// string representing an editor's model. + /// /// /// An object that is used to configure the validator. An example could be a regex /// expression if the validator was a regex validator. This is defined in the manifest along with @@ -37,6 +40,6 @@ namespace Umbraco.Core.PropertyEditors /// the validation message applies to the entire property type being validated. If there is a field name applied to a /// validation result we will try to match that field name up with a field name on the item itself. /// - public abstract IEnumerable Validate(string value, string config, string preValues, PropertyEditor editor); + public abstract IEnumerable Validate(object value, string config, string preValues, PropertyEditor editor); } } \ No newline at end of file diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 47365e2ea1..3adf1f2558 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -585,7 +585,6 @@ - diff --git a/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/PostcodeValidator.cs b/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/PostcodeValidator.cs index 159acdce04..05eed35a79 100644 --- a/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/PostcodeValidator.cs +++ b/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/PostcodeValidator.cs @@ -13,31 +13,35 @@ namespace Umbraco.Web.UI.App_Plugins.MyPackage.PropertyEditors internal class PostcodeValidator : ValidatorBase { - public override IEnumerable Validate(string value, string preValues, PropertyEditor editor) + public override IEnumerable Validate(object value, string preValues, PropertyEditor editor) { - var stringVal = value; - - if (preValues.IsNullOrWhiteSpace()) yield break; - var asJson = JObject.Parse(preValues); - if (asJson["country"] == null) yield break; - - if (asJson["country"].ToString() == "Australia") + if (value != null) { - if (Regex.IsMatch(stringVal, "^\\d{4}$") == false) + var stringVal = value.ToString(); + + if (preValues.IsNullOrWhiteSpace()) yield break; + var asJson = JObject.Parse(preValues); + if (asJson["country"] == null) yield break; + + if (asJson["country"].ToString() == "Australia") { - yield return new ValidationResult("Australian postcodes must be a 4 digit number", - new[] + if (Regex.IsMatch(stringVal, "^\\d{4}$") == false) + { + yield return new ValidationResult("Australian postcodes must be a 4 digit number", + new[] { //we only store a single value for this editor so the 'member' or 'field' // we'll associate this error with will simply be called 'value' "value" }); + } + } + else + { + yield return new ValidationResult("Only Australian postcodes are supported for this validator"); } } - else - { - yield return new ValidationResult("Only Australian postcodes are supported for this validator"); - } + } } } \ No newline at end of file diff --git a/src/Umbraco.Web/Models/ContentEditing/ContentPropertyBasic.cs b/src/Umbraco.Web/Models/ContentEditing/ContentPropertyBasic.cs index ba5c98d89e..cdebd65d33 100644 --- a/src/Umbraco.Web/Models/ContentEditing/ContentPropertyBasic.cs +++ b/src/Umbraco.Web/Models/ContentEditing/ContentPropertyBasic.cs @@ -15,7 +15,7 @@ namespace Umbraco.Web.Models.ContentEditing public int Id { get; set; } [DataMember(Name = "value")] - public string Value { get; set; } + public object Value { get; set; } [DataMember(Name = "alias", IsRequired = true)] [Required(AllowEmptyStrings = false)] diff --git a/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs index aaa3c86c10..5c621a275d 100644 --- a/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs @@ -40,14 +40,14 @@ namespace Umbraco.Web.PropertyEditors /// CUstom value editor so we can serialize with the correct date format (excluding time) /// and includes the date validator /// - private class DateValueEditor : ValueEditorWrapper + internal class DateValueEditor : ValueEditorWrapper { public DateValueEditor(ValueEditor wrapped) : base(wrapped) { Validators = new List { new DateTimeValidator() }; } - public override string FormatDataForEditor(object dbValue) + public override object FormatDataForEditor(object dbValue) { var date = dbValue.TryConvertTo(); if (date.Success == false || date.Result == null) diff --git a/src/Umbraco.Web/PropertyEditors/DateTimeValidator.cs b/src/Umbraco.Web/PropertyEditors/DateTimeValidator.cs index c1f7277a05..694434357e 100644 --- a/src/Umbraco.Web/PropertyEditors/DateTimeValidator.cs +++ b/src/Umbraco.Web/PropertyEditors/DateTimeValidator.cs @@ -11,10 +11,10 @@ namespace Umbraco.Web.PropertyEditors /// internal class DateTimeValidator : ValidatorBase { - public override IEnumerable Validate(string value, string preValues, PropertyEditor editor) + public override IEnumerable Validate(object value, string preValues, PropertyEditor editor) { DateTime dt; - if (value.IsNullOrWhiteSpace() == false && DateTime.TryParse(value, out dt) == false) + if (value != null && DateTime.TryParse(value.ToString(), out dt) == false) { yield return new ValidationResult(string.Format("The string value {0} cannot be parsed into a DateTime", value), new[] diff --git a/src/Umbraco.Web/PropertyEditors/DropDownMultiplePreValueEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownMultiplePreValueEditor.cs deleted file mode 100644 index 11c03b1051..0000000000 --- a/src/Umbraco.Web/PropertyEditors/DropDownMultiplePreValueEditor.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Collections.Generic; -using Umbraco.Core.Models; -using Umbraco.Core.PropertyEditors; - -namespace Umbraco.Web.PropertyEditors -{ - /// - /// A pre-value editor for the 'drop down list multiple' property editor that ensures that 'multiple' is saved for the config in the db but is not - /// rendered as a pre-value field. - /// - /// - /// This is mostly to maintain backwards compatibility with old property editors. Devs can now simply use the Drop down property editor and check the multiple pre-value checkbox - /// - internal class DropDownMultiplePreValueEditor : DropDownPreValueEditor - { - public DropDownMultiplePreValueEditor() - { - var fields = CreatePreValueFields(); - //add the multiple field, we'll make it hidden so it is not seen in the pre-value editor - fields.Add(new PreValueField - { - Key = "multiple", - Name = "multiple", - View = "hidden" - }); - Fields = fields; - } - - /// - /// Always - /// - /// - /// - /// - public override IDictionary FormatDataForEditor(IDictionary defaultPreVals, PreValueCollection persistedPreVals) - { - var returnVal = base.FormatDataForEditor(defaultPreVals, persistedPreVals); - //always add the multiple param to true - returnVal["multiple"] = "1"; - return returnVal; - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs index ffe1882682..b40a5dd3f9 100644 --- a/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs @@ -1,4 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using Umbraco.Core; +using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -23,17 +29,88 @@ namespace Umbraco.Web.PropertyEditors return new DropDownMultiplePreValueEditor(); } - } - - internal class DropDownMultipleValueEditor : ValueEditorWrapper - { - public DropDownMultipleValueEditor(ValueEditor wrapped) : base(wrapped) + /// + /// A pre-value editor for the 'drop down list multiple' property editor that ensures that 'multiple' is saved for the config in the db but is not + /// rendered as a pre-value field. + /// + /// + /// This is mostly to maintain backwards compatibility with old property editors. Devs can now simply use the Drop down property editor and check the multiple pre-value checkbox + /// + internal class DropDownMultiplePreValueEditor : DropDownPreValueEditor { + public DropDownMultiplePreValueEditor() + { + var fields = CreatePreValueFields(); + //add the multiple field, we'll make it hidden so it is not seen in the pre-value editor + fields.Add(new PreValueField + { + Key = "multiple", + Name = "multiple", + View = "hidden" + }); + Fields = fields; + } + + /// + /// Always + /// + /// + /// + /// + public override IDictionary FormatDataForEditor(IDictionary defaultPreVals, PreValueCollection persistedPreVals) + { + var returnVal = base.FormatDataForEditor(defaultPreVals, persistedPreVals); + //always add the multiple param to true + returnVal["multiple"] = "1"; + return returnVal; + } } - public override object FormatDataForPersistence(Core.Models.Editors.ContentPropertyData editorValue, object currentValue) + /// + /// Custom value editor to handle posted json data and to return json data for the multiple selected items. + /// + internal class DropDownMultipleValueEditor : ValueEditorWrapper { - return base.FormatDataForPersistence(editorValue, currentValue); + public DropDownMultipleValueEditor(ValueEditor wrapped) + : base(wrapped) + { + } + + /// + /// Override so that we can return a json array to the editor for multi-select values + /// + /// + /// + public override object FormatDataForEditor(object dbValue) + { + var delimited = base.FormatDataForEditor(dbValue).ToString(); + return delimited.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + } + + /// + /// When multiple values are selected a json array will be posted back so we need to format for storage in + /// the database which is a comma separated ID value + /// + /// + /// + /// + public override object FormatDataForPersistence(Core.Models.Editors.ContentPropertyData editorValue, object currentValue) + { + var json = editorValue.Value as JArray; + if (json == null) + { + return null; + } + + var values = json.Select(item => item.Value()).ToList(); + //change to delimited + return string.Join(",", values); + } } + } + + + + } \ No newline at end of file diff --git a/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs index 956233dd98..aac3b27f66 100644 --- a/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs @@ -4,7 +4,9 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Umbraco.Core; using Umbraco.Core.Logging; +using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; +using Umbraco.Core.Services; using umbraco; namespace Umbraco.Web.PropertyEditors @@ -30,27 +32,53 @@ namespace Umbraco.Web.PropertyEditors return new DropDownValueEditor(base.CreateValueEditor()); } - } - - /// - /// A property editor to allow the individual selection of pre-defined items. - /// - /// - /// Due to remaining backwards compatible, this stores the id of the drop down item in the database which is why it is marked - /// as INT and we have logic in here to ensure it is formatted correctly including ensuring that the INT ID value is published - /// in cache and not the string value. - /// - [PropertyEditor(Constants.PropertyEditors.DropdownlistPublishingKeys, "Dropdown list, publishing keys", "dropdown", ValueType = "INT")] - public class DropDownWithKeysPropertyEditor : PropertyEditor - { - /// - /// Return a custom pre-value editor + /// A custom value editor for the drop down so that we can ensure that the 'value' not the ID get's put into cache /// - /// - protected override PreValueEditor CreatePreValueEditor() + /// + /// 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 DropDownValueEditor : ValueEditorWrapper { - return new DropDownPreValueEditor(); + private readonly DataTypeService _dataTypeService; + + internal DropDownValueEditor(IDataTypeService dataTypeService, ValueEditor wrapped) + : base(wrapped) + { + _dataTypeService = (DataTypeService)dataTypeService; + } + + public DropDownValueEditor(ValueEditor wrapped) + : this(ApplicationContext.Current.Services.DataTypeService, wrapped) + { + } + + /// + /// Need to lookup the pre-values and put the string version in cache, not the ID (which is what is stored in the db) + /// + /// + /// + public override object FormatValueForCache(Property property) + { + var preValId = property.Value.TryConvertTo(); + if (preValId.Success) + { + var preVals = _dataTypeService.GetPreValuesCollectionByDataTypeId(property.PropertyType.DataTypeDefinitionId); + if (preVals != null) + { + var dictionary = PreValueCollection.AsDictionary(preVals); + if (dictionary.Any(x => x.Value.Id == preValId.Result)) + { + return dictionary.Single(x => x.Value.Id == preValId.Result).Value.Value; + } + + LogHelper.Warn("Could not find a pre value with ID " + preValId + " for property alias " + property.Alias); + } + } + + return base.FormatValueForCache(property); + } } } } \ No newline at end of file diff --git a/src/Umbraco.Web/PropertyEditors/DropDownValueEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownValueEditor.cs deleted file mode 100644 index 4d6a951c47..0000000000 --- a/src/Umbraco.Web/PropertyEditors/DropDownValueEditor.cs +++ /dev/null @@ -1,59 +0,0 @@ -using Umbraco.Core; -using Umbraco.Core.Logging; -using Umbraco.Core.Models; -using Umbraco.Core.Models.Editors; -using Umbraco.Core.PropertyEditors; -using Umbraco.Core.Services; -using System.Linq; - -namespace Umbraco.Web.PropertyEditors -{ - /// - /// A custom value editor for the drop down so that we can ensure that the 'value' not the ID get's put into cache - /// - /// - /// 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 DropDownValueEditor : ValueEditorWrapper - { - private readonly DataTypeService _dataTypeService; - - internal DropDownValueEditor(IDataTypeService dataTypeService, ValueEditor wrapped) - : base(wrapped) - { - _dataTypeService = (DataTypeService)dataTypeService; - } - - public DropDownValueEditor(ValueEditor wrapped) - : this(ApplicationContext.Current.Services.DataTypeService, wrapped) - { - } - - /// - /// Need to lookup the pre-values and put the string version in cache, not the ID (which is what is stored in the db) - /// - /// - /// - public override object FormatValueForCache(Property property) - { - var preValId = property.Value.TryConvertTo(); - if (preValId.Success) - { - var preVals = _dataTypeService.GetPreValuesCollectionByDataTypeId(property.PropertyType.DataTypeDefinitionId); - if (preVals != null) - { - var dictionary = PreValueCollection.AsDictionary(preVals); - if (dictionary.Any(x => x.Value.Id == preValId.Result)) - { - return dictionary.Single(x => x.Value.Id == preValId.Result).Value.Value; - } - - LogHelper.Warn("Could not find a pre value with ID " + preValId + " for property alias " + property.Alias); - } - } - - return base.FormatValueForCache(property); - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Web/PropertyEditors/FileUploadValueEditor.cs b/src/Umbraco.Web/PropertyEditors/FileUploadValueEditor.cs index af20c14f3a..bb0f3432f6 100644 --- a/src/Umbraco.Web/PropertyEditors/FileUploadValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/FileUploadValueEditor.cs @@ -54,17 +54,10 @@ namespace Umbraco.Web.PropertyEditors //check the editorValue value to see if we need to clear the files or not. var clear = false; - if (editorValue.Value.IsNullOrWhiteSpace() == false && editorValue.Value.StartsWith("{clearFiles:")) + var json = editorValue.Value as JObject; + if (json != null && json["clearFiles"] != null && json["clearFiles"].Value()) { - try - { - var parsed = JObject.Parse(editorValue.Value); - clear = parsed["clearFiles"].Value(); - } - catch (JsonReaderException) - { - clear = false; - } + clear = json["clearFiles"].Value(); } var currentPersistedValues = new string[] {}; diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 966d3a52b1..3d40dfbb7a 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -318,11 +318,10 @@ - - +