drupal 8 form validation method -- static method form validation
Recently on a project I moved a hook_form_alter() function into an event subscriber, utilizing the hook event dispatcher module. I was able to, using their example, create an equivelant to hook_form_alter and have it call. You can see the example in hook_event_dispatcher/examples/ExampleFormEventSubscribers.php of just how they accomplished this.
Now what I felt was missing was the ability to place your validation code inside of that same event subscriber and have it called, allowing you to keep related functionality together and presentable. It turns out, here is what you would do:
$form['#validate'] = [ 'Drupal\example_module\EventSubscriber\CustomFormsEventSubscriber', 'customValidate', ];
This will then call the method, which you want to make available as a STATIC method, like so:
public static function customValidate(&$form, FormStateInterface $form_state)
Then just write your validation code as normal in the custom static validation method.
I just discovered you don't need to pass the full namespace either. You can simply do...
$form['#validate'] = [$this, 'customValidate'];