You are here

protected function FieldableEdgeEntityForm::copyFormValuesToEntity in Apigee Edge 8

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

src/Entity/Form/FieldableEdgeEntityForm.php, line 165

Class

FieldableEdgeEntityForm
Base entity form for fieldable Apigee Edge entity types.

Namespace

Drupal\apigee_edge\Entity\Form

Code

protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {

  /** @var \Drupal\apigee_edge\Entity\FieldableEdgeEntityInterface $entity */

  // 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);
    }
  }
}