selectlist для таксономии с optgroup

function module_form_alter(&$form, &$form_state, $form_id) {
  if ($form['#form_id'] == 'post_node_form') {    // id формы
    $top_level = taxonomy_get_tree($vid = 2, $parent = 0, $max_depth = 1); // id словаря
    foreach ($top_level as $id => $term) {
      $options[$term->name] = array();
      $children = taxonomy_get_tree(2, $term->tid); // id словаря
      foreach ($children as $child) {
        $options[$term->name][$child->tid] = $child->name;
      }
    }
    $form['field_category']['und']['#options'] = $options;
  }
}