It is a pretty common use case that a module needs to identify a vocabulary that has significance to itself. The typical place to do this is in the settings hooks. This is a helper function that returns the form element to do this. I don't have stats about how many modules currently use this functionality, but I think it would justify its inclusion in core and make the end experience more consistent (and lower the bar for programming such modules - not that it was high to begin with).
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());.'),
);
$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;
}
If Dries and drumm are open to the idea (and have suggestions) I'll roll a patch.
Comments
Comment #1
robertdouglass commentedsmall fix
Comment #2
robertdouglass commentedsetting to review to hopefully get some feedback =)
Comment #3
Bèr Kessels commentedRobert, maybe it is a good idea if you give a concrete example of how and where to use this? I don't really understand why I would want this, but that is probably because I haven't created many such modules?
Do I understand it correctly if this could be the first in a whole range of such functions like
node_type_binding(), user_role_binding(), filter_format_binding() etc?
Comment #4
moshe weitzman commentedforum.module, glossary.module, og_vocab, ...
drumm was working on a module which had cool new form elements a long time ago. not sure where that is now.
Comment #5
bdragon commentedPatch?
Comment #6
nancydruI assume this is not in D6?
Comment #7
bdragon commentedMoving to 8.
Comment #8
jibranWe can save vocabulary settings in yml file because vocabulary is ConfigEntity now. So I think it is irrelevant now. Also see taxonomy.vocabulary.forums.yml for reference.
Comment #22
quietone commented@robertdouglass, thanks for helping to improve Drupal.
Based on the last comment here there are other ways to accomplish this.
The proposal doesn't met the Criteria for evaluating proposed changes. In this case, there is not demonstrated demand and support for the change.