July 2017
Intermediate to advanced
456 pages
11h 32m
English
Beyond separating each Form into separate classes, another significant change is the introduction of FormStateInterface. In Drupal 7, the $form_state variable that was passed to the various form functions was a simple array. However, in Drupal 8, in addition to getting the values from the previous form actions, the FormStateInterface is used to set form errors. In Drupal 7, if you needed to indicate an error with a form field, you would call the following:
Form_set_error('first_name', t('The first name is invalid'));
In Drupal 8, this looks like this:
$form_state->setErrorByName('first_name', $this->t('The first name is invalid'));
The FormStateInterface has some other nice convenience functions, especially around checking ...
Read now
Unlock full access