Create classification fields

To learn more about the different steps to create a custom field, read the For developers: Create custom fields for product types article.

Here is a list of the things that are specific for the classification field:

  • Field CLR type: The classification field does not use this parameter.
  • User friendly data type: UserFriendlyDataType.Classification
  • DB type: The classification field does not use this parameter.
  • Field type: typeof(HierarchicalTaxonomyField).FullName or typeof(FlatTaxonomyField).FullName

In addition, when creating a classification field you must perform the following:

  1. Get an instance of the taxonomy that is used by the field.
    To do this, you must call the GetTaxonomy method of the TaxonomyManager instance and pass the ID of the taxonomy as an argument.
  2. Skip the creating of a database mapping.
  3. Where creating the field definition set the following additional properties:
    • TaxonomyId
      Gets or sets the ID of the taxonomy that is used by the field.
    • AllowMultipleSelection
      Specifies whether the item will by classified by single taxon or by multiple taxa. Only the classification field requires this property. Set this property to true.
  4. Where creating the field definition set the FieldType property depending on the type of the taxonomy (flat or hierarchical).
  5. Skip the step where the database mappings are set.
  6. Set the following additional properties of the MetaField instance:
    • TaxonomyId
      Gets or sets the taxonomy used by field. Only the classification field requires this property.
    • TaxonomyProvider
      Gets or sets the provider of the taxonomy used by field. Only the classification field requires this property.
    • IsSingleTaxon
      Specifies whether the item will by classified by single taxon or by multiple taxa. Only the classification field requires this property.
  7. Add meta attribute ControlTag.
    This is the value of the attribute must be a taxonomy field control template. To get the value for the attribute, call the GetTaxonomyFieldControlTemplate static method and pass the name of the field and the instance of the taxonomy.

Here is a code example:

Want to learn more?

Sign up for our free beginner training. Boost your credentials through advanced courses and certification.
Register for Sitefinity training and certification.

Was this article helpful?