mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00

There is one change which have to verify: Orchard.ContentManagement.Handlers.StorageFilter Orchard.ContentManagement.Handlers.StorageVersionFilter because I removed _value parameter from loader delegate - it was pointless and used nowhere except above filters.
55 lines
2.3 KiB
C#
55 lines
2.3 KiB
C#
using Orchard.ContentManagement;
|
|
using Orchard.ContentManagement.MetaData;
|
|
using Orchard.Core.Title.Models;
|
|
using Orchard.Taxonomies.Fields;
|
|
using Orchard.Taxonomies.Services;
|
|
using Orchard.Taxonomies.Models;
|
|
using Orchard.ContentManagement.Handlers;
|
|
using Orchard.Data;
|
|
using Orchard.Taxonomies.Settings;
|
|
using System;
|
|
|
|
namespace Orchard.Taxonomies.Handlers {
|
|
public class TaxonomyPartHandler : ContentHandler {
|
|
public TaxonomyPartHandler(
|
|
IRepository<TaxonomyPartRecord> repository,
|
|
ITaxonomyService taxonomyService,
|
|
IContentDefinitionManager contentDefinitionManager) {
|
|
|
|
string previousName = null;
|
|
|
|
Filters.Add(StorageFilter.For(repository));
|
|
OnPublished<TaxonomyPart>((context, part) => {
|
|
|
|
if (part.TermTypeName == null) {
|
|
// is it a new taxonomy ?
|
|
taxonomyService.CreateTermContentType(part);
|
|
}
|
|
else {
|
|
// 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(() => 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;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
} |