I am using the following code.
$form['my_fieldset'] = array(
'#type' => 'fieldset',
'#title' => t('My Title'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#access' => TRUE,
'#process' => array('my_callback_function'),
);
If a fieldset is collapsible, it gets two callbacks at some point later.
form_process_fieldset | (Callback) form_process_fieldset();
ajax_process_form | (Callback) ajax_process_form();
They aren't added to the array with my callback function. If I look at the form array, there is only my callback; so, there is no collapse functionality.
I tried to avoid that by adding the callback in hook_form_alter()
, but this is too early; the callback functions are still not there.
$form['my_fieldset']['#process'][] = 'my_callback_function'; //Not working eather
So where is the right place to add a #process
callback to my own form element, so it gets added as last callback in the callback array, or at least is not destroying the callbacks implemented by this specific form element itself?
I do some calculations in the callback to set #access = FALSE
for this fieldset under certain conditions. This works fine, but maybe this is the wrong way to do it.
The documentation on #process says:
You will probably want to add to the existing array rather than writing over it, so don't follow this usage example exactly.
The documentation is not very helpful, I don't follow but there is no info how it is done right.