You are here

protected function WebformSubmissionForm::prepopulateData in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/WebformSubmissionForm.php \Drupal\webform\WebformSubmissionForm::prepopulateData()

Prepopulate element data.

Parameters

array $data: An array of default.

1 call to WebformSubmissionForm::prepopulateData()
WebformSubmissionForm::buildForm in src/WebformSubmissionForm.php
Form constructor.

File

src/WebformSubmissionForm.php, line 2610

Class

WebformSubmissionForm
Provides a webform to collect and edit submissions.

Namespace

Drupal\webform

Code

protected function prepopulateData(array &$data) {

  // Get prepopulate data.
  if ($this
    ->getWebformSetting('form_prepopulate')) {
    $prepopulate_data = $this
      ->getRequest()->query
      ->all();
  }
  else {
    $prepopulate_data = [];
    $elements = $this
      ->getWebform()
      ->getElementsPrepopulate();
    foreach ($elements as $element_key) {
      if ($this
        ->getRequest()->query
        ->has($element_key)) {
        $prepopulate_data[$element_key] = $this
          ->getRequest()->query
          ->get($element_key);
      }
    }
  }

  // Validate prepopulate data.
  foreach ($prepopulate_data as $element_key => &$value) {
    if ($this
      ->checkPrepopulateDataValid($element_key, $value) === FALSE) {
      unset($prepopulate_data[$element_key]);
    }
  }

  // Set prepopulate data.
  $data = $prepopulate_data + $data;
}