* Implements hook_form_FORM_ID_alter().
function mymod_form_menu_link_content_menu_link_content_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {

  array_unshift($form['#submit'], 'mymod_menu_link_content_form_submit');

function mymod_menu_link_content_form_submit($form, \Drupal\Core\Form\FormStateInterface $formState) {
  //some code

Debug shows me that my custom submit handler is added to $form['#submit'] array as a first item. However this submit handler is never called.

  • Do you clean caches ? and do you run your page with a "die()" in the "mymod_menu_link_content_form_submit" function ? Oct 24, 2016 at 11:45
  • I've cleared cache multiple times. It seems that only code in alter hook implementation is running upon submit.
    – Codium
    Oct 24, 2016 at 12:32
  • Is the function located at the same file?
    – Jimmy Ko
    Oct 24, 2016 at 13:11
  • unfortunately yes it is :( no idea what have done wrong
    – Codium
    Oct 24, 2016 at 14:15

1 Answer 1


Forms can have submit callbacks in two places. Either on the form level or on the button that is pressed. The form level callbacks are only invoked if no button-specific callbacks are specified.

Entity forms generally have the submit callbacks on the submit button, which is usually $form['actions']['submit']['#submit'].

This was the same in Drupal 7, although the node form and possibly others had a backwards compatibility layer that also invoked form-level submit callbacks, but this was removed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.