using taxonomy as a property of a custom part

Topics: Writing modules
Apr 29, 2013 at 7:37 PM
Hi all,
It's a little sad that this great thing does not have any documentation on how to implement it on a custom part through code :) could someone please provide me with a good link to do so?

This is what I have found so far:

ContentDefinitionManager.AlterPartDefinition("ProductPart", builder =>
        builder.WithField("Materials", fld => fld.OfType("TaxonomyField")
            .WithSetting("DisplayName", "Materials")
            .WithSetting("TaxonomyFieldSettings.Taxonomy", "Materials")
            .WithSetting("TaxonomyFieldSettings.LeavesOnly", "False")
            .WithSetting("TaxonomyFieldSettings.SingleChoice", "False")
How do I make sure the taxonomy "Materials" exists?
should I define a property in my Product Part?
When I should have to define a property in my product part, what type does it need since it's multiple choice? (and what would it be when having single choice?)
Should I define a property in my Record? and what type?
Apr 30, 2013 at 9:52 AM
  1. To ensure that "Materials" exist, use the taxonomy service to get a taxonomy by that name. If it's null, create it. Look at Contrib.Taxonomies to learn how to work with taxonomies and terms programmatically.
  2. No
  3. N/a
  4. N/a
May 6, 2013 at 6:34 PM
hey mate,

I still have quite some questions before I would be able to get this one done.
What should I do with my edit view? How will this be programmed? How can I display the taxonomy field?
May 9, 2013 at 6:56 AM
anyone? :) any examples of how the editor view would look like? I suppose I have to select a view from taxonomy itself?
May 22, 2013 at 11:05 AM

I'm still not successfull in adding this field to my part. I'm not good enough with orchard just yet to just look at the code and copy it. Is there a tutorial or another forum post about it?
May 27, 2013 at 1:38 PM
Well, the beauty of attaching existing content fields to parts is that you don't have to program the editor; it's provided for you by the field's driver.

To see how the editor looks like, simply use the admin and manually attach a TaxonomyField to a part, make sure that part s attached to some type, then create a new content item of that type.