function EntityDisplayFormBase::copyFormValuesToEntity
Same name in other branches
- 9 core/modules/field_ui/src/Form/EntityDisplayFormBase.php \Drupal\field_ui\Form\EntityDisplayFormBase::copyFormValuesToEntity()
- 8.9.x core/modules/field_ui/src/Form/EntityDisplayFormBase.php \Drupal\field_ui\Form\EntityDisplayFormBase::copyFormValuesToEntity()
- 10 core/modules/field_ui/src/Form/EntityDisplayFormBase.php \Drupal\field_ui\Form\EntityDisplayFormBase::copyFormValuesToEntity()
Overrides EntityForm::copyFormValuesToEntity
1 call to EntityDisplayFormBase::copyFormValuesToEntity()
- LayoutBuilderEntityViewDisplayForm::copyFormValuesToEntity in core/
modules/ layout_builder/ src/ Form/ LayoutBuilderEntityViewDisplayForm.php - Copies top-level form values to entity properties.
1 method overrides EntityDisplayFormBase::copyFormValuesToEntity()
- LayoutBuilderEntityViewDisplayForm::copyFormValuesToEntity in core/
modules/ layout_builder/ src/ Form/ LayoutBuilderEntityViewDisplayForm.php - Copies top-level form values to entity properties.
File
-
core/
modules/ field_ui/ src/ Form/ EntityDisplayFormBase.php, line 605
Class
- EntityDisplayFormBase
- Base class for EntityDisplay edit forms.
Namespace
Drupal\field_ui\FormCode
protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
$form_values = $form_state->getValues();
if ($this->entity instanceof EntityWithPluginCollectionInterface) {
// Do not manually update values represented by plugin collections.
$form_values = array_diff_key($form_values, $this->entity
->getPluginCollections());
}
// Collect data for 'regular' fields.
foreach ($form['#fields'] as $field_name) {
$values = $form_values['fields'][$field_name];
if ($values['region'] == 'hidden') {
$entity->removeComponent($field_name);
}
else {
$options = $entity->getComponent($field_name);
// Update field settings only if the submit handler told us to.
if ($form_state->get('plugin_settings_update') === $field_name) {
// Only store settings actually used by the selected plugin.
$default_settings = $this->pluginManager
->getDefaultSettings($options['type']);
$options['settings'] = isset($values['settings_edit_form']['settings']) ? array_intersect_key($values['settings_edit_form']['settings'], $default_settings) : [];
$options['third_party_settings'] = $values['settings_edit_form']['third_party_settings'] ?? [];
$form_state->set('plugin_settings_update', NULL);
}
$options['type'] = $values['type'];
$options['weight'] = $values['weight'];
$options['region'] = $values['region'];
// Only formatters have configurable label visibility.
if (isset($values['label'])) {
$options['label'] = $values['label'];
}
$entity->setComponent($field_name, $options);
}
}
// Collect data for 'extra' fields.
foreach ($form['#extra'] as $name) {
if ($form_values['fields'][$name]['region'] == 'hidden') {
$entity->removeComponent($name);
}
else {
$entity->setComponent($name, [
'weight' => $form_values['fields'][$name]['weight'],
'region' => $form_values['fields'][$name]['region'],
]);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.