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

Update Taxomony field #14477

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
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 @@ -2,20 +2,29 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Localization;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Display.ContentDisplay;
using OrchardCore.ContentManagement.Display.Models;
using OrchardCore.DisplayManagement.ModelBinding;
using OrchardCore.DisplayManagement.Views;
using OrchardCore.Mvc.ModelBinding;
using OrchardCore.Taxonomies.Models;
using OrchardCore.Taxonomies.ViewModels;

namespace OrchardCore.Taxonomies.Drivers
{
public class TaxonomyPartDisplayDriver : ContentPartDisplayDriver<TaxonomyPart>
{
private readonly IStringLocalizer S;

public TaxonomyPartDisplayDriver(IStringLocalizer<TaxonomyPartDisplayDriver> stringLocalizer)
{
S = stringLocalizer;
}

public override IDisplayResult Display(TaxonomyPart part, BuildPartDisplayContext context)
{
var hasItems = part.Terms.Any();
Expand All @@ -42,6 +51,11 @@ public override async Task<IDisplayResult> UpdateAsync(TaxonomyPart part, IUpdat

if (await updater.TryUpdateModelAsync(model, Prefix, t => t.Hierarchy, t => t.TermContentType))
{
if (string.IsNullOrWhiteSpace(model.TermContentType))
{
updater.ModelState.AddModelError(Prefix, nameof(model.TermContentType), S["The Term Content Type field is required."]);
}

if (!string.IsNullOrWhiteSpace(model.Hierarchy))
{
var originalTaxonomyItems = part.ContentItem.As<TaxonomyPart>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<div class="w-sm-75 w-lg-75 w-xl-50">
<label asp-for="TaxonomyContentItemId">@T["Taxonomy"]</label>
<select asp-for="TaxonomyContentItemId" class="form-select">
<option value="">@T["Select a Taxonomy"]</option>
@foreach (var taxonomy in taxonomies)
{
<option value="@taxonomy.ContentItemId">@taxonomy</option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<label asp-for="TermContentType" class="@Orchard.GetLabelCssClasses()">@T["Term Content Type"]</label>
<div class="@Orchard.GetEndCssClasses()">
<select asp-for="TermContentType" class="form-select" asp-items="@(new SelectList(termContentTypes, "Name", "DisplayName"))">
<option value="">@T["Select a term content type"]</option>
</select>
</div>
<span asp-validation-for="TermContentType"></span>
Expand All @@ -38,11 +39,11 @@
@if (termContentType != null)
{
<a class="btn btn-primary btn-sm"
asp-route-action="Create"
asp-route-controller="Admin"
asp-route-id="@Model.TaxonomyPart.TermContentType"
asp-route-taxonomyContentItemId="@Model.TaxonomyPart.ContentItem.ContentItemId"
asp-route-area="OrchardCore.Taxonomies">
asp-route-action="Create"
asp-route-controller="Admin"
asp-route-id="@Model.TaxonomyPart.TermContentType"
asp-route-taxonomyContentItemId="@Model.TaxonomyPart.ContentItem.ContentItemId"
asp-route-area="OrchardCore.Taxonomies">
@T["Add {0}", termContentType.DisplayName]
</a>
}
Expand Down