I'm trying to display a webform through a module controller. The webform display works as it should but I need to update existing submission data and instead of updating the existing submission a new one gets created.
The code I use looks like this:
public function edit()
{
$submissionId = \Drupal::request()->get('sid');
$webform = Webform::load('eventsignup');
$webformSubmission = WebformSubmission::load($submissionId);
$webform = $webform->getSubmissionForm([
'data' => $webformSubmission->getData()
]);
$build['submissionForm'] = $webform;
return $build;
}
I tried to alter it by giving the operation "edit" and setting the "sid" but that leads to a duplicate key error:
public function edit()
{
$submissionId = \Drupal::request()->get('sid');
$webform = Webform::load('eventsignup');
$webformSubmission = WebformSubmission::load($submissionId);
$webform = $webform->getSubmissionForm([
'sid' => $submissionId,
'data' => $webformSubmission->getData()
], 'edit');
$build['submissionForm'] = $webform;
return $build;
}
What am I doing wrong?
Thanks for your help!