我的 Orchard 代码生成的模块和部件不会在其驱动程序类中调用编辑器方法,因此不会加载显示部件属性的编辑器模板视图。它也不会写入模块创建的自定义数据库表,但它允许保存并创建关联的内容项。
作为项目的模块在visual studio中构建,我可以调试驱动程序的构造函数方法,但它不会命中Editor()或Display()或Editor()回发。
我使用 codegen 和代码生成扩展模块构建了一个 Orchard 模块。codegen 部分来自代码生成扩展模块,其余部分来自核心代码生成模块。我创建了模块,添加了带有属性的内容部分并生成了数据迁移。
以下是我使用的命令:
codegen module "TestModule.Foo"
codegen part "TestModule.Foo" Bar /Properties:Description:string,Broken:bool
codegen datamigration "TestModule.Foo"
我所做的唯一代码更改是通过迁移更新使类型 creatable()。我确认这已运行,并且我可以在管理员中看到用于创建新条形记录的内容类型选项。我还手动编辑了placement.info 文件以添加Parts_Bar_Edit 形状的放置标签。
这是正在使用的所有代码:
迁移.cs:
使用 System.Data;
使用 Orchard.ContentManagement.MetaData;
使用 Orchard.Core.Contents.Extensions;
使用 Orchard.Data.Migration;
命名空间 TestModule.Foo {
公共类迁移:DataMigrationImpl {
公共int创建(){
// 创建表 BarRecord
SchemaBuilder.CreateTable("BarRecord", table => table
.ContentPartRecord()
.Column("描述", DbType.String)
.Column("破碎", DbType.Boolean)
);
返回 1;
}
公共 int UpdateFrom1() {
ContentDefinitionManager.AlterTypeDefinition("BarRecord", cfg => cfg
.Creatable()
);
返回 2;
}
}
}
安置信息:
<放置>
<Place Parts_Bar="Content:5"/>
<Place Parts_Bar_Edit="Content:7.5" />
</放置>
型号/Bar.cs:
使用果园;
使用 Orchard.ContentManagement;
命名空间 TestModule.Foo.Models {
公共类栏:ContentPart {
公共字符串描述{
得到{返回记录。描述;}
设置 { Record.Description = 值;}
}
公共布尔破碎{
得到{返回记录。破碎;}
设置 { Record.Broken = value; }
}
}
}
模型/BarRecord.cs
使用果园;
使用 Orchard.ContentManagement.Records;
命名空间 TestModule.Foo.Models {
公共类 BarRecord : ContentPartRecord {
公共虚拟字符串描述{get; 放; }
公共虚拟布尔破碎{得到; 放; }
}
}
处理程序/BarHandler.cs
使用 JetBrains.Annotations;
使用 Orchard.ContentManagement.Handlers;
使用果园。数据;
使用 TestModule.Foo.Models;
命名空间 TestModule.Foo.Handlers
{
[隐式使用]
公共类 BarHandler : ContentHandler
{
公共 BarHandler(IRepository 存储库)
{
Filters.Add(StorageFilter.For(repository));
}
}
}
驱动程序/BarDrivers.cs
使用 JetBrains.Annotations;
使用 Orchard.ContentManagement;
使用 Orchard.ContentManagement.Drivers;
使用 Orchard.Localization;
使用 Orchard.UI.Notify;
使用 TestModule.Foo.Models;
命名空间 TestModule.Foo.Drivers
{
[隐式使用]
公共类 BarDriver : ContentPartDriver
{
私有只读 INotifier _notifier;
private const string TemplateName = "Parts/Bar";
公共定位器 T { 获取;放; }
公共 BarDriver(INotifier 通知程序)
{
_notifier = 通知器;
T = NullLocalizer.Instance;
}
protected override DriverResult Display(Bar part, string displayType, dynamic shapeHelper)
{
return ContentShape("Parts_Bar",
() => shapeHelper.Parts_Bar(ContentItem: part.ContentItem));
}
protected override DriverResult Editor(Bar part, dynamic shapeHelper)
{
return ContentShape("Parts_Bar",
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model:part, Prefix: Prefix));`
}
protected override DriverResult Editor(Bar part, IUpdateModel updater, dynamic shapeHelper)
{
if (updater.TryUpdateModel(part, Prefix, null, null))
{
_notifier.Information(T("栏编辑成功"));
}
别的
{
_notifier.Error(T("柱状图更新出错!"));
}
返回编辑器(部分,shapeHelper);
}
}
}
视图/EditorTemplates/Parts/Bar.cshtml
@model TestModule.Foo.Models.Bar
@使用果园。内容管理;
@{ Layout.Title = T("编辑栏").ToString(); }
<字段集>
<legend>@T("条形设置")</legend>
<div>
@Html.LabelFor(m => m.Description, @T("Description"))
@Html.EditorFor(m => m.Description)
@Html.ValidationMessageFor(m => m.Description, "*")
</div>
<div>
@Html.LabelFor(m => m.Broken, @T("Broken"))
@Html.EditorFor(m => m.Broken)
@Html.ValidationMessageFor(m => m.Broken, "*")
</div>
</fieldset>
视图/零件/Bar.cshtml
@model 动态
我正在使用 Orchard 1.6.1,并且能够在 1.7rc 上复制相同的行为。在这一点上,我完全被难住和沮丧,所以任何帮助将不胜感激。谢谢。