TermForm::buildEntity

public TermForm::buildEntity(array $form, FormStateInterface $form_state)

Builds an updated entity object based upon the submitted form values.

For building the updated entity object the form's entity is cloned and the submitted form values are copied to entity properties. The form's entity remains unchanged.

Parameters

array $form: A nested array form elements comprising the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

\Drupal\Core\Entity\EntityInterface An updated copy of the form's entity object.

Overrides ContentEntityForm::buildEntity

See also

\Drupal\Core\Entity\EntityFormInterface::getEntity()

File

core/modules/taxonomy/src/TermForm.php, line 106

Class

TermForm
Base for handler for taxonomy term edit forms.

Namespace

Drupal\taxonomy

Code

public function buildEntity(array $form, FormStateInterface $form_state) {
  $term = parent::buildEntity($form, $form_state);

  // Prevent leading and trailing spaces in term names.
  $term->setName(trim($term->getName()));

  // Assign parents with proper delta values starting from 0.
  $term->parent = array_keys($form_state->getValue('parent'));

  return $term;
}
doc_Drupal
2016-10-29 09:47:12
Comments
Leave a Comment

Please login to continue.