Problem/Motivation
If you add a form validator to a submit button, all the default form validators are bypassed.
Yur custom submit validation handler is added to the form_state->getValidateHandlers().
Here is the related code in Drupal FormValidator class:
public function executeValidateHandlers(&$form, FormStateInterface &$form_state) {
// If there was a button pressed, use its handlers.
$handlers = $form_state->getValidateHandlers();
// Otherwise, check for a form-level handler.
if (!$handlers && isset($form['#validate'])) {
$handlers = $form['#validate'];
}
foreach ($handlers as $callback) {
call_user_func_array($form_state->prepareCallback($callback), [&$form, &$form_state]);
}
}
Steps to reproduce
Got hit while trying to alter a node edit form and add another custom form validator.
I was getting this error message:
Uncaught PHP Exception Drupal\\Core\\Entity\\EntityStorageException: "Entity validation is required, but was skipped." at /var/www/html/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php line 815,
Comments
Comment #4
mably commented