将字段添加到Orchard CMS中的“站点设置”

时间:2015-01-23 14:00:55

标签: orchardcms orchardcms-1.8

此问题与此one类似,但它的目标是 Orchard CMS 1.8 ,其中重新设计了Site Settings

我已实施HomeSettingsPart来存储主页的自定义设置。

public class HomeSettingsPart : ContentPart { 
    public int NewsCount {
        get { return this.Retrieve(x => x.NewsCount); }
        set { this.Store(x => x.NewsCount, value); }
    }

    public int MaterialsCount {
        get { return this.Retrieve(x => x.MaterialsCount); }
        set { this.Store(x => x.MaterialsCount, value); }
    }

    public string WelcomeText {
        get { return this.Retrieve(x => x.WelcomeText); }
        set { this.Store(x => x.WelcomeText, value); }
    }

}

此外,我还为此部分添加了handler

public class HomeSettingsHandler : ContentHandler {

    public HomeSettingsHandler() {
        T = NullLocalizer.Instance;
        Filters.Add(new ActivatingFilter<HomeSettingsPart>("Site"));
        Filters.Add(new TemplateFilterForPart<HomeSettingsPart>("HomeSettings", "Parts.HomeSettings", "HomePage"));
    }

    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("HomePage")));
    }
}

一切都像this tutorial这段代码正常

现在我想在此内容部分添加MediaLibraryPickerField。我像往常一样在迁移中添加了此字段,我在AdminUI ContentManagement / Parts 部分中看到了它。

ContentDefinitionManager.AlterPartDefinition("HomeSettingsPart", x => x
    .WithField("HomeSlider", y => y 
        .OfType("MediaLibraryPickerField")
        .WithDisplayName("...")
        .WithSetting("MediaLibraryPickerFieldSettings.Multiple", "true")
     )
 );

但是,当我打开Settings/HomeSettings时,我只看到HomeSettingsPart的3个编辑器,并且没有为选择器字段呈现任何内容。 那么,我该如何正确添加这个字段呢?

感谢。

1 个答案:

答案 0 :(得分:0)

您还可以在文档网站中查看此页面:http://docs.orchardproject.net/Documentation/Adding-custom-settings