public TaxonomyFieldQueryObjectType() { Name = nameof(TaxonomyField); Field <ListGraphType <StringGraphType>, IEnumerable <string> >() .Name("termContentItemIds") .Description("term content item ids") .PagingArguments() .Resolve(x => { return(x.Page(x.Source.TermContentItemIds)); }); Field <StringGraphType, string>() .Name("taxonomyContentItemId") .Description("taxonomy content item id") .Resolve(x => { return(x.Source.TaxonomyContentItemId); }); Field <ListGraphType <ContentItemInterface>, IEnumerable <ContentItem> >() .Name("termContentItems") .Description("the term content items") .PagingArguments() .ResolveAsync(async x => { var ids = x.Page(x.Source.TermContentItemIds); var context = (GraphQLContext)x.UserContext; var contentManager = context.ServiceProvider.GetService <IContentManager>(); var taxonomy = await contentManager.GetAsync(x.Source.TaxonomyContentItemId); if (taxonomy == null) { return(null); } var terms = new List <ContentItem>(); foreach (var termContentItemId in ids) { var term = TaxonomyOrchardHelperExtensions.FindTerm(taxonomy.Content.TaxonomyPart.Terms as JArray, termContentItemId); terms.Add(term); } return(terms); }); Field <ContentItemInterface, ContentItem>() .Name("taxonomyContentItem") .Description("the taxonomy content item") .ResolveAsync(async x => { var context = (GraphQLContext)x.UserContext; var contentManager = context.ServiceProvider.GetService <IContentManager>(); return(await contentManager.GetAsync(x.Source.TaxonomyContentItemId)); }); }
public async Task <IActionResult> Index(string id, string taxonomyid) { var taxonomyContentItem = await _contentManager.GetAsync(taxonomyid); var termContentItem = TaxonomyOrchardHelperExtensions.FindTerm(taxonomyContentItem.Content.TaxonomyPart.Terms as JArray, id); // This part is added automatically to all terms // termContentItem.Weld(new TermPart()); var model = await _contentItemDisplayManager.BuildDisplayAsync(termContentItem, this, "Detail"); //https://english.orchardproject.hu/blog/the-orchard-dynamic-page-pattern return(View(model)); }
public override async Task <IDisplayResult> UpdateAsync(TaxonomyField field, IUpdateModel updater, UpdateFieldEditorContext context) { var model = new EditTagTaxonomyFieldViewModel(); if (await updater.TryUpdateModelAsync(model, Prefix, f => f.TermContentItemIds)) { var settings = context.PartFieldDefinition.GetSettings <TaxonomyFieldSettings>(); field.TaxonomyContentItemId = settings.TaxonomyContentItemId; field.TermContentItemIds = model.TermContentItemIds == null ? Array.Empty <string>() : model.TermContentItemIds.Split(',', StringSplitOptions.RemoveEmptyEntries); if (settings.Required && field.TermContentItemIds.Length == 0) { updater.ModelState.AddModelError( nameof(EditTagTaxonomyFieldViewModel.TermContentItemIds), S["A value is required for '{0}'", context.PartFieldDefinition.DisplayName()]); } // Update display text for tags. var taxonomy = await _contentManager.GetAsync(settings.TaxonomyContentItemId, VersionOptions.Latest); if (taxonomy == null) { return(null); } var terms = new List <ContentItem>(); foreach (var termContentItemId in field.TermContentItemIds) { var term = TaxonomyOrchardHelperExtensions.FindTerm(taxonomy.Content.TaxonomyPart.Terms as JArray, termContentItemId); terms.Add(term); } field.SetTagNames(terms.Select(t => t.DisplayText).ToArray()); } return(Edit(field, context)); }
private ContentItem GetTermContentItem(TermEntry entry, ContentItem taxonomy) { // var term = default(TermPart); var termContentItem = default(ContentItem); if (taxonomy == null) { return(null); } if (!string.IsNullOrEmpty(entry.ContentItemId)) { termContentItem = TaxonomyOrchardHelperExtensions.FindTerm(taxonomy.Content.TaxonomyPart.Terms as JArray, entry.ContentItemId); } return(termContentItem); }