protected function WebformSubmissionStorage::setAnonymousSubmission in Webform 8.5
Same name and namespace in other branches
- 6.x src/WebformSubmissionStorage.php \Drupal\webform\WebformSubmissionStorage::setAnonymousSubmission()
Track anonymous submissions.
Anonymous submission are tracked so that they can be assigned to the user if they login.
We use session for storing draft tokens. So we can only do it for the current user.
We do not use PrivateTempStore because it utilizes session ID as the key in key-value hash map where it stores its data. During user login the session ID is regenerated (see user_login_finalize()) so it is not suitable for us since we need to "carry" the draft tokens from anonymous session to the logged in one.
Parameters
\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.
See also
WebformSubmissionStorage::loadDraft
WebformSubmissionStorage::userLogin
1 call to WebformSubmissionStorage::setAnonymousSubmission()
- WebformSubmissionStorage::doSave in src/
WebformSubmissionStorage.php - Performs storage-specific saving of the entity.
File
- src/
WebformSubmissionStorage.php, line 1590
Class
- WebformSubmissionStorage
- Defines the webform submission storage.
Namespace
Drupal\webformCode
protected function setAnonymousSubmission(WebformSubmissionInterface $webform_submission) {
// Make sure the account and current user are identical.
if ((int) $webform_submission
->getOwnerId() !== (int) $this->currentUser
->id()) {
return;
}
// Make sure the submission is anonymous.
if (!$webform_submission
->getOwner()
->isAnonymous()) {
return;
}
// Check if anonymous users are allowed to save submission using $_SESSION.
if ($this
->hasAnonymousSubmissionTracking($webform_submission)) {
$_SESSION['webform_submissions'][$webform_submission
->id()] = $webform_submission
->id();
}
}