You are here

protected function EntityForm::copyFormValuesToEntity in Drupal 8

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

Copies top-level form values to entity properties

This should not change existing entity properties that are not being edited by this form.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity the current form should operate upon.

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

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

1 call to EntityForm::copyFormValuesToEntity()
EntityForm::buildEntity in core/lib/Drupal/Core/Entity/EntityForm.php
Builds an updated entity object based upon the submitted form values.
9 methods override EntityForm::copyFormValuesToEntity()
ContentEntityForm::copyFormValuesToEntity in core/lib/Drupal/Core/Entity/ContentEntityForm.php
Copies top-level form values to entity properties
EntityDisplayFormBase::copyFormValuesToEntity in core/modules/field_ui/src/Form/EntityDisplayFormBase.php
Copies top-level form values to entity properties
LanguageAddForm::copyFormValuesToEntity in core/modules/language/src/Form/LanguageAddForm.php
Copies top-level form values to entity properties
WorkflowAddForm::copyFormValuesToEntity in core/modules/workflows/src/Form/WorkflowAddForm.php
Copies top-level form values to entity properties
WorkflowEditForm::copyFormValuesToEntity in core/modules/workflows/src/Form/WorkflowEditForm.php
Copies top-level form values to entity properties

... See full list

File

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

Class

EntityForm
Base class for entity forms.

Namespace

Drupal\Core\Entity

Code

protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  if ($this->entity instanceof EntityWithPluginCollectionInterface) {

    // Do not manually update values represented by plugin collections.
    $values = array_diff_key($values, $this->entity
      ->getPluginCollections());
  }

  // @todo: This relies on a method that only exists for config and content
  //   entities, in a different way. Consider moving this logic to a config
  //   entity specific implementation.
  foreach ($values as $key => $value) {
    $entity
      ->set($key, $value);
  }
}