Added null check on taxonomyPart. (#8664)

This commit is contained in:
Andrea Piovanelli
2023-04-07 15:06:25 +02:00
committed by GitHub
parent 4455c66a64
commit ff70011b69

View File

@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Web.Management;
using Orchard.ContentManagement;
using Orchard.Core.Title.Models;
using Orchard.Environment.Extensions;
@@ -30,6 +31,11 @@ namespace Orchard.Taxonomies.Services {
.Where(r => r.Title == name)
.List()
.FirstOrDefault();
// Null check on taxonomyPart
// It can be null in the case of a TaxonomyField with not taxonomy selected (misconfiguration).
if (taxonomyPart == null) {
return null;
}
if (String.IsNullOrWhiteSpace(culture) || _localizationService.GetContentCulture(taxonomyPart.ContentItem) == culture)
return taxonomyPart;
else {