Files
Orchard/src/Orchard.Web/Modules/Orchard.Taxonomies/Handlers/TaxonomyPartHandler.cs
Wojciech Gadziński b9973d91d8 Move all usages of LazyField to Orchard.ContentManagement.Utilities.LazyField
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.
2015-04-26 23:56:04 +02:00

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;
}
});
}
}
}