You are here

protected function YamlFormSubmissionDevelGenerate::generateSubmission in YAML Form 8

Create one node. Used by both batch and non-batch code branches.

1 call to YamlFormSubmissionDevelGenerate::generateSubmission()
YamlFormSubmissionDevelGenerate::generateSubmissions in src/Plugin/DevelGenerate/YamlFormSubmissionDevelGenerate.php
Generates submissions for a list of given forms.

File

src/Plugin/DevelGenerate/YamlFormSubmissionDevelGenerate.php, line 256

Class

YamlFormSubmissionDevelGenerate
Provides a YamlFormSubmissionDevelGenerate plugin.

Namespace

Drupal\yamlform\Plugin\DevelGenerate

Code

protected function generateSubmission(&$results) {
  $yamlform_id = array_rand(array_filter($results['yamlform_ids']));

  /** @var \Drupal\yamlform\YamlFormInterface  $yamlform */
  $yamlform = $this->yamlformStorage
    ->load($yamlform_id);
  $users = $results['users'];
  $uid = $users[array_rand($users)];
  $entity_type = $results['entity-type'] ?: '';
  $entity_id = $results['entity-id'] ?: '';
  $timestamp = rand($results['created_min'], $results['created_max']);
  $this->yamlformSubmissionStorage
    ->create([
    'yamlform_id' => $yamlform_id,
    'entity_type' => $entity_type,
    'entity_id' => $entity_id,
    'uid' => $uid,
    'remote_addr' => mt_rand(0, 255) . '.' . mt_rand(0, 255) . '.' . mt_rand(0, 255) . '.' . mt_rand(0, 255),
    'uri' => preg_replace('#^' . base_path() . '#', '/', $yamlform
      ->toUrl()
      ->toString()),
    'data' => Yaml::encode($this->yamlformSubmissionGenerate
      ->getData($yamlform)),
    'created' => $timestamp,
    'changed' => $timestamp,
  ])
    ->save();
}