protected function WebformSubmissionDevelGenerateTrait::generateSubmission in Webform 8.5
Same name and namespace in other branches
- 6.x src/Plugin/DevelGenerate/WebformSubmissionDevelGenerateTrait.php \Drupal\webform\Plugin\DevelGenerate\WebformSubmissionDevelGenerateTrait::generateSubmission()
Create one node. Used by both batch and non-batch code branches.
1 call to WebformSubmissionDevelGenerateTrait::generateSubmission()
- WebformSubmissionDevelGenerateTrait::generateSubmissions in src/
Plugin/ DevelGenerate/ WebformSubmissionDevelGenerateTrait.php - Generates submissions for a list of given webforms.
File
- src/
Plugin/ DevelGenerate/ WebformSubmissionDevelGenerateTrait.php, line 360
Class
- WebformSubmissionDevelGenerateTrait
- Provides a WebformSubmissionDevelGenerate trait.
Namespace
Drupal\webform\Plugin\DevelGenerateCode
protected function generateSubmission(&$results) {
$webform_id = array_rand(array_filter($results['webform_ids']));
/** @var \Drupal\webform\WebformInterface $webform */
$webform = $this->webformStorage
->load($webform_id);
$users = $results['users'];
$uid = $users[array_rand($users)];
$entity_type = $results['entity-type'];
$entity_id = $results['entity-id'];
// Get submission URL from source entity or webform.
$url = $webform
->toUrl();
if ($entity_type && $entity_id) {
$source_entity = \Drupal::entityTypeManager()
->getStorage($entity_type)
->load($entity_id);
if ($source_entity
->hasLinkTemplate('canonical')) {
$url = $source_entity
->toUrl();
}
}
$timestamp = rand($results['created_min'], $results['created_max']);
$this->webformSubmissionStorage
->create([
'webform_id' => $webform_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() . '#', '/', $url
->toString()),
'data' => Yaml::encode($this->webformSubmissionGenerate
->getData($webform)),
'created' => $timestamp,
'changed' => $timestamp,
])
->save();
}