You are here

public function EntityForm::buildEntity in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/EntityForm.php \Drupal\Core\Entity\EntityForm::buildEntity()
  2. 10 core/lib/Drupal/Core/Entity/EntityForm.php \Drupal\Core\Entity\EntityForm::buildEntity()

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()

6 calls to EntityForm::buildEntity()
ContentEntityForm::buildEntity in core/lib/Drupal/Core/Entity/ContentEntityForm.php
Builds an updated entity object based upon the submitted form values.
DefaultsEntityForm::buildEntity in core/modules/layout_builder/src/Form/DefaultsEntityForm.php
Builds an updated entity object based upon the submitted form values.
EntityDisplayFormBase::multistepSubmit in core/modules/field_ui/src/Form/EntityDisplayFormBase.php
Form submission handler for multistep buttons.
EntityForm::afterBuild in core/lib/Drupal/Core/Entity/EntityForm.php
Form element #after_build callback: Updates the entity with submitted data.
EntityForm::submitForm in core/lib/Drupal/Core/Entity/EntityForm.php
This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state…

... See full list

3 methods override EntityForm::buildEntity()
ContentEntityForm::buildEntity in core/lib/Drupal/Core/Entity/ContentEntityForm.php
Builds an updated entity object based upon the submitted form values.
DefaultsEntityForm::buildEntity in core/modules/layout_builder/src/Form/DefaultsEntityForm.php
Builds an updated entity object based upon the submitted form values.
FieldStorageConfigEditForm::buildEntity in core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php
Builds an updated entity object based upon the submitted form values.

File

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

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($form_state
        ->prepareCallback($function), [
        $entity
          ->getEntityTypeId(),
        $entity,
        &$form,
        &$form_state,
      ]);
    }
  }
  return $entity;
}