Classes that inherit from (extend) FormBase and its children now use the protected method setFormError instead of form_set_error().
The setFormError method accepts the same arguments as form_set_error(): the name of the form element (string $name), an associative array containing the current state of the form (array $form_state) and an optional message to show to the user (string $message).
After #2225353: Convert $form_state to an object and provide methods like setError() $form_state is now a classed object and all the form_*_error methods are moved from FormErrorInterface to FormStateInterface after #2308821: Replace FormErrorInterface with $form_state->setErrorByName() and $form_state->setError() see drupal_*_form() methods are replaced by a form builder service for the renaming of form_*_error methods.
For example in \Drupal\book\Form\BookAdminEditForm:
Before
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, array &$form_state) {
if ($form_state['values']['tree_hash'] != $form_state['values']['tree_current_hash']) {
form_set_error('', $form_state, $this->t('This book has been modified by another user, the changes could not be saved.'));
}
}
After
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
if ($form_state['values']['tree_hash'] != $form_state['values']['tree_current_hash']) {
$form_state->setErrorByName('', $this->t('This book has been modified by another user, the changes could not be saved.'));
}
}