From 6df794b928ee62a33ff7a4af727e072fd62d7cf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=BA=AE?= Date: Mon, 2 Nov 2020 11:21:43 +0800 Subject: [PATCH 1/3] Content list, select content type, taxonomies filter only show the content definition used. --- .../TaxonomyContentsAdminListDisplayDriver.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs index 5d60b35b03e..690ed5fdd4b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.Localization; using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; +using OrchardCore.ContentManagement.Metadata; using OrchardCore.Contents.ViewModels; using OrchardCore.DisplayManagement; using OrchardCore.DisplayManagement.Handlers; @@ -13,6 +14,7 @@ using OrchardCore.DisplayManagement.Views; using OrchardCore.Entities; using OrchardCore.Settings; +using OrchardCore.Taxonomies.Fields; using OrchardCore.Taxonomies.Models; using OrchardCore.Taxonomies.Settings; using OrchardCore.Taxonomies.ViewModels; @@ -25,15 +27,18 @@ public class TaxonomyContentsAdminListDisplayDriver : DisplayDriver stringLocalizer) { _siteService = siteService; _contentManager = contentManager; + _contentDefinitionManager = contentDefinitionManager; S = stringLocalizer; } @@ -46,8 +51,18 @@ public override async Task EditAsync(ContentOptionsViewModel mod return null; } + var taxonomyContentItemIds = settings.TaxonomyContentItemIds; + if (!string.IsNullOrWhiteSpace(model.SelectedContentType)) + { + var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(model.SelectedContentType); + var fieldDefinitions = contentTypeDefinition + .Parts.SelectMany(x => x.PartDefinition.Fields.Where(f => f.FieldDefinition.Name == nameof(TaxonomyField))); + var fieldTaxonomyContentItemIds = fieldDefinitions.Select(x => x.GetSettings().TaxonomyContentItemId); + taxonomyContentItemIds = taxonomyContentItemIds.Intersect(fieldTaxonomyContentItemIds).ToArray(); + } + var results = new List(); - var taxonomies = await _contentManager.GetAsync(settings.TaxonomyContentItemIds); + var taxonomies = await _contentManager.GetAsync(taxonomyContentItemIds); var position = 5; foreach (var taxonomy in taxonomies) From 1e9ad53005784741a13d7be5863df6389bba9791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=BA=AE?= Date: Wed, 4 Nov 2020 13:02:50 +0800 Subject: [PATCH 2/3] add : if (!taxonomyContentItemIds.Any()) return null; --- .../Drivers/TaxonomyContentsAdminListDisplayDriver.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs index 690ed5fdd4b..0067594e948 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs @@ -59,6 +59,7 @@ public override async Task EditAsync(ContentOptionsViewModel mod .Parts.SelectMany(x => x.PartDefinition.Fields.Where(f => f.FieldDefinition.Name == nameof(TaxonomyField))); var fieldTaxonomyContentItemIds = fieldDefinitions.Select(x => x.GetSettings().TaxonomyContentItemId); taxonomyContentItemIds = taxonomyContentItemIds.Intersect(fieldTaxonomyContentItemIds).ToArray(); + if (!taxonomyContentItemIds.Any()) return null; } var results = new List(); From d1efe75aaa0ec6eedd277f1842d66dfb2fbeae89 Mon Sep 17 00:00:00 2001 From: Dean Marcussen Date: Wed, 4 Nov 2020 13:43:33 +0000 Subject: [PATCH 3/3] Update TaxonomyContentsAdminListDisplayDriver.cs --- .../Drivers/TaxonomyContentsAdminListDisplayDriver.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs index 0067594e948..c5064a17374 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs @@ -52,14 +52,18 @@ public override async Task EditAsync(ContentOptionsViewModel mod } var taxonomyContentItemIds = settings.TaxonomyContentItemIds; - if (!string.IsNullOrWhiteSpace(model.SelectedContentType)) + if (!String.IsNullOrEmpty(model.SelectedContentType)) { var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(model.SelectedContentType); var fieldDefinitions = contentTypeDefinition .Parts.SelectMany(x => x.PartDefinition.Fields.Where(f => f.FieldDefinition.Name == nameof(TaxonomyField))); var fieldTaxonomyContentItemIds = fieldDefinitions.Select(x => x.GetSettings().TaxonomyContentItemId); taxonomyContentItemIds = taxonomyContentItemIds.Intersect(fieldTaxonomyContentItemIds).ToArray(); - if (!taxonomyContentItemIds.Any()) return null; + + if (!taxonomyContentItemIds.Any()) + { + return null; + } } var results = new List(); @@ -104,7 +108,6 @@ public override async Task EditAsync(ContentOptionsViewModel mod if (results.Any()) { return Combine(results); - } return null;