How to validate a field value programatically in Drupal 8?
The $form_state now become a classed object as documented here

You can use getValue() to get field value instead of converting it into an array

$form_state-&gt;getValue('name');


instead of:

$form_state = get_object_vars($form_state);
$name = $form_state['values']['name']);


Same thing for form_set_value.

And form_set_error() became $form_state-&gt;setErrorByName().