Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When filtered by content type only show taxonomies from that type #7480

Merged
merged 3 commits into from
Nov 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
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;
using OrchardCore.DisplayManagement.ModelBinding;
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;
Expand All @@ -25,15 +27,18 @@ public class TaxonomyContentsAdminListDisplayDriver : DisplayDriver<ContentOptio

private readonly ISiteService _siteService;
private readonly IContentManager _contentManager;
private readonly IContentDefinitionManager _contentDefinitionManager;
private readonly IStringLocalizer S;

public TaxonomyContentsAdminListDisplayDriver(
ISiteService siteService,
IContentManager contentManager,
IContentDefinitionManager contentDefinitionManager,
IStringLocalizer<TaxonomyContentsAdminListDisplayDriver> stringLocalizer)
{
_siteService = siteService;
_contentManager = contentManager;
_contentDefinitionManager = contentDefinitionManager;
S = stringLocalizer;
}

Expand All @@ -46,8 +51,23 @@ public override async Task<IDisplayResult> EditAsync(ContentOptionsViewModel mod
return null;
}

var taxonomyContentItemIds = settings.TaxonomyContentItemIds;
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<TaxonomyFieldSettings>().TaxonomyContentItemId);
taxonomyContentItemIds = taxonomyContentItemIds.Intersect(fieldTaxonomyContentItemIds).ToArray();

if (!taxonomyContentItemIds.Any())
{
return null;
}
}

chinasqzl marked this conversation as resolved.
Show resolved Hide resolved
var results = new List<IDisplayResult>();
var taxonomies = await _contentManager.GetAsync(settings.TaxonomyContentItemIds);
var taxonomies = await _contentManager.GetAsync(taxonomyContentItemIds);

var position = 5;
foreach (var taxonomy in taxonomies)
Expand Down Expand Up @@ -88,7 +108,6 @@ public override async Task<IDisplayResult> EditAsync(ContentOptionsViewModel mod
if (results.Any())
{
return Combine(results);

}

return null;
Expand Down