protected EntityDisplayFormBase::copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state)
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/modules/field_ui/src/Form/EntityDisplayFormBase.php, line 541
Class
- EntityDisplayFormBase
- Base class for EntityDisplay edit forms.
Namespace
Drupal\field_ui\Form
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | 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 [ 'type' ] == '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' ] = isset( $values [ 'settings_edit_form' ][ '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' ]; // 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 ][ 'type' ] == 'hidden' ) { $entity ->removeComponent( $name ); } else { $entity ->setComponent( $name , array ( 'weight' => $form_values [ 'fields' ][ $name ][ 'weight' ], )); } } } |
Please login to continue.