This project is not covered by Drupal’s security advisory policy.

Seeking a new maintainer

Please contact Todd Nienkerk if you are interested in taking over maintenance of this module.

About Taxonomy Widget

Implements a new form element named taxonomy_widget for selecting a vocabulary and then a term within that vocabulary. The term list is dynamically populated by jQuery when a vocabulary is selected.

The element takes an array for the #default_value property with up to two keyed elements:

  • vid contains an integer representing the vocabulary ID. You set this if you want the list of terms to be pre-populated with terms from a specific vocabulary.
  • tid contains either a single integer or an array of integers representing the term IDs that should be selected by default in the element.
  • type contains a string with the machine readable name of a specific type. Set this value when you wish to constrain the list of vocabularies to those available only to a specific content type.

Additionally, the element acknowledges the #multiple property. If set to TRUE (default), the term select element will allow multiple terms to be selected. If set to FALSE, the term select element allow only a single term to be selected and will be rendered as a drop-down box.

An example usage of this element could be:

$form['taxonomy-select'] = array(
   '#type'          => 'taxonomy_widget',
   '#default_value' => array(
     'vid'  => 15,
     'type' => 'story',
     'tid'  => array(217, 234),
   ),
 );

Data returned for this element by the Form API will be an associative array containing two keys: vid and tid. The value for vid will be the selected vocabulary's ID. The value type for 'tid' will be depend on whether the element's #multiple property is set to TRUE or FALSE. If set to TRUE, the value will be an array containing the term IDs of the selected term. Data returned by this element with #multiple set to TRUE will resemble the following:

taxonomy-select => Array (
     [vid] => 25
     [tid] => Array (
         [318] => 318
         [518] => 518
     )
) 

If the element's #multiple property is set to FALSE, a single integer value will be returned for the tid. Data returned by this element with #multiple set to FALSE will resemble the following:

taxonomy-select => Array (
    [vid] => 25
    [tid] => 318
)

NOTE: This widget requires JavaScript to be enabled and does not gracefully degrade.

Dependency: jquery_update

Project information

Releases