Posted by Osiride on September 22, 2008 at 9:24am
3 followers
Jump to:
| Project: | Taxonomy Access Control |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
| Issue tags: | TAC UX |
Issue Summary
Hi,
for a type of content, the numbers of options in a selectBox are determined by Taxonomy Acess Control.
for a particular group the selectBox had only one option.
Is possibile to automatically preselect that value?
thanks
Comments
#1
This is an issue that extends beyond the scope of TAC (See #180109: Only taxonomy term selected by default when there is only one)
I'm inclined to wait for that issue to be resolved before deciding what to do within TAC.
For my own sites where this issue is a problem, I've create a simple module with the following code:
<?php/**
* Implementation of hook_form_alter().
*/
function taxonomy_default_form_alter(&$form, $form_state, $form_id) {
if ($form['taxonomy']) {
foreach (array_keys($form['taxonomy']) as $vid) {
if ($form['taxonomy'][$vid]['#required'] && 0 == count($form['taxonomy'][$vid]['#default_value'])) {
if ($form['taxonomy'][$vid]['#options'][0]) {
$term_keys = array_keys($form['taxonomy'][$vid]['#options'][0]->option);
$form['taxonomy'][$vid]['#default_value'] = $term_keys[0];
}
}
}
}
}
?>
It seems to work.
#2
I should explain that this code will set the first (or only, if there is just one) item as the default selection (where no default selection exists) for only required fields.
#3
Doesn't look like the patch made it into core for 6.x, so it's probably worth patching in TAC.
#4
Marked #208798: upgrade to drupal 5.4 broke something as duplicate of this issue.
#5
Tagging.