protected function ContentEntityForm::copyFormValuesToEntity in Drupal 9
Same name and namespace in other branches
- 8 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()
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.
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);
}
}
}