function ContentEntityForm::copyFormValuesToEntity
Same name in other branches
- 9 core/lib/Drupal/Core/Entity/ContentEntityForm.php \Drupal\Core\Entity\ContentEntityForm::copyFormValuesToEntity()
- 8.9.x core/lib/Drupal/Core/Entity/ContentEntityForm.php \Drupal\Core\Entity\ContentEntityForm::copyFormValuesToEntity()
- 10 core/lib/Drupal/Core/Entity/ContentEntityForm.php \Drupal\Core\Entity\ContentEntityForm::copyFormValuesToEntity()
Overrides EntityForm::copyFormValuesToEntity
File
-
core/
lib/ Drupal/ Core/ Entity/ ContentEntityForm.php, line 332
Class
- ContentEntityForm
- Entity form variant for content entity types.
Namespace
Drupal\Core\EntityCode
protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
// First, extract values from widgets.
$extracted = $this->getFormDisplay($form_state)
->extractFormValues($entity, $form, $form_state);
// Then extract the values of fields that are not rendered through widgets,
// by simply copying from top-level form values. This leaves the fields
// that are not being edited within this form untouched.
foreach ($form_state->getValues() as $name => $values) {
if ($entity->hasField($name) && !isset($extracted[$name])) {
$entity->set($name, $values);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.