modify submit on user login so that only admins can log in through this route I have written a hook form alter which adds a submit action but I get this error 


  Recoverable fatal error: Argument 2 passed to xxx_form_submit() must be an instance of FormStateInterface, instance of Drupal\Core\Form\FormState given in xxx_form_submit() 


the code is like this 

function xxx_form_alter(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {

 if ($form_id=='user_login_form') {

    $form['actions']['submit']['#submit'][] = 'xxx_form_submit';
  }
}

function xxx_form_submit ($form, FormStateInterface  $form_state) {
  $username=$form_state-&gt;getValue('name'));
}
You are getting this because you did not include the use statement at the top of your file:

use Drupal\Core\Form\FormStateInterface;

function xxx_form_alter(&amp;$form, FormStateInterface $form_state, $form_id) {

 if ($form_id=='user_login_form') {

    $form['actions']['submit']['#submit'][] = 'xxx_form_submit';
  }
}


You can use the full path, but it is preferred for developers to do use statements.