Fixes issues with U4-7318
This commit is contained in:
@@ -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<string, object>
|
||||
{
|
||||
{"idType", "int"}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Umbraco.Web.PropertyEditors
|
||||
{
|
||||
//default it to multi picker
|
||||
InternalPreValues["multiPicker"] = "1";
|
||||
InternalPreValues["idType"] = "int";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -100,10 +100,6 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
/// </returns>
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -208,9 +208,9 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
/// <returns>
|
||||
/// The <see cref="Type"/>.
|
||||
/// </returns>
|
||||
public virtual Type GetPropertyValueType(PublishedPropertyType propertyType)
|
||||
public Type GetPropertyValueType(PublishedPropertyType propertyType)
|
||||
{
|
||||
return IsMultipleDataType(propertyType.DataTypeId) ? typeof(IEnumerable<IPublishedContent>) : typeof(IPublishedContent);
|
||||
return IsMultipleDataType(propertyType.DataTypeId, propertyType.PropertyEditorAlias) ? typeof(IEnumerable<IPublishedContent>) : typeof(IPublishedContent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -219,10 +219,11 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
/// <param name="dataTypeId">
|
||||
/// The data type id.
|
||||
/// </param>
|
||||
/// <param name="propertyEditorAlias"></param>
|
||||
/// <returns>
|
||||
/// The <see cref="bool"/>.
|
||||
/// </returns>
|
||||
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<bool>().Result;
|
||||
if (preVals.ContainsKey("multiPicker"))
|
||||
{
|
||||
var preValue = preVals
|
||||
.FirstOrDefault(x => string.Equals(x.Key, "multiPicker", StringComparison.InvariantCultureIgnoreCase))
|
||||
.Value;
|
||||
|
||||
return preValue != null && preValue.Value.TryConvertTo<bool>().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<bool>().Result;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user