In the past week, I have had two projects where I needed to use hook_form_alter() to add a submit handler to a form. Problem is, I need the submit handler to fire in a particular order with regard to both the base form and any other hook_form_alter() implementations.
Right now, AFAIK, #submit is just a positional array, and you have to do some nasty sorting of that array in order to manipulate the execution order of your handler.
Proposal is to add an #order or #execution_order parameter to the #submit element, so that we can fine-tune the sort on these elements.
E.g.
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
'#order' => 0, // defaults to zero if not set
);
$form['#submit'][] = array(
'#callback' => 'mycallback_submit',
'#order' => -5, // We always runs before anything else!
);
We would then modify form_execute_handlers() to sort based on this value.
Comments
Comment #1
Crell CreditAttribution: Crell commentedTo be consistent with the rest of the FAPI array, #order should probably be #weight.
Comment #2
agentrickardCan't use #weight here, since that is already taken, though it would be nice.
Comment #3
sun.core CreditAttribution: sun.core commentedComment #4
valthebald#weight still can be used in #submit arrays, like
no?
Comment #5
agentrickardIt can? Is that documented somewhere?
I'd be ok with a docs change if that is the case.
Comment #6
valthebaldNo, I just meant that the word 'weight' is not reserved, and can be used
Comment #7
agentrickardI see. I figure using #weight in that case might be confusing for people scanning the API.
Comment #20
smustgrave CreditAttribution: smustgrave at Mobomo commentedWonder of 10+ years of inactivity if this is still a desired feature request for D10?