In order to get a form validation handler to run first we need to put it at the beginning of the validation handler array. This is done using array_unshift.
Here is an example of setting a form validation to the login form using a hook_form_FORM_ID_alter() hook.
/**
* Implements hook_form_FORM_ID_alter().
*/
function mymodule_form_user_login_form_alter(&$form, FormStateInterface $form_state, $form_id) {
array_unshift($form['#validate'], 'mymodule_login_form_validate');
}
Add new comment