Skip to content

Commit c5098f6

Browse files
authored
Multi-node picker: Validate content type when filter is configured but object type is not (closes #21338) (#21342)
Validate content type for multi-node picker when content types are defined but the object type is not (consider as being for a document).
1 parent aa0d636 commit c5098f6

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/Umbraco.Infrastructure/PropertyEditors/MultiNodeTreePickerPropertyEditor.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
using System.ComponentModel.DataAnnotations;
55
using System.Text.Json.Nodes;
6-
using Microsoft.Extensions.DependencyInjection;
7-
using Umbraco.Cms.Core.DependencyInjection;
86
using Umbraco.Cms.Core.IO;
97
using Umbraco.Cms.Core.Models;
108
using Umbraco.Cms.Core.Models.Editors;
@@ -348,18 +346,21 @@ public IEnumerable<ValidationResult> Validate(
348346

349347
Guid[] allowedTypes = configuration?.Filter?.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries).Select(Guid.Parse).ToArray() ?? [];
350348

351-
// We can't validate if there is no object type, and we don't need to if there's no filter.
352-
if (entityReferences is null || allowedTypes.Length == 0 || configuration?.TreeSource?.ObjectType is null)
349+
// Don't need to validate if there's no filter.
350+
if (entityReferences is null || allowedTypes.Length == 0)
353351
{
354352
return validationResults;
355353
}
356354

355+
// If no object type is specified, it's considered as document.
356+
var objectType = configuration?.TreeSource?.ObjectType ?? DocumentObjectType;
357+
357358
using ICoreScope scope = _coreScopeProvider.CreateCoreScope();
358359

359360
Guid?[] uniqueContentTypeKeys = entityReferences
360361
.Select(x => x.Unique)
361362
.Distinct()
362-
.Select(x => GetContent(configuration.TreeSource.ObjectType, x))
363+
.Select(x => GetContent(objectType, x))
363364
.Select(x => x?.ContentType.Key)
364365
.Distinct()
365366
.ToArray();

tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/MultiNodeTreePickerValidationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@ public void Validates_Object_Type()
135135
[TestCase(false, false, true, MultiNodeTreePickerPropertyEditor.MultiNodeTreePickerPropertyValueEditor.DocumentObjectType)]
136136
[TestCase(false, false, true, MultiNodeTreePickerPropertyEditor.MultiNodeTreePickerPropertyValueEditor.MediaObjectType)]
137137
[TestCase(false, false, true, MultiNodeTreePickerPropertyEditor.MultiNodeTreePickerPropertyValueEditor.MemberObjectType)]
138+
[TestCase(false, true, false, null)] // Null object type should be treated as being for document.
138139
[TestCase(false, true, false, MultiNodeTreePickerPropertyEditor.MultiNodeTreePickerPropertyValueEditor.DocumentObjectType)]
139140
[TestCase(false, true, false, MultiNodeTreePickerPropertyEditor.MultiNodeTreePickerPropertyValueEditor.MediaObjectType)]
140141
[TestCase(false, true, false, MultiNodeTreePickerPropertyEditor.MultiNodeTreePickerPropertyValueEditor.MemberObjectType)]
141-
public void Validates_Allowed_Type(bool shouldSucceed, bool hasAllowedType, bool findsContent, string objectType)
142+
public void Validates_Allowed_Type(bool shouldSucceed, bool hasAllowedType, bool findsContent, string? objectType)
142143
{
143144
var (valueEditor, _, contentService, mediaService, memberService) = CreateValueEditor();
144145

@@ -170,7 +171,6 @@ public void Validates_Allowed_Type(bool shouldSucceed, bool hasAllowedType, bool
170171

171172
var result = valueEditor.Validate(value, false, null, PropertyValidationContext.Empty());
172173
TestShouldSucceed(shouldSucceed, result);
173-
174174
}
175175

176176
private static (MultiNodeTreePickerPropertyEditor.MultiNodeTreePickerPropertyValueEditor ValueEditor,

0 commit comments

Comments
 (0)