I want to do array_unshift for submit function in D8. Array_unshift working perfectly for validate function but not submit function. Below is my code:
function example_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
if ($form_id == "commerce_order_default_edit_form") {
array_unshift($form['#validate'], 'example_manual_validate');
array_unshift($form['#submit'], 'example_manual_submit');
}
}
function example_manual_validate(&$form, \Drupal\Core\Form\FormStateInterface &$form_state) {
$values = $form_state->getValues();
dsm($values);
}
function example_manual_submit(&$form, \Drupal\Core\Form\FormStateInterface &$form_state) {
$values = $form_state->getValues();
dsm($values);
}
array_unshift()
works. What could eventually happen is that you add submission handlers to$form['#submit']
when the form is using something else, like$form['actions']['submit']['#submit']
, for example.