public function EntityForm::buildEntity

public EntityForm::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 EntityFormInterface::buildEntity

See also

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

File

core/lib/Drupal/Core/Entity/EntityForm.php, line 289

Class

EntityForm
Base class for entity forms.

Namespace

Drupal\Core\Entity

Code

public function buildEntity(array $form, FormStateInterface $form_state) {
  $entity = clone $this->entity;
  $this->copyFormValuesToEntity($entity, $form, $form_state);

  // Invoke all specified builders for copying form values to entity
  // properties.
  if (isset($form['#entity_builders'])) {
    foreach ($form['#entity_builders'] as $function) {
      call_user_func_array($function, array($entity->getEntityTypeId(), $entity, &$form, &$form_state));
    }
  }

  return $entity;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!EntityForm.php/function/EntityForm::buildEntity/8.1.x