You are here

public function YamlFormSubmissionExporter::getValuesFromInput in YAML Form 8

Get the values from the form's user input or form state values.

@paran array $input An associative array of user input or form state values.

Return value

array An associative array of export options.

Overrides YamlFormSubmissionExporterInterface::getValuesFromInput

File

src/YamlFormSubmissionExporter.php, line 546

Class

YamlFormSubmissionExporter
Form submission exporter.

Namespace

Drupal\yamlform

Code

public function getValuesFromInput(array $input) {
  if (empty($input['export'])) {
    return [];
  }
  $export_values = $input['export'];
  $values = [];

  // Append download/range type, submitted, and sticky.
  if (isset($export_values['download'])) {
    if (isset($export_values['download']['download'])) {
      $values['download'] = $export_values['download']['download'];
    }
    if (isset($export_values['download']['state'])) {
      $values['state'] = $export_values['download']['state'];
    }
    if (isset($export_values['download']['files'])) {
      $values['files'] = $export_values['download']['files'];
    }
    if (isset($export_values['download']['sticky'])) {
      $values['sticky'] = $export_values['download']['sticky'];
    }
    if (!empty($export_values['download']['submitted']['entity_type'])) {
      $values += $export_values['download']['submitted'];
    }
    if (isset($export_values['download']['range_type'])) {
      $range_type = $export_values['download']['range_type'];
      $values['range_type'] = $range_type;
      if (isset($export_values['download'][$range_type])) {
        $values += $export_values['download'][$range_type];
      }
    }
  }

  // Append format.
  if (isset($export_values['format'])) {
    $values += $export_values['format'];
  }

  // Append header.
  if (isset($export_values['header'])) {
    $values += $export_values['header'];
  }

  // Append columns.
  if (isset($export_values['columns'])) {
    $values += $export_values['columns'];
  }

  // Append (and flatten) elements.
  // http://stackoverflow.com/questions/1319903/how-to-flatten-a-multidimensional-array
  $default_options = $this
    ->getDefaultExportOptions();
  array_walk_recursive($export_values['elements'], function ($item, $key) use (&$values, $default_options) {
    if (isset($default_options[$key])) {
      $values[$key] = $item;
    }
  });
  return $values;
}