I have a a taxonomy term select box (called “product_keyword”) in a node that gets its options populated via the Reference Field Option Limit module. There are 3 other taxonomy term reference fields in the node that are responsible for limiting the “product_keyword” option list all the way down to a single option, and this part is working beautifully.
The “product_keyword” field is set to Required, so when you actually go in to edit the node, the “product_keyword” field appears to already have this one option selected. However, with the use of the Devel module, I have discovered that this is not the case. There is no #value for the “product_keyword.” I have created a custom module (my very first one ever, in fact) to set this #value, but I am having trouble determining how to choose the right properties to set this. This response by Clive is what I’m trying to wrap my brain around.
My module code is using a hook_form_alter function that involves the use of #after_build:
//Declare the callback for after_build for page node form function set_keywords_form_alter(&$form, &$form_state, $form_id) { if ($form_id == 'part_node_form') { $form['#after_build'][] = 'set_keywords_after_build'; } } function set_keywords_after_build($form, &$form_state) {
The overall goal is to simply allow this field to be displayed in a view, but one complication is that these 7000+ nodes are being imported via the Feeds module, and the clients should not have to edit each node manually just to hit the Save button (which is the only way the problem can be solved now – VBO can’t do it, nor can the Resave Nodes module). I’m not even sure if #after_build should be involved, and I am also ok with setting the field’s #default_value instead of or in addition to the #value.
EDIT:
In the page array dropdown, for the keyword’s select list options:
#options (Array, 1 element) 0 (String, 13 characters ) Inker Parts
But under ‘#value,” I’m just getting:
#value (String, 8 characters ) - None -
Under another reference field, “Product Family,” where things are functioning normally, I see:
#options (Array, 40 elements) _none (String, 8 characters ) - None - 1401 (String, 5 characters ) AUTOZ
…….and so on
and for the #value:
0 (String, 2 characters ) 1401 $...['content']['system_main']['field_product_family']['und']['#value'][0]
In this example, “1401” is the tid, and “AUTOZ” is the term name.