【问题标题】:Orchard CMS 1.10 adding Taxonomy with migration in a custom partOrchard CMS 1.10 在自定义部分中添加了带有迁移的分类法
【发布时间】:2016-05-03 22:04:04
【问题描述】:

我正在尝试向 orchard cms 中的自定义类型添加分类。

ContentDefinitionManager.AlterPartDefinition("ExpertPart", 
                     b => b
                    .WithField("ExpertOf", fld => fld            
                                                .OfType("TaxononmyField")
                                                .WithDisplayName("Expert Of")
                                                .WithSetting("TaxonomyFieldSettings.Taxonomy", "ExpertOf")
                                                .WithSetting("TaxonomyFieldSettings.LeavesOnly", "false")
                                                .WithSetting("TaxonomyFieldSettings.SingleChoice", "true")
                                                .WithSetting("TaxonomyFieldSettings.Required", "true")));

当我运行此代码时,分类显示在内容定义中的“部分”而不是“字段”下。我可以手动将其添加到字段中,并且效果很好。 Orchard 1.10 的新迁移代码是什么,允许您以编程方式将分类字段添加到自定义内容类型?

感谢您对此的帮助!所以我试过了。

ContentDefinitionManager.AlterTypeDefinition("Expert",
                                b => b.WithPart("ExpertPart"));

ContentDefinitionManager.AlterPartDefinition("ExpertPart",
                     b => b
                    .WithField("ExpertOf", fld => fld
                        .OfType("TaxononmyField")
                        .WithDisplayName("ExpertOf")
                        .WithSetting("TaxonomyFieldSettings.Taxonomy", "ExpertOf")
                        .WithSetting("TaxonomyFieldSettings.LeavesOnly", "false")
                        .WithSetting("TaxonomyFieldSettings.SingleChoice", "true")
                        .WithSetting("TaxonomyFieldSettings.Required", "true")));

当我运行此迁移时,然后进入部件的内容定义。内容定义中的“领域”下未列出专家。它列在“零件”下。您无法进入分类设置。这就是发生的事情

Orchard Problems

此外,内容编辑屏幕没有列出分类。所以我不能将专家部分附加到分类中。

【问题讨论】:

  • 您的代码中有错字:.OfType("TaxononmyField")
  • 谢谢!一直都是问题。

标签: orchardcms taxonomy custom-taxonomy


【解决方案1】:

你这样做:

ContentDefinitionManager.AlterPartDefinition("ExpertPart", ...

所以你说:将字段添加到 ExpertPart。当您在仪表板中手动将字段添加到内容类型的“字段”部分时,Orchard 会将其添加到与内容类型具有相同名称的部分(使用内容类型隐式创建)。 注意:这部分实际上并不存在,但果园会在加载类型时动态创建它。

因此,假设您的自定义内容类型称为“专家”,Orchard 会将仪表板中的字段添加到称为“专家”的部分。

因此,要让您的字段显示在字段下而不是部分下,您的迁移应该如下所示:

// Orchard can only handle these migrations if you explicitly add the
// Expert part to the Expert content type
ContentDefinitionManager.AlterTypeDefinition("Expert", type => type
    .WithPart("Expert"));

// Add the field to the part
ContentDefinitionManager.AlterPartDefinition("Expert", part => part
    .WithField("ExpertOf", fld => fld
        .OfType("TaxononmyField"));

【讨论】:

  • 感谢您的帮助。我在第一篇文章中添加了一些额外的细节。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多