$form_state->getValue('username');
$values = $form_state->getValues();In this example, the getValues() method is used to retrieve an array of all the form element values from the $form_state object. Package Library: Drupal\Core\Form\FormStateInterface