Merge pull request #5491 from kjac/v8-feature-mntp-single-mode-improvements

V8: MNTP improvements when configured to select only one item
This commit is contained in:
Sebastiaan Janssen
2019-05-31 20:47:41 +02:00
committed by GitHub
2 changed files with 22 additions and 1 deletions

View File

@@ -157,6 +157,11 @@ function contentPickerController($scope, entityResource, editorState, iconHelper
// pre-value config on to the dialog options
angular.extend(dialogOptions, $scope.model.config);
// if we can't pick more than one item, explicitly disable multiPicker in the dialog options
if ($scope.model.config.maxNumber && parseInt($scope.model.config.maxNumber) === 1) {
dialogOptions.multiPicker = false;
}
// add the current filter (if any) as title for the filtered out nodes
if ($scope.model.config.filter) {
localizationService.localize("contentPicker_allowedItemTypes", [$scope.model.config.filter]).then(function (data) {

View File

@@ -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;
}
}
}