The object of this exercise is to set a default value for a single-selection vocabulary item in the "Add a story" form. I have written the necessary code in a hook_forum_alter() function; I know that it's doing what I think it should do, and the form processor is ignoring it.
By examining $form values for a node in which the vocabulary is already set, I know that the value is represented at this point by the array element
$form['taxonomy'][$vid]['#default_value']
where $vid represents the vocabulary ID of the vocabulary being set. The value of this element should be a one-element array in which the element's value is the term ID of the selected vocabulary term.
I have done that. I have print_r'ed the value of $form['taxonomy'][$vid] before and after to confirm that I have done it right, and the form still displays with the vocabulary's value unset ("Please choose").
I think an example to copy would be the best thing for me at this point. There is an example in the forms_api_reference (in the description of select), but it must be for an older version of Drupal, because it doesn't look even vaguely like what I see in $form.
Comments
Never mind...
Got up this morning and looked at the results again. Problem. Repeated the test without changing anything. No problem.
Drupal does this to me occasionally. If you've seen similar things, and found the cause, I'd love to hear from you!
In many cases I have thought it must be something in a cache, but the problem persisted when I cleared every cache I could find, and some time later it disappeared on its own. This time I don't think "the cache" is even a plausible possibility.
something caches
I just tried to add a defualt value to a select value... no joy... renamed my field and it works... rename the field back to it's original value and default stops working...
would be good to know how to clear the cache ... but hope this helps someone at least figure out the problem