You are here

protected function YamlFormSubmissionStorage::loadData in YAML Form 8

Save form submission data from the 'yamlform_submission_data' table.

Parameters

array $yamlform_submissions: An array of form submissions.

1 call to YamlFormSubmissionStorage::loadData()
YamlFormSubmissionStorage::loadMultiple in src/YamlFormSubmissionStorage.php
Loads one or more entities.

File

src/YamlFormSubmissionStorage.php, line 652

Class

YamlFormSubmissionStorage
Defines the form submission storage.

Namespace

Drupal\yamlform

Code

protected function loadData(array &$yamlform_submissions) {

  // Load form submission data.
  if ($sids = array_keys($yamlform_submissions)) {
    $result = Database::getConnection()
      ->select('yamlform_submission_data', 'sd')
      ->fields('sd', [
      'yamlform_id',
      'sid',
      'name',
      'property',
      'delta',
      'value',
    ])
      ->condition('sd.sid', $sids, 'IN')
      ->orderBy('sd.sid', 'ASC')
      ->orderBy('sd.name', 'ASC')
      ->orderBy('sd.property', 'ASC')
      ->orderBy('sd.delta', 'ASC')
      ->execute();
    $submissions_data = [];
    while ($record = $result
      ->fetchAssoc()) {
      $sid = $record['sid'];
      $name = $record['name'];
      $elements = $yamlform_submissions[$sid]
        ->getYamlForm()
        ->getElementsFlattenedAndHasValue();
      $element = isset($elements[$name]) ? $elements[$name] : [
        '#yamlform_multiple' => FALSE,
        '#yamlform_composite' => FALSE,
      ];
      if ($element['#yamlform_multiple']) {
        $submissions_data[$sid][$name][$record['delta']] = $record['value'];
      }
      elseif ($element['#yamlform_composite']) {
        $submissions_data[$sid][$name][$record['property']] = $record['value'];
      }
      else {
        $submissions_data[$sid][$name] = $record['value'];
      }
    }

    // Set form submission data via setData().
    foreach ($submissions_data as $sid => $submission_data) {
      $yamlform_submissions[$sid]
        ->setData($submission_data);
      $yamlform_submissions[$sid]
        ->setOriginalData($submission_data);
    }
  }
}