Initialize the form state and the entity before the first form build.
protected function init(array &$form_state) {
// Add the controller to the form state so it can be easily accessed by
// module-provided form handlers there.
$form_state['controller'] = $this;
$this
->prepareEntity();
// @todo Allow the usage of different form modes by exposing a hook and the
// UI for them.
$form_display = entity_get_render_form_display($this->entity, 'default');
// Let modules alter the form display.
$form_display_context = array(
'entity_type' => $this->entity
->entityType(),
'bundle' => $this->entity
->bundle(),
'form_mode' => 'default',
);
\Drupal::moduleHandler()
->alter('entity_form_display', $form_display, $form_display_context);
$this
->setFormDisplay($form_display, $form_state);
}