You are here

public function WebformSubmissionStorage::userLogin in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/WebformSubmissionStorage.php \Drupal\webform\WebformSubmissionStorage::userLogin()

React to an event when a user logs in.

Parameters

\Drupal\user\UserInterface $account: Account that has just logged in.

Overrides WebformSubmissionStorageInterface::userLogin

File

src/WebformSubmissionStorage.php, line 1472

Class

WebformSubmissionStorage
Defines the webform submission storage.

Namespace

Drupal\webform

Code

public function userLogin(UserInterface $account) {
  if (empty($_SESSION['webform_submissions'])) {
    return;
  }

  // Move all anonymous submissions to UID of this account.
  $query = $this
    ->getQuery();
  $query
    ->accessCheck(FALSE);
  $query
    ->condition('uid', 0);
  $query
    ->condition('sid', $_SESSION['webform_submissions'], 'IN');
  $query
    ->sort('sid');
  if ($sids = $query
    ->execute()) {
    $webform_submissions = $this
      ->loadMultiple($sids);
    foreach ($webform_submissions as $sid => $webform_submission) {
      $webform = $webform_submission
        ->getWebform();

      // Do not convert confidential submissions and check for convert
      // anonymous setting.
      if ($webform
        ->isConfidential() || empty($webform
        ->getSetting('form_convert_anonymous'))) {
        continue;
      }
      unset($_SESSION['webform_submissions'][$sid]);
      $webform_submission
        ->convert($account);
    }
  }

  // Now that the user has logged in because when the log out $_SESSION is
  // completely reset.
  unset($_SESSION['webform_submissions']);
}