There are several modules that bind a variable to one or more taxonomies. This is usually done in hook_settings. Here is a function that takes a variable name, a boolean for multiple, and returns a $form array to achieve the vocabulary binding.

/**
 * This would be a very nice function to have in core
 *
 * @param string $variable_name 
 *     the name of the variable that is to be bound to a vocabulary
 * @param bool $multiple
 *     whether or not multiple vocabularies should be bound to this vocabulary
 * @return array
 *     a form array suitable for use in hook_settings
 */
function taxonomy_vocabulary_binding($variable_name, $multiple = FALSE) {
	$form[$variable_name] = array(
    '#title' => t('Vocabularies associated with %variable', array('%variable' => $variable_name)),
    '#default_value' => variable_get($variable_name, array()),
    '#description' => t('These vocabularies will be bound to the variable %variable. You can get this list of vocabulary ids later by using variable_get("%variable", array());.', array('%variable' => $variable_name, '%variable' => $variable_name)),
  );
  
  $form[$variable_name]['#type'] = $multiple ? 'checkboxes' : 'radios';
  
  	  
  $options = array();
  foreach(taxonomy_get_vocabularies() as $vid => $vocabulary) {
    $options[$vid] = $vocabulary->name;
  }

  $form[$variable_name]['#options'] = $options;

  return $form;
}

Comments

robertdouglass’s picture

This has also been submitted for possible inclusion in core:
http://drupal.org/node/66982

Bèr Kessels’s picture

Status: Needs review » Fixed

bit late, but committed nonetheless ;)

Anonymous’s picture

Status: Fixed » Closed (fixed)