I am trying to set the default value for the Content Taxonomy field in hook_form_alter, but cannot bind the desired format. I tried this and many options:
foreach (element_children($form) as $child) { // Set $default_value. if ($form[$child]['tids']) { // This, for Content Taxonomy fields, isn't working: $form[$child]['tids']['#default_value'] = array('value' => $default_value); dsm($form[$child]['tids']['#default_value']); } else { // This, for other fields, is working: $form[$child][0]['#default_value']['value'] = $default_value; } }
Can someone tell me what I am missing?
Edit: In response to Henrik Opel (thanks for participating), here is a printout from the corresponding form field with my changes to the default fields commented out, showing the "#default_value" field I'm trying to influence.
It also shows that the widget parameter I am using is Hierarchical choice (could this be a factor?). In the dsm () code above, changes to the default value are recognized, but they are not processed later.
field_name_of_content_taxonomy_field (Array, 3 elements) #tree (Boolean) TRUE #weight (String, 1 characters ) 5 tids (Array, 7 elements) #title (String, 10 characters ) Vocabulary_name #type (String, 19 characters ) hierarchical_select #weight (String, 1 characters ) 5 #config (Array, 15 elements)
source share