|Issue tags:||DX (Developer Experience)|
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.
$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.