我的模块中有两种设置。
- 全局设置(针对整个模块)
- 本地设置(每个小部件都不同)
现在我有一个控制器,我想要这两种设置。
在控制器中,我可以获得如下全局设置:
var globalSettings = Services.WorkContext.CurrentSite.As<Interspire_MailingSettingsPart>();
但是我怎样才能获得本地设置?
两个处理程序:
全球的
公共类 MailingSettingsHandler: ContentHandler { 公共 MailingSettingsHandler(IRepository 存储库) { T = NullLocalizer.Instance; Filters.Add(new ActivatingFilter("Site")); Filters.Add(new TemplateFilterForPart("Nastavitve", "Parts/MailingSettings", "Interspire")); Filters.Add(StorageFilter.For(repository)); }
public Localizer T { get; set; } protected override void GetItemMetadata(GetContentItemMetadataContext context) { if (context.ContentItem.ContentType != "Site") return; base.GetItemMetadata(context); context.Metadata.EditorGroupInfo.Add(new GroupInfo(T("Interspire"))); }
}
当地的
公共类 MailingHandler : ContentHandler { public MailingHandler(IRepository repository) { Filters.Add(StorageFilter.For(repository)); } }
编辑:添加驱动程序,如果它可以帮助事情:
public class MailingDriver : ContentPartDriver<Interspire_MailingPart>
{
private readonly IOrchardServices _services;
public MailingDriver(INotifier notifier, IOrchardServices services)
{
_services = services;
}
protected override DriverResult Display(Interspire_MailingPart part, string displayType, dynamic shapeHelper)
{
var mailingSettings = _services.WorkContext.CurrentSite.As<Interspire_MailingSettingsPart>();
return ContentShape("Parts_Mailing",
() => shapeHelper.Parts_Mailing(
Url: mailingSettings.Url,
SubscribeFormID: part.SubscribeFormID
));
}
//GET
protected override DriverResult Editor(Interspire_MailingPart part, dynamic shapeHelper)
{
return ContentShape("Parts_Mailing_Edit",
() => shapeHelper.EditorTemplate(
TemplateName: "Parts/Mailing",
Model: part,
Prefix: Prefix));
_services.WorkContext.CurrentSite.As<Interspire_MailingPart>() = part;
}
//POST
protected override DriverResult Editor(Interspire_MailingPart part, IUpdateModel updater, dynamic shapeHelper)
{
updater.TryUpdateModel(part, Prefix, null, null);
return Editor(part, shapeHelper);
}
}