diff --git a/src/Umbraco.Web/PropertyEditors/MediaPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MediaPickerPropertyEditor.cs index e9a57aee24..8828f89a0b 100644 --- a/src/Umbraco.Web/PropertyEditors/MediaPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MediaPickerPropertyEditor.cs @@ -33,8 +33,19 @@ namespace Umbraco.Web.PropertyEditors internal class SingleMediaPickerPreValueEditor : PreValueEditor { - [PreValueField("startNodeId", "Start node", "mediapicker")] - public int StartNodeId { get; set; } + public SingleMediaPickerPreValueEditor() + { + Fields.Add(new PreValueField() + { + Key = "startNodeId", + View = "mediapicker", + Name = "Start node", + Config = new Dictionary + { + {"idType", "int"} + } + }); + } } } } diff --git a/src/Umbraco.Web/PropertyEditors/MultipleMediaPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MultipleMediaPickerPropertyEditor.cs index 450dffabd3..268ad30ffb 100644 --- a/src/Umbraco.Web/PropertyEditors/MultipleMediaPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultipleMediaPickerPropertyEditor.cs @@ -13,6 +13,7 @@ namespace Umbraco.Web.PropertyEditors { //default it to multi picker InternalPreValues["multiPicker"] = "1"; + InternalPreValues["idType"] = "int"; } /// diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/MediaPickerPropertyConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/MediaPickerPropertyConverter.cs index 69de94952b..921ec8cd16 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/MediaPickerPropertyConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/MediaPickerPropertyConverter.cs @@ -100,10 +100,6 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters /// public override bool IsConverter(PublishedPropertyType propertyType) { - // ** not sure if we want to convert the legacy media picker or not ** - if (propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.MediaPickerAlias)) - return false; - return propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.MediaPicker2Alias); } diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/MultipleMediaPickerPropertyConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/MultipleMediaPickerPropertyConverter.cs index ddb50a0e31..6be9b604da 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/MultipleMediaPickerPropertyConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/MultipleMediaPickerPropertyConverter.cs @@ -208,9 +208,9 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters /// /// The . /// - public virtual Type GetPropertyValueType(PublishedPropertyType propertyType) + public Type GetPropertyValueType(PublishedPropertyType propertyType) { - return IsMultipleDataType(propertyType.DataTypeId) ? typeof(IEnumerable) : typeof(IPublishedContent); + return IsMultipleDataType(propertyType.DataTypeId, propertyType.PropertyEditorAlias) ? typeof(IEnumerable) : typeof(IPublishedContent); } /// @@ -219,10 +219,11 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters /// /// The data type id. /// + /// /// /// The . /// - public bool IsMultipleDataType(int dataTypeId) + private bool IsMultipleDataType(int dataTypeId, string propertyEditorAlias) { // GetPreValuesCollectionByDataTypeId is cached at repository level; // still, the collection is deep-cloned so this is kinda expensive, @@ -230,12 +231,29 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters return Storages.GetOrAdd(dataTypeId, id => { - var preValue = _dataTypeService.GetPreValuesCollectionByDataTypeId(id) - .PreValuesAsDictionary - .FirstOrDefault(x => string.Equals(x.Key, "multiPicker", StringComparison.InvariantCultureIgnoreCase)) - .Value; + var preVals = _dataTypeService.GetPreValuesCollectionByDataTypeId(id).PreValuesAsDictionary; - return preValue != null && preValue.Value.TryConvertTo().Result; + if (preVals.ContainsKey("multiPicker")) + { + var preValue = preVals + .FirstOrDefault(x => string.Equals(x.Key, "multiPicker", StringComparison.InvariantCultureIgnoreCase)) + .Value; + + return preValue != null && preValue.Value.TryConvertTo().Result; + } + + //in some odd cases, the pre-values in the db won't exist but their default pre-values contain this key so check there + var propertyEditor = PropertyEditorResolver.Current.GetByAlias(propertyEditorAlias); + if (propertyEditor != null) + { + var preValue = propertyEditor.DefaultPreValues + .FirstOrDefault(x => string.Equals(x.Key, "multiPicker", StringComparison.InvariantCultureIgnoreCase)) + .Value; + + return preValue != null && preValue.TryConvertTo().Result; + } + + return false; }); }