Adding Parts to Taxonomy Terms in Code

Topics: Customizing Orchard, Writing modules
Apr 17, 2013 at 3:09 PM
Hey there. I've just watched Bertrand's video on Taxonomies and am now trying to set that up in a custom module using FeatureEventHandlers and Migrations.cs. Can someone give me a hand here?

I want a Body part and an Image field added to the a Country taxonomy term. I've got this so far:

public int UpdateFrom18()
{
ContentDefinitionManager.AlterPartDefinition("AlbumPart", builder =>
builder.WithField("Country", fld =>
    fld.OfType("TaxonomyField")
    .WithSetting("DisplayName", "Country")
    .WithSetting("TaxonomyFieldSettings.Taxonomy", "Country")
    .WithSetting("TaxonomyFieldSettings.LeavesOnly", "False")
    .WithSetting("TaxonomyFieldSettings.SingleChoice", "False")
    .WithSetting("TaxonomyFieldSettings.Hint", "Select as many countries as you like.")
));
return 19;
}

I want to add lines to also create the Body part and Image fields.

Thanks as always!

Toby
Apr 17, 2013 at 6:58 PM
Edited Apr 17, 2013 at 6:58 PM
Have you considered creating a part, attaching the desired fields to this part and then attaching this to your Taxonomy type.
ContentDefinitionManager.AlterPartDefinition("MyPart", cfg =>
   cfg.WithField("Description", field => field.OfType("HtmlField"))
);
ContentDefinitionManager.AlterTypeDefinition("MyTaxonomy", cfg =>
    cfg.WithPart("MyPart")
);