You are here

protected function YamlFormUiOptionsForm::copyFormValuesToEntity in YAML Form 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

modules/yamlform_ui/src/YamlFormUiOptionsForm.php, line 36

Class

YamlFormUiOptionsForm
Base for controller for form option UI.

Namespace

Drupal\yamlform_ui

Code

protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();

  // @todo Determine why options.options and options.add are being included.
  // Best guess is the yamlform_options element has not been validated.
  if (isset($values['options']['options'])) {
    $options = is_array($values['options']['options']) ? YamlFormOptions::convertValuesToOptions($values['options']['options']) : [];
  }
  elseif (isset($values['options'])) {
    $options = is_array($values['options']) ? $values['options'] : [];
  }
  else {
    $options = [];
  }
  $entity
    ->set('options', Yaml::encode($options));
  unset($values['options']);
  foreach ($values as $key => $value) {
    $entity
      ->set($key, $value);
  }
}