DX: Allow ordering of #validate and #submit callbacks

Created on 1 June 2009, about 15 years ago
Updated 17 August 2023, 10 months ago

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.

✨ Feature request
Status

Postponed: needs info

Version

9.5

Component
FormΒ  β†’

Last updated about 2 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024