📅  最后修改于: 2022-03-11 14:59:05.455000             🧑  作者: Mango
// PART DEFINITION
ContentDefinitionManager.AlterPartDefinition("ProductPart", p => p
.WithDescription("Product part")
// To select other contents ( on this example "ProductPresentation" content type )
.WithField("ProductPresentation", f => f
.OfType("ContentPickerField")
.WithDisplayName("Product presentation")
.WithSetting("ContentPickerFieldSettings.Required", "True")
.WithSetting("ContentPickerFieldSettings.Multiple", "True")
.WithSetting("ContentPickerFieldSettings.ShowContentTab", "True")
.WithSetting("ContentPickerFieldSettings.Hint", "Please select product's presentation")
.WithSetting("ContentPickerFieldSettings.DisplayedContentTypes", "ProductPresentation")
)
// To select images
.WithField("ProductImageField", f => f
.OfType("MediaLibraryPickerField")
.WithDisplayName("Product image")
.WithSetting("MediaLibraryPickerFieldSettings.Hint", "Please select product's image")
.WithSetting("MediaLibraryPickerFieldSettings.Required", "True")
.WithSetting("MediaLibraryPickerFieldSettings.Multiple", "False")
)
// To add a taxonomy field called "ProductLines"
.WithField("Category", fcfg => fcfg
.OfType("TaxonomyField")
.WithDisplayName("Category")
.WithSetting("TaxonomyFieldSettings.Taxonomy", "ProductLines")
.WithSetting("TaxonomyFieldSettings.LeavesOnly", "True")
.WithSetting("TaxonomyFieldSettings.Required", "True")
.WithSetting("TaxonomyFieldSettings.SingleChoice", "False")
.WithSetting("TaxonomyFieldSettings.Autocomplete", "False")
.WithSetting("TaxonomyFieldSettings.AllowCustomTerms", "False")
.WithSetting("TaxonomyFieldSettings.Hint", "Please select product's category")
)
.Attachable()
);
// CONTENT TYPE DEFINITION
ContentDefinitionManager.AlterTypeDefinition("Product", cfg => cfg
.DisplayedAs("Product")
.WithPart(
"CommonPart", c => c
.WithSetting("DateEditorSettings.ShowDateEditor", "False")
.WithSetting("OwnerEditorSettings.ShowOwnerEditor", "False")
)
.WithPart("ProductPart")
.WithPart("TitlePart", c => c.WithSetting("Hint", "Please enter the product name"))
.WithPart("BodyPart", c => c.WithSetting("Hint", "Please enter the product description"))
.WithPart("LocalizationPart")
.WithPart("AutoroutePart", partBuilder => partBuilder
.WithSetting("AutorouteSettings.AllowCustomPattern", "true")
.WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "true")
.WithSetting("AutorouteSettings.PatternDefinitions", "[{Name:'Product Title', Pattern: 'product/{Content.Slug}', Description: 'product/title-product'}]"))
.Listable()
.Draftable()
.Creatable()
.Securable()
.Indexed()
);