mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
@@ -1,16 +1,57 @@
|
||||
using Orchard.Taxonomies.Services;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.Core.Title.Models;
|
||||
using Orchard.Taxonomies.Fields;
|
||||
using Orchard.Taxonomies.Services;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Taxonomies.Models;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Data;
|
||||
using Orchard.Taxonomies.Settings;
|
||||
|
||||
namespace Orchard.Taxonomies.Handlers {
|
||||
[UsedImplicitly]
|
||||
public class TaxonomyPartHandler : ContentHandler {
|
||||
public TaxonomyPartHandler(IRepository<TaxonomyPartRecord> repository, ITaxonomyService taxonomyService) {
|
||||
public TaxonomyPartHandler(
|
||||
IRepository<TaxonomyPartRecord> repository,
|
||||
ITaxonomyService taxonomyService,
|
||||
IContentDefinitionManager contentDefinitionManager) {
|
||||
|
||||
string previousName = null;
|
||||
|
||||
Filters.Add(StorageFilter.For(repository));
|
||||
OnPublished<TaxonomyPart>((context, part) => taxonomyService.CreateTermContentType(part));
|
||||
OnPublished<TaxonomyPart>((context, part) => {
|
||||
taxonomyService.CreateTermContentType(part);
|
||||
|
||||
if (previousName != null && part.Name != previousName) {
|
||||
|
||||
// remove previous term type
|
||||
contentDefinitionManager.DeleteTypeDefinition(previousName + " Term");
|
||||
|
||||
// update existing fields
|
||||
foreach (var partDefinition in contentDefinitionManager.ListPartDefinitions()) {
|
||||
foreach (var field in partDefinition.Fields) {
|
||||
if (field.FieldDefinition.Name == typeof (TaxonomyField).Name) {
|
||||
|
||||
if (field.Settings.GetModel<TaxonomyFieldSettings>().Taxonomy == previousName) {
|
||||
contentDefinitionManager.AlterPartDefinition(partDefinition.Name,
|
||||
cfg => cfg.WithField(field.Name,
|
||||
builder => builder.WithSetting("TaxonomyFieldSettings.Taxonomy", part.Name)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
OnLoading<TaxonomyPart>( (context, part) => part.TermsField.Loader(x => taxonomyService.GetTerms(part.Id)));
|
||||
|
||||
OnUpdating<TitlePart>((context, part) => {
|
||||
// if altering the title of a taxonomy, save the name
|
||||
if (part.As<TaxonomyPart>() != null) {
|
||||
previousName = part.Title;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -11,7 +11,6 @@ namespace Orchard.Taxonomies.Services {
|
||||
TaxonomyPart GetTaxonomyBySlug(string slug);
|
||||
void CreateTermContentType(TaxonomyPart taxonomy);
|
||||
void DeleteTaxonomy(TaxonomyPart taxonomy);
|
||||
void EditTaxonomy(TaxonomyPart taxonomy, string oldName);
|
||||
|
||||
IEnumerable<TermPart> GetAllTerms();
|
||||
IEnumerable<TermPart> GetTerms(int taxonomyId);
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.Taxonomies.Fields;
|
||||
using Orchard.Taxonomies.Models;
|
||||
using Orchard.Autoroute.Models;
|
||||
using Orchard.ContentManagement;
|
||||
@@ -101,14 +102,6 @@ namespace Orchard.Taxonomies.Services {
|
||||
|
||||
}
|
||||
|
||||
public void EditTaxonomy(TaxonomyPart taxonomy, string oldName) {
|
||||
// Rename term definition
|
||||
_contentDefinitionManager.AlterTypeDefinition(taxonomy.TermTypeName, cfg => cfg
|
||||
.WithSetting("Taxonomy", taxonomy.Name)
|
||||
.DisplayedAs(taxonomy.Name + " Term")
|
||||
);
|
||||
}
|
||||
|
||||
public void DeleteTaxonomy(TaxonomyPart taxonomy) {
|
||||
_contentManager.Remove(taxonomy.ContentItem);
|
||||
|
||||
|
Reference in New Issue
Block a user