Overrides Drupal\Core\Entity\EntityFormController::buildEntity().
Overrides EntityFormControllerNG::buildEntity
public function buildEntity(array $form, array &$form_state) {
$term = parent::buildEntity($form, $form_state);
// Prevent leading and trailing spaces in term names.
$term->name->value = trim($term->name->value);
// Convert text_format field into values expected by
// \Drupal\Core\Entity\Entity::save() method.
$description = $form_state['values']['description'];
$term->description->value = $description['value'];
$term->format->value = $description['format'];
// Assign parents with proper delta values starting from 0.
$term->parent = array_keys($form_state['values']['parent']);
return $term;
}