Closed (fixed)
Project:
Helpers
Version:
master
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
3 Jul 2006 at 15:43 UTC
Updated:
7 Mar 2007 at 11:03 UTC
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
Comment #1
robertdouglass commentedThis has also been submitted for possible inclusion in core:
http://drupal.org/node/66982
Comment #2
Bèr Kessels commentedbit late, but committed nonetheless ;)
Comment #3
(not verified) commented