Why isn't the custom validation handler fired in hook_form_alter()? I am adding a custom validation handler to the node edit form, using the following code.

function my_module_form_alter(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  if ($form_id != 'node_article_edit_form') {
    return;
  }   

  // ...

  $form['#validate'][] = 'my_module_node_article_edit_form_validate';
}

function my_module_node_article_edit_form_validate(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state) {
  // ...
}


The validation handler is not invoked, though. What is wrong with the code I am using?
Validate and submit handlers can be placed on the form level or on specific buttons. If they are defined on a button, only those will be executed; it only falls back to the top-level if nothing is defined on the pressed button.

The node form, like all entity forms has the callbacks defined on the button, which is complicated by the fact that there are multiple buttons (save as published, save as unpublished and so on). You must define your validate callback on all of them.

Also, for validation of an entity, you should instead use validation constrains on the fields or the entity.