function FieldConfigEditForm::copyFormValuesToEntity
Same name in other branches
- 11.x core/modules/field_ui/src/Form/FieldConfigEditForm.php \Drupal\field_ui\Form\FieldConfigEditForm::copyFormValuesToEntity()
Overrides EntityForm::copyFormValuesToEntity
File
-
core/
modules/ field_ui/ src/ Form/ FieldConfigEditForm.php, line 284
Class
- FieldConfigEditForm
- Provides a form for the field settings form.
Namespace
Drupal\field_ui\FormCode
protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
parent::copyFormValuesToEntity($entity, $form, $form_state);
// Update the current field storage instance based on subform state.
if (!empty($form['field_storage']['subform'])) {
$subform_state = SubformState::createForSubform($form['field_storage']['subform'], $form, $form_state);
$field_storage_form = $this->entityTypeManager
->getFormObject('field_storage_config', $this->operation);
$field_storage_form->setEntity($entity->getFieldStorageDefinition());
$reflector = new \ReflectionObject($entity);
// Update the field storage entity based on subform values.
$property = $reflector->getProperty('fieldStorage');
$property->setValue($entity, $field_storage_form->buildEntity($form['field_storage']['subform'], $subform_state));
// Remove the item definition to make sure it's not storing stale data.
$property = $reflector->getProperty('itemDefinition');
$property->setValue($entity, NULL);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.