I have a Products taxonomy with all possible product names offered by the organization, Order content type to place an order and ordering form. Order content type includes field collection with term reference field referencing to Product taxonomy. The case is that I need to predefine field collection items with all possible selected Product terms on ordering form. Items number = count(Products terms)
I tried to use field_multiple_value_form function to generate items, but in this case I can't predefine default value for field inside field collection item (or can?).
$products_taxonomy = taxonomy_vocabulary_machine_name_load('products');
$product_tree = taxonomy_get_tree($products_taxonomy->vid);
if (is_array($product_tree)) {
$field_instance = field_info_instance('node', 'field_fc_o_position', 'order_request');
$field_instance['cardinality'] = count($product_tree);
$field_instance['type'] = 'field_collection_item';
$field_instance['columns'] = array();
$form_state['field']['field_fc_o_position'][LANGUAGE_NONE]['items_count'] = count($product_tree);
$instance = $form_state['field']['field_fc_o_position'][LANGUAGE_NONE]['instance'];
$form['field_fc_o_position'][LANGUAGE_NONE] = field_multiple_value_form(
$field_instance,
$instance,
LANGUAGE_NONE,
array(),
$form,
$form_state
);
}
Question is how to generate empty field collection items on ordering form and default value for select field inside each new item?
Thank you!