If MNTP is configured to pick max 1 item, convert the value into IPublishedContent instead of IEnumerable<IPublishedContent>
This commit is contained in:
@@ -43,7 +43,9 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
=> PropertyCacheLevel.Snapshot;
|
||||
|
||||
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
|
||||
=> typeof (IEnumerable<IPublishedContent>);
|
||||
=> IsSingleNodePicker(propertyType)
|
||||
? typeof(IPublishedContent)
|
||||
: typeof(IEnumerable<IPublishedContent>);
|
||||
|
||||
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
|
||||
{
|
||||
@@ -73,6 +75,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
if (propertyType.EditorAlias.Equals(Constants.PropertyEditors.Aliases.MultiNodeTreePicker))
|
||||
{
|
||||
var udis = (Udi[])source;
|
||||
var isSingleNodePicker = IsSingleNodePicker(propertyType);
|
||||
|
||||
if ((propertyType.Alias != null && PropertiesToExclude.InvariantContains(propertyType.Alias)) == false)
|
||||
{
|
||||
@@ -102,9 +105,17 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
if (multiNodeTreePickerItem != null && multiNodeTreePickerItem.ItemType != PublishedItemType.Element)
|
||||
{
|
||||
multiNodeTreePicker.Add(multiNodeTreePickerItem);
|
||||
if (isSingleNodePicker)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isSingleNodePicker)
|
||||
{
|
||||
return multiNodeTreePicker.FirstOrDefault();
|
||||
}
|
||||
return multiNodeTreePicker;
|
||||
}
|
||||
|
||||
@@ -141,5 +152,10 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
private static bool IsSingleNodePicker(PublishedPropertyType propertyType)
|
||||
{
|
||||
return propertyType.DataType.ConfigurationAs<MultiNodePickerConfiguration>().MaxNumber == 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user