通过迁移创建新的内容类型,添加到他的内容字段,但它们不会显示在仪表板中。
仪表板中的内容类型视图:
我的代码出了什么问题?
public int UpdateFrom2() {
var name = "ProductViaCode";
ContentDefinitionManager.AlterPartDefinition(
string.Format("{0}Part", name),
b => b
.Attachable()
.WithField("ProductId", cfg => cfg
.OfType("InputField")
.WithDisplayName("Product Id")));
ContentDefinitionManager.AlterTypeDefinition(
name, cfg => cfg
.WithPart(typeof(CommonPart).Name)
.WithPart(typeof(AutoroutePart).Name)
.WithPart(typeof(BodyPart).Name)
.WithPart(typeof(TitlePart).Name)
.WithPart(typeof(MenuPart).Name)
.Creatable()
.Draftable()
.Listable()
.Securable());
return 3;
}
答案 0 :(得分:2)
正如@Xceno所说,您没有将该部分添加到您的内容类型中。但是,通过执行此操作,它不会显示在“字段”部分下,而是显示在“部件”部分下的“ProductViaCode”下。这是因为你用'Part'作为后缀。
要使其显示在类型的“字段”部分下,您可以将字段添加到具有相同类型名称的部分,然后将该部分添加到您的类型中:< / p>
var name = "ProductViaCode";
ContentDefinitionManager.AlterPartDefinition(
// Without 'Part' postfix
name,
b => b
.Attachable()
.WithField("ProductId", cfg => cfg
.OfType("InputField")
.WithDisplayName("Product Id")));
// Don't forget to add the part to the type
ContentDefinitionManager.AlterTypeDefinition(name, cfg => cfg
.WithPart(name));