Skip to content

Commit

Permalink
Update Taxomony field (#14477)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored Oct 12, 2023
1 parent 93d1993 commit f377a07
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
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

0 comments on commit f377a07

Please sign in to comment.