Hi,
In Drupal 7 I'm working on a module that deals with node
forms.
I must set some values from code. Actually what I do is save some
user input
and populate the node form with the values.
I can easily modify field values from hook_form_alter except
term_reference_tree.
It looks like that when hook_form_alter gets called, the
term_reference_tree field
only has some meta data and doesn't contain the
checkboxes for the tree.
They are missing in hook_field_attach_form too. However, when I check
the field
upon form submit, the checkboxes are there.
On form submit the field has a key [#options] and an array with the
checkbox tree,
but these keys are missing in hook_form_alter. There's a function
term_reference_tree_process_checkbox_tree which I tried to call from
my module.
It builds the frame of the checkbox tree, but not the actual
checkboxes. Output is like this:
[#options_tree] => Array
(
)
[#options] => Array
(
)
[0] => Array
span>
(
[#type] => checkbox_tree_level
[#max_choices] => 1
[#leaves_only] =>
[#start_minimized] =>
[#depth] => 1
[#level_start_minimized] =>
)
As you can see, the #options array is empty, and
the checkbox array only has some default
values.
I tried to simply insert values in the array (and set the keys
where they should belong), set
#checked to true like with regular
checkboxes, but when the form is presented to the user,
these values got overwritten with empty values.
I also tried to modify weight, to put my module before term_reference_tree, but it didn't help.
Is there a way to check some checkboxes from code before it the form gets displayed
to the user? I am not too familiar with term reference tree
module, but I think there must
be some function I can call or another hook I can catch to build
the checkbox tree so I
can populate it.
Thanks in advance,
Balazs