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 ( [#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
On Fri, Oct 19, 2012 at 6:25 AM, Karsai Balázs balazs.karsai@flavongroup.com wrote:
Is there a way to check some checkboxes from code before it the form gets displayed to the user?
#default_value
I tried it, but it gets overwritten, probably when term reference tree module creates the checkbox tree.
2012.10.19. 16:47 keltezéssel, Earnie Boyd írta:
On Fri, Oct 19, 2012 at 6:25 AM, Karsai Balázs balazs.karsai@flavongroup.com wrote:
Is there a way to check some checkboxes from code before it the form gets displayed to the user?
#default_value
You should ask in the issue queue for the module. #default_value is the field to populate for default value display.
On Fri, Oct 19, 2012 at 10:55 AM, Karsai Balázs balazs.karsai@flavongroup.com wrote:
I tried it, but it gets overwritten, probably when term reference tree module creates the checkbox tree.
2012.10.19. 16:47 keltezéssel, Earnie Boyd írta:
On Fri, Oct 19, 2012 at 6:25 AM, Karsai Balázs balazs.karsai@flavongroup.com wrote:
Is there a way to check some checkboxes from code before it the form gets displayed to the user?
#default_value
-- [ Drupal support list | http://lists.drupal.org/ ]